@pluv/io 0.30.2 → 0.32.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/dist/index.d.ts CHANGED
@@ -82,34 +82,34 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
82
82
  sendMessage<TMessage extends IOEventMessage<any> = IOEventMessage<any>>(data: TMessage): void;
83
83
  }
84
84
 
85
- interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
86
- broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
85
+ interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
86
+ broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
87
87
  input?: InputZodLike<TInput>;
88
- self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
88
+ self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
89
89
  sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
90
90
  }
91
- declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
91
+ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
92
92
  private _broadcast;
93
93
  private _input;
94
94
  private _self;
95
95
  private _sync;
96
96
  get config(): ProcedureLike<TInput, TOutput>["config"];
97
97
  constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
98
- broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
98
+ broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
99
99
  input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
100
- self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
101
- sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
100
+ self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
101
+ sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
102
102
  private _resolver;
103
103
  }
104
104
 
105
- type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
105
+ type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> = {
106
106
  [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
107
107
  };
108
- type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
108
+ type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
109
109
  infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
110
110
  ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
111
111
  ] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
112
- declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
112
+ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
113
113
  readonly _defs: {
114
114
  events: TEvents;
115
115
  };
@@ -122,12 +122,13 @@ declare global {
122
122
  log: (...data: any[]) => void;
123
123
  };
124
124
  }
125
+ type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
125
126
  interface CrdtLibraryType {
126
127
  doc: (value: any) => AbstractCrdtDocFactory<any>;
127
128
  kind: "loro" | "yjs";
128
129
  }
129
- type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
130
- interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
130
+ type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
131
+ interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
131
132
  context: TContext;
132
133
  doc: AbstractCrdtDoc<any>;
133
134
  room: string;
@@ -176,19 +177,19 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
176
177
  }> : Id<TRoot>;
177
178
  type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
178
179
  room: string;
179
- } & InferRoomContextType<TPlatform>;
180
+ };
180
181
  type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
181
- interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
182
+ interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
182
183
  onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
183
184
  onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
184
185
  onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
185
186
  }
186
- type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
187
- context: TContext & InferRoomContextType<TPlatform>;
187
+ type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
188
+ context: TContext;
188
189
  encodedState: string | null;
189
190
  room: string;
190
191
  };
191
- type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
192
+ type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
192
193
  message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
193
194
  user?: InferIOAuthorizeUser<TAuthorize>;
194
195
  };
@@ -206,31 +207,31 @@ declare abstract class AbstractPubSub {
206
207
  type WebSocketRegistrationMode = "attached" | "detached";
207
208
  type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
208
209
  type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
209
- type InferPlatformContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IPlatformContext> ? IPlatformContext : never;
210
- type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IPlatformContext, infer IRoomContext> ? IPlatformContext & IRoomContext : never;
211
- type AbstractPlatformConfig<TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> = {
212
- context?: TPlatformContext & TRoomContext;
210
+ type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
211
+ type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
212
+ type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
213
+ context?: TRoomContext;
213
214
  persistence?: AbstractPersistence;
214
215
  pubSub?: AbstractPubSub;
215
216
  };
216
217
  interface ConvertWebSocketConfig {
217
218
  room: string;
218
219
  }
219
- declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
220
- protected readonly _ioContext: TPlatformContext | undefined;
220
+ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
221
+ protected readonly _initContext: TInitContext | undefined;
221
222
  protected readonly _roomContext: TRoomContext | undefined;
222
223
  private _initialized;
223
224
  persistence: AbstractPersistence;
224
225
  pubSub: AbstractPubSub;
225
226
  abstract readonly _registrationMode: WebSocketRegistrationMode;
226
- constructor(config?: AbstractPlatformConfig<TPlatformContext, TRoomContext>);
227
+ constructor(config?: AbstractPlatformConfig<TRoomContext>);
227
228
  abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
228
229
  abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
229
230
  abstract getLastPing(webSocket: AbstractWebSocket): number | null;
230
231
  abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
231
232
  abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
232
233
  abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
233
- abstract initialize(config: AbstractPlatformConfig<TPlatformContext, TRoomContext>): this;
234
+ abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
234
235
  abstract parseData(data: string | ArrayBuffer): Record<string, any>;
235
236
  abstract randomUUID(): string;
236
237
  abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
@@ -246,7 +247,7 @@ type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform>
246
247
  maxAge?: number;
247
248
  room: string;
248
249
  user: TUser;
249
- } & InferPlatformContextType<TPlatform>;
250
+ } & InferInitContextType<TPlatform>;
250
251
  interface AuthorizeParams {
251
252
  platform: AbstractPlatform;
252
253
  secret: string;
@@ -260,27 +261,28 @@ declare const authorize: (params: AuthorizeParams) => {
260
261
  encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
261
262
  };
262
263
 
263
- interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
264
+ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
264
265
  onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
265
266
  onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
266
267
  }
267
268
  type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
268
269
  [event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
269
270
  };
270
- type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
271
+ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
271
272
  authorize?: TAuthorize;
272
- context: TContext & InferRoomContextType<TPlatform>;
273
+ context: TContext;
273
274
  crdt?: {
274
275
  doc: (value: any) => AbstractCrdtDocFactory<any>;
275
276
  };
276
277
  debug: boolean;
277
278
  platform: TPlatform;
279
+ roomContext: InferRoomContextType<TPlatform>;
278
280
  router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
279
281
  };
280
- interface WebsocketRegisterOptions {
282
+ type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
281
283
  token?: string | null;
282
- }
283
- declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
284
+ } & InferInitContextType<TPlatform>;
285
+ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
284
286
  readonly id: string;
285
287
  private _doc;
286
288
  private _uninitialize;
@@ -299,7 +301,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
299
301
  */
300
302
  get _defs(): {
301
303
  authorize: TAuthorize | null;
302
- context: TContext & InferRoomContextType<TPlatform>;
304
+ context: TContext;
303
305
  events: TEvents;
304
306
  platform: TPlatform;
305
307
  };
@@ -310,7 +312,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
310
312
  onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
311
313
  onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
312
314
  onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
313
- register(webSocket: InferPlatformWebSocketSource<TPlatform>, options?: WebsocketRegisterOptions): Promise<void>;
315
+ register(webSocket: InferPlatformWebSocketSource<TPlatform>, ...options: keyof InferInitContextType<TPlatform> extends never ? [{
316
+ token?: string;
317
+ }?] : [WebsocketRegisterConfig<TPlatform>]): Promise<void>;
314
318
  private _broadcast;
315
319
  private _emitQuitters;
316
320
  private _emitRegistered;
@@ -335,9 +339,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
335
339
  }
336
340
 
337
341
  type InferIORoom<TServer extends PluvServer<any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, IEvents> : never;
338
- type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
342
+ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
339
343
  authorize?: TAuthorize;
340
- context?: TContext;
344
+ context?: PluvContext<TPlatform, TContext>;
341
345
  crdt?: {
342
346
  doc: (value: any) => AbstractCrdtDocFactory<any>;
343
347
  };
@@ -346,11 +350,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
346
350
  platform: TPlatform;
347
351
  router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
348
352
  };
349
- type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
353
+ type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
350
354
  debug?: boolean;
351
355
  };
352
- type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
353
- declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
356
+ type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
357
+ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
354
358
  readonly version: string;
355
359
  private readonly _authorize;
356
360
  private readonly _baseRouter;
@@ -367,7 +371,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
367
371
  */
368
372
  get _defs(): {
369
373
  authorize: TAuthorize | null;
370
- context: TContext;
374
+ context: PluvContext<TPlatform, TContext>;
371
375
  events: TEvents;
372
376
  platform: TPlatform;
373
377
  };
@@ -379,18 +383,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
379
383
  private _logDebug;
380
384
  }
381
385
 
382
- type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = {
386
+ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
383
387
  authorize?: TAuthorize;
384
- context?: TContext;
388
+ context?: PluvContext<TPlatform, TContext>;
385
389
  crdt?: CrdtLibraryType;
386
390
  debug?: boolean;
387
391
  platform: TPlatform;
388
392
  };
389
- type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
393
+ type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
390
394
  getInitialStorage?: GetInitialStorageFn<TPlatform>;
391
395
  router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
392
396
  };
393
- declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> {
397
+ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
394
398
  readonly version: string;
395
399
  private readonly _authorize;
396
400
  private readonly _context;
@@ -405,13 +409,13 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
405
409
  server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
406
410
  }
407
411
 
408
- type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
409
- authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
410
- context?: TContext;
412
+ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
413
+ authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
414
+ context?: PluvContext<TPlatform, TContext>;
411
415
  crdt?: CrdtLibraryType;
412
416
  debug?: boolean;
413
417
  platform: TPlatform;
414
418
  };
415
- declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>, TContext>;
419
+ declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
416
420
 
417
- export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
421
+ export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
package/dist/index.js CHANGED
@@ -220,7 +220,6 @@ var AbstractPlatform = class {
220
220
  this._initialized = false;
221
221
  const { context, persistence, pubSub } = config;
222
222
  this._meta = config._meta;
223
- context && (this._ioContext = context);
224
223
  context && (this._roomContext = context);
225
224
  this.persistence = persistence != null ? persistence : new Persistence();
226
225
  this.pubSub = pubSub != null ? pubSub : new PubSub();
@@ -408,6 +407,7 @@ var IORoom = class {
408
407
  onDestroy,
409
408
  onMessage,
410
409
  platform,
410
+ roomContext,
411
411
  router
412
412
  } = config;
413
413
  this.id = id;
@@ -415,7 +415,7 @@ var IORoom = class {
415
415
  this._debug = debug;
416
416
  this._docFactory = crdt.doc(() => ({}));
417
417
  this._router = router;
418
- this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context }));
418
+ this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
419
419
  this._listeners = {
420
420
  onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
421
421
  onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
@@ -495,9 +495,11 @@ var IORoom = class {
495
495
  });
496
496
  return this._onMessage(wsSession);
497
497
  }
498
- register(_0) {
499
- return __async(this, arguments, function* (webSocket, options = {}) {
500
- const { token } = options;
498
+ register(webSocket, ...options) {
499
+ return __async(this, null, function* () {
500
+ var _a, _b;
501
+ const _options = (_a = options[0]) != null ? _a : {};
502
+ const token = (_b = _options.token) != null ? _b : null;
501
503
  const sessionId = this._platform.getSessionId(webSocket);
502
504
  const sessionExists = typeof sessionId === "string" && this._sessions.has(sessionId);
503
505
  if (sessionExists) return;
@@ -505,12 +507,12 @@ var IORoom = class {
505
507
  this._initialize();
506
508
  yield this._initialized;
507
509
  }
508
- const user = yield this._getAuthorizedUser(token);
509
- const ioAuthorize = this._getIOAuthorize();
510
+ const user = yield this._getAuthorizedUser(token, _options);
511
+ const ioAuthorize = this._getIOAuthorize(_options);
510
512
  const isUnauthorized = !!(ioAuthorize == null ? void 0 : ioAuthorize.required) && !user;
511
513
  const isTokenInUse = !!user && (yield this._getSessions().then((sessions) => sessions.some((session) => {
512
- var _a;
513
- return ((_a = session.user) == null ? void 0 : _a.id) === user.id;
514
+ var _a2;
515
+ return ((_a2 = session.user) == null ? void 0 : _a2.id) === user.id;
514
516
  })));
515
517
  const pluvWs = this._platform.convertWebSocket(webSocket, { room: this.id });
516
518
  this._logDebug(`${import_kleur.default.blue(`Registering connection for room ${this.id}:`)} ${pluvWs.sessionId}`);
@@ -594,10 +596,10 @@ var IORoom = class {
594
596
  const sessions = Array.from(this._sessions.values());
595
597
  return (_b = sessions.find((pluvWs) => pluvWs.webSocket === webSocket)) != null ? _b : null;
596
598
  }
597
- _getAuthorizedUser(token) {
599
+ _getAuthorizedUser(token, options) {
598
600
  return __async(this, null, function* () {
599
601
  var _a;
600
- const ioAuthorize = this._getIOAuthorize();
602
+ const ioAuthorize = this._getIOAuthorize(options);
601
603
  if (!ioAuthorize) return null;
602
604
  if (!token) return null;
603
605
  const payload = yield authorize({
@@ -631,9 +633,9 @@ var IORoom = class {
631
633
  return doc;
632
634
  });
633
635
  }
634
- _getIOAuthorize() {
636
+ _getIOAuthorize(options) {
635
637
  if (typeof this._authorize === "function") {
636
- return this._authorize(this._context);
638
+ return this._authorize(options);
637
639
  }
638
640
  return this._authorize;
639
641
  }
@@ -753,7 +755,7 @@ var IORoom = class {
753
755
  this._getSessions()
754
756
  ]);
755
757
  const doc = yield this._doc;
756
- const baseContext = {
758
+ const eventContext = {
757
759
  context: this._context,
758
760
  doc,
759
761
  room: this.id,
@@ -795,11 +797,10 @@ var IORoom = class {
795
797
  });
796
798
  return;
797
799
  }
798
- const extendedContext = __spreadProps(__spreadValues({}, baseContext), { context: __spreadValues({}, this._context) });
799
800
  yield Promise.all([
800
- (_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, extendedContext),
801
- (_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, extendedContext),
802
- (_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, baseContext)
801
+ (_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, eventContext),
802
+ (_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, eventContext),
803
+ (_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, eventContext)
803
804
  ]).then((_0) => __async(this, [_0], function* ([broadcast, self, sync]) {
804
805
  const handleBroadcast = () => __async(this, null, function* () {
805
806
  if (!broadcast) return;
@@ -931,7 +932,7 @@ var IORoom = class {
931
932
  };
932
933
 
933
934
  // src/version.generated.ts
934
- var version = "0.30.2";
935
+ var version = "0.32.0";
935
936
 
936
937
  // src/PluvServer.ts
937
938
  var PluvServer = class {
@@ -1068,10 +1069,11 @@ var PluvServer = class {
1068
1069
  var _a, _c;
1069
1070
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1070
1071
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1071
- const roomContext = __spreadValues(__spreadValues({}, this._context), platformRoomContext);
1072
+ const roomContext = platformRoomContext;
1073
+ const context = typeof this._context === "function" ? this._context(roomContext) : this._context;
1072
1074
  const newRoom = new IORoom(room, __spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), {
1073
1075
  authorize: (_c = this._authorize) != null ? _c : void 0,
1074
- context: roomContext,
1076
+ context,
1075
1077
  crdt: this._crdt,
1076
1078
  debug: debug != null ? debug : this._debug,
1077
1079
  onDestroy: (event) => __async(this, null, function* () {
@@ -1086,6 +1088,7 @@ var PluvServer = class {
1086
1088
  yield Promise.resolve(this._getListeners().onRoomMessage(event));
1087
1089
  }),
1088
1090
  platform: this._platform,
1091
+ roomContext,
1089
1092
  router: this._router
1090
1093
  }));
1091
1094
  this._logDebug(`${import_kleur2.default.blue("Created room:")} ${room}`);
package/dist/index.mjs CHANGED
@@ -178,7 +178,6 @@ var AbstractPlatform = class {
178
178
  this._initialized = false;
179
179
  const { context, persistence, pubSub } = config;
180
180
  this._meta = config._meta;
181
- context && (this._ioContext = context);
182
181
  context && (this._roomContext = context);
183
182
  this.persistence = persistence != null ? persistence : new Persistence();
184
183
  this.pubSub = pubSub != null ? pubSub : new PubSub();
@@ -366,6 +365,7 @@ var IORoom = class {
366
365
  onDestroy,
367
366
  onMessage,
368
367
  platform,
368
+ roomContext,
369
369
  router
370
370
  } = config;
371
371
  this.id = id;
@@ -373,7 +373,7 @@ var IORoom = class {
373
373
  this._debug = debug;
374
374
  this._docFactory = crdt.doc(() => ({}));
375
375
  this._router = router;
376
- this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context }));
376
+ this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
377
377
  this._listeners = {
378
378
  onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
379
379
  onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
@@ -453,9 +453,11 @@ var IORoom = class {
453
453
  });
454
454
  return this._onMessage(wsSession);
455
455
  }
456
- register(_0) {
457
- return __async(this, arguments, function* (webSocket, options = {}) {
458
- const { token } = options;
456
+ register(webSocket, ...options) {
457
+ return __async(this, null, function* () {
458
+ var _a, _b;
459
+ const _options = (_a = options[0]) != null ? _a : {};
460
+ const token = (_b = _options.token) != null ? _b : null;
459
461
  const sessionId = this._platform.getSessionId(webSocket);
460
462
  const sessionExists = typeof sessionId === "string" && this._sessions.has(sessionId);
461
463
  if (sessionExists) return;
@@ -463,12 +465,12 @@ var IORoom = class {
463
465
  this._initialize();
464
466
  yield this._initialized;
465
467
  }
466
- const user = yield this._getAuthorizedUser(token);
467
- const ioAuthorize = this._getIOAuthorize();
468
+ const user = yield this._getAuthorizedUser(token, _options);
469
+ const ioAuthorize = this._getIOAuthorize(_options);
468
470
  const isUnauthorized = !!(ioAuthorize == null ? void 0 : ioAuthorize.required) && !user;
469
471
  const isTokenInUse = !!user && (yield this._getSessions().then((sessions) => sessions.some((session) => {
470
- var _a;
471
- return ((_a = session.user) == null ? void 0 : _a.id) === user.id;
472
+ var _a2;
473
+ return ((_a2 = session.user) == null ? void 0 : _a2.id) === user.id;
472
474
  })));
473
475
  const pluvWs = this._platform.convertWebSocket(webSocket, { room: this.id });
474
476
  this._logDebug(`${colors.blue(`Registering connection for room ${this.id}:`)} ${pluvWs.sessionId}`);
@@ -552,10 +554,10 @@ var IORoom = class {
552
554
  const sessions = Array.from(this._sessions.values());
553
555
  return (_b = sessions.find((pluvWs) => pluvWs.webSocket === webSocket)) != null ? _b : null;
554
556
  }
555
- _getAuthorizedUser(token) {
557
+ _getAuthorizedUser(token, options) {
556
558
  return __async(this, null, function* () {
557
559
  var _a;
558
- const ioAuthorize = this._getIOAuthorize();
560
+ const ioAuthorize = this._getIOAuthorize(options);
559
561
  if (!ioAuthorize) return null;
560
562
  if (!token) return null;
561
563
  const payload = yield authorize({
@@ -589,9 +591,9 @@ var IORoom = class {
589
591
  return doc;
590
592
  });
591
593
  }
592
- _getIOAuthorize() {
594
+ _getIOAuthorize(options) {
593
595
  if (typeof this._authorize === "function") {
594
- return this._authorize(this._context);
596
+ return this._authorize(options);
595
597
  }
596
598
  return this._authorize;
597
599
  }
@@ -711,7 +713,7 @@ var IORoom = class {
711
713
  this._getSessions()
712
714
  ]);
713
715
  const doc = yield this._doc;
714
- const baseContext = {
716
+ const eventContext = {
715
717
  context: this._context,
716
718
  doc,
717
719
  room: this.id,
@@ -753,11 +755,10 @@ var IORoom = class {
753
755
  });
754
756
  return;
755
757
  }
756
- const extendedContext = __spreadProps(__spreadValues({}, baseContext), { context: __spreadValues({}, this._context) });
757
758
  yield Promise.all([
758
- (_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, extendedContext),
759
- (_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, extendedContext),
760
- (_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, baseContext)
759
+ (_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, eventContext),
760
+ (_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, eventContext),
761
+ (_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, eventContext)
761
762
  ]).then((_0) => __async(this, [_0], function* ([broadcast, self, sync]) {
762
763
  const handleBroadcast = () => __async(this, null, function* () {
763
764
  if (!broadcast) return;
@@ -889,7 +890,7 @@ var IORoom = class {
889
890
  };
890
891
 
891
892
  // src/version.generated.ts
892
- var version = "0.30.2";
893
+ var version = "0.32.0";
893
894
 
894
895
  // src/PluvServer.ts
895
896
  var PluvServer = class {
@@ -1026,10 +1027,11 @@ var PluvServer = class {
1026
1027
  var _a, _c;
1027
1028
  const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
1028
1029
  if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
1029
- const roomContext = __spreadValues(__spreadValues({}, this._context), platformRoomContext);
1030
+ const roomContext = platformRoomContext;
1031
+ const context = typeof this._context === "function" ? this._context(roomContext) : this._context;
1030
1032
  const newRoom = new IORoom(room, __spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), {
1031
1033
  authorize: (_c = this._authorize) != null ? _c : void 0,
1032
- context: roomContext,
1034
+ context,
1033
1035
  crdt: this._crdt,
1034
1036
  debug: debug != null ? debug : this._debug,
1035
1037
  onDestroy: (event) => __async(this, null, function* () {
@@ -1044,6 +1046,7 @@ var PluvServer = class {
1044
1046
  yield Promise.resolve(this._getListeners().onRoomMessage(event));
1045
1047
  }),
1046
1048
  platform: this._platform,
1049
+ roomContext,
1047
1050
  router: this._router
1048
1051
  }));
1049
1052
  this._logDebug(`${colors2.blue("Created room:")} ${room}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.30.2",
3
+ "version": "0.32.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.9.3",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.4",
24
- "@pluv/crdt": "^0.30.2",
25
- "@pluv/types": "^0.30.2"
24
+ "@pluv/crdt": "^0.32.0",
25
+ "@pluv/types": "^0.32.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.0",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.3.0",
31
31
  "typescript": "^5.6.2",
32
- "@pluv/tsconfig": "^0.30.2",
33
- "eslint-config-pluv": "^0.30.2"
32
+ "@pluv/tsconfig": "^0.32.0",
33
+ "eslint-config-pluv": "^0.32.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",