@pluv/io 0.32.1 → 0.32.3

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.
@@ -1,9 +1,9 @@
1
1
 
2
- > @pluv/io@0.32.1 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.32.3 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@0.32.1 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@0.32.3 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- ESM dist/index.mjs 39.90 KB
16
- ESM ⚡️ Build success in 145ms
17
- CJS dist/index.js 42.08 KB
18
- CJS ⚡️ Build success in 160ms
15
+ ESM dist/index.mjs 40.83 KB
16
+ ESM ⚡️ Build success in 163ms
17
+ CJS dist/index.js 43.00 KB
18
+ CJS ⚡️ Build success in 172ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 2517ms
21
- DTS dist/index.d.mts 25.82 KB
22
- DTS dist/index.d.ts 25.82 KB
20
+ DTS ⚡️ Build success in 2374ms
21
+ DTS dist/index.d.mts 26.66 KB
22
+ DTS dist/index.d.ts 26.66 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.32.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb21274: Added the ability to evict (i.e. close) a connection to a room via `IORoom.evict` and `IORoom.evictAll`.
8
+ - @pluv/crdt@0.32.3
9
+ - @pluv/types@0.32.3
10
+
11
+ ## 0.32.2
12
+
13
+ ### Patch Changes
14
+
15
+ - 890d45b: Update `onRoomMessage` and `onStorageUpdated` events to include the WebSocket as part of the `event` parameter of those listeners.
16
+ - @pluv/crdt@0.32.2
17
+ - @pluv/types@0.32.2
18
+
3
19
  ## 0.32.1
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -182,7 +182,7 @@ type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitia
182
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>> {
183
183
  onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
184
184
  onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
185
- onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
185
+ onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
186
186
  }
187
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
188
  context: TContext;
@@ -192,6 +192,11 @@ type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize ext
192
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> & {
193
193
  message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
194
194
  user?: InferIOAuthorizeUser<TAuthorize>;
195
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
196
+ };
197
+ type IOStorageUpdatedEvent<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> & {
198
+ user?: InferIOAuthorizeUser<TAuthorize>;
199
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
195
200
  };
196
201
  type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
197
202
 
@@ -308,6 +313,16 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
308
313
  get broadcast(): BroadcastProxy<this>;
309
314
  private get _initialized();
310
315
  constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
316
+ /**
317
+ * @description Closes a connection with the specified sessionId
318
+ * @param sessionId The session id of the connection to close
319
+ */
320
+ evict(sessionId: string): Promise<void>;
321
+ /**
322
+ * @description Closes all connections to this room, effectively destroying
323
+ * the room
324
+ */
325
+ evictAll(): Promise<void>;
311
326
  getSize(): number;
312
327
  onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
313
328
  onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
@@ -354,7 +369,7 @@ type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize e
354
369
  debug?: boolean;
355
370
  };
356
371
  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> {
372
+ 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 IOLike<TAuthorize, TEvents> {
358
373
  readonly version: string;
359
374
  private readonly _authorize;
360
375
  private readonly _baseRouter;
@@ -418,4 +433,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
418
433
  };
419
434
  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>;
420
435
 
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 };
436
+ 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 IOStorageUpdatedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
package/dist/index.d.ts CHANGED
@@ -182,7 +182,7 @@ type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitia
182
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>> {
183
183
  onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
184
184
  onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
185
- onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
185
+ onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
186
186
  }
187
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
188
  context: TContext;
@@ -192,6 +192,11 @@ type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize ext
192
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> & {
193
193
  message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
194
194
  user?: InferIOAuthorizeUser<TAuthorize>;
195
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
196
+ };
197
+ type IOStorageUpdatedEvent<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> & {
198
+ user?: InferIOAuthorizeUser<TAuthorize>;
199
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
195
200
  };
196
201
  type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
197
202
 
@@ -308,6 +313,16 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
308
313
  get broadcast(): BroadcastProxy<this>;
309
314
  private get _initialized();
310
315
  constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
316
+ /**
317
+ * @description Closes a connection with the specified sessionId
318
+ * @param sessionId The session id of the connection to close
319
+ */
320
+ evict(sessionId: string): Promise<void>;
321
+ /**
322
+ * @description Closes all connections to this room, effectively destroying
323
+ * the room
324
+ */
325
+ evictAll(): Promise<void>;
311
326
  getSize(): number;
312
327
  onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
313
328
  onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
@@ -354,7 +369,7 @@ type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize e
354
369
  debug?: boolean;
355
370
  };
356
371
  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> {
372
+ 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 IOLike<TAuthorize, TEvents> {
358
373
  readonly version: string;
359
374
  private readonly _authorize;
360
375
  private readonly _baseRouter;
@@ -418,4 +433,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
418
433
  };
419
434
  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>;
420
435
 
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 };
436
+ 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 IOStorageUpdatedEvent, 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
@@ -462,6 +462,30 @@ var IORoom = class {
462
462
  var _a;
463
463
  return Promise.resolve(!!((_a = this._uninitialize) == null ? void 0 : _a.then((result) => !!result)));
464
464
  }
465
+ /**
466
+ * @description Closes a connection with the specified sessionId
467
+ * @param sessionId The session id of the connection to close
468
+ */
469
+ evict(sessionId) {
470
+ return __async(this, null, function* () {
471
+ const session = this._sessions.get(sessionId);
472
+ if (session) session.state.quit = true;
473
+ yield this._emitQuitters();
474
+ });
475
+ }
476
+ /**
477
+ * @description Closes all connections to this room, effectively destroying
478
+ * the room
479
+ */
480
+ evictAll() {
481
+ return __async(this, null, function* () {
482
+ const sessions = Array.from(this._sessions.values());
483
+ sessions.forEach((session) => {
484
+ session.state.quit = true;
485
+ });
486
+ yield this._emitQuitters();
487
+ });
488
+ }
465
489
  getSize() {
466
490
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
467
491
  return Array.from(this._sessions.values()).reduce((count, pluvWs) => {
@@ -774,7 +798,8 @@ var IORoom = class {
774
798
  encodedState: doc.getEncodedState(),
775
799
  message,
776
800
  room: this.id,
777
- user: session.user
801
+ user: session.user,
802
+ webSocket: session.webSocket.webSocket
778
803
  }));
779
804
  const sessionId = session.id;
780
805
  const user = session.user;
@@ -932,7 +957,7 @@ var IORoom = class {
932
957
  };
933
958
 
934
959
  // src/version.generated.ts
935
- var version = "0.32.1";
960
+ var version = "0.32.3";
936
961
 
937
962
  // src/PluvServer.ts
938
963
  var PluvServer = class {
@@ -971,7 +996,7 @@ var PluvServer = class {
971
996
  presence
972
997
  }
973
998
  };
974
- }).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, room }) {
999
+ }).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, room, session }) {
975
1000
  var _a, _b;
976
1001
  const oldState = yield this._platform.persistence.getStorageState(room);
977
1002
  const update = data == null ? void 0 : data.update;
@@ -982,7 +1007,13 @@ var PluvServer = class {
982
1007
  if (updates.some((_update) => !!_update)) {
983
1008
  const encodedState = doc.batchApplyEncodedState(updates).getEncodedState();
984
1009
  yield this._platform.persistence.setStorageState(room, encodedState);
985
- this._getListeners().onStorageUpdated({ context, encodedState, room });
1010
+ this._getListeners().onStorageUpdated({
1011
+ context,
1012
+ encodedState,
1013
+ room,
1014
+ user: session == null ? void 0 : session.user,
1015
+ webSocket: session == null ? void 0 : session.webSocket.webSocket
1016
+ });
986
1017
  }
987
1018
  const state = (_b = yield this._platform.persistence.getStorageState(room)) != null ? _b : doc.getEncodedState();
988
1019
  return { $STORAGE_RECEIVED: { state } };
package/dist/index.mjs CHANGED
@@ -420,6 +420,30 @@ var IORoom = class {
420
420
  var _a;
421
421
  return Promise.resolve(!!((_a = this._uninitialize) == null ? void 0 : _a.then((result) => !!result)));
422
422
  }
423
+ /**
424
+ * @description Closes a connection with the specified sessionId
425
+ * @param sessionId The session id of the connection to close
426
+ */
427
+ evict(sessionId) {
428
+ return __async(this, null, function* () {
429
+ const session = this._sessions.get(sessionId);
430
+ if (session) session.state.quit = true;
431
+ yield this._emitQuitters();
432
+ });
433
+ }
434
+ /**
435
+ * @description Closes all connections to this room, effectively destroying
436
+ * the room
437
+ */
438
+ evictAll() {
439
+ return __async(this, null, function* () {
440
+ const sessions = Array.from(this._sessions.values());
441
+ sessions.forEach((session) => {
442
+ session.state.quit = true;
443
+ });
444
+ yield this._emitQuitters();
445
+ });
446
+ }
423
447
  getSize() {
424
448
  const currentTime = (/* @__PURE__ */ new Date()).getTime();
425
449
  return Array.from(this._sessions.values()).reduce((count, pluvWs) => {
@@ -732,7 +756,8 @@ var IORoom = class {
732
756
  encodedState: doc.getEncodedState(),
733
757
  message,
734
758
  room: this.id,
735
- user: session.user
759
+ user: session.user,
760
+ webSocket: session.webSocket.webSocket
736
761
  }));
737
762
  const sessionId = session.id;
738
763
  const user = session.user;
@@ -890,7 +915,7 @@ var IORoom = class {
890
915
  };
891
916
 
892
917
  // src/version.generated.ts
893
- var version = "0.32.1";
918
+ var version = "0.32.3";
894
919
 
895
920
  // src/PluvServer.ts
896
921
  var PluvServer = class {
@@ -929,7 +954,7 @@ var PluvServer = class {
929
954
  presence
930
955
  }
931
956
  };
932
- }).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, room }) {
957
+ }).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, room, session }) {
933
958
  var _a, _b;
934
959
  const oldState = yield this._platform.persistence.getStorageState(room);
935
960
  const update = data == null ? void 0 : data.update;
@@ -940,7 +965,13 @@ var PluvServer = class {
940
965
  if (updates.some((_update) => !!_update)) {
941
966
  const encodedState = doc.batchApplyEncodedState(updates).getEncodedState();
942
967
  yield this._platform.persistence.setStorageState(room, encodedState);
943
- this._getListeners().onStorageUpdated({ context, encodedState, room });
968
+ this._getListeners().onStorageUpdated({
969
+ context,
970
+ encodedState,
971
+ room,
972
+ user: session == null ? void 0 : session.user,
973
+ webSocket: session == null ? void 0 : session.webSocket.webSocket
974
+ });
944
975
  }
945
976
  const state = (_b = yield this._platform.persistence.getStorageState(room)) != null ? _b : doc.getEncodedState();
946
977
  return { $STORAGE_RECEIVED: { state } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.32.1",
3
+ "version": "0.32.3",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,19 +18,19 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@panva/hkdf": "^1.2.1",
21
- "jose": "^5.9.3",
21
+ "jose": "^5.9.4",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.4",
24
- "@pluv/crdt": "^0.32.1",
25
- "@pluv/types": "^0.32.1"
24
+ "@pluv/crdt": "^0.32.3",
25
+ "@pluv/types": "^0.32.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.0",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.3.0",
31
- "typescript": "^5.6.2",
32
- "@pluv/tsconfig": "^0.32.1",
33
- "eslint-config-pluv": "^0.32.1"
31
+ "typescript": "^5.6.3",
32
+ "@pluv/tsconfig": "^0.32.3",
33
+ "eslint-config-pluv": "^0.32.3"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
package/src/IORoom.ts CHANGED
@@ -191,6 +191,32 @@ export class IORoom<
191
191
  this._uninitialize = uninitialize;
192
192
  }
193
193
 
194
+ /**
195
+ * @description Closes a connection with the specified sessionId
196
+ * @param sessionId The session id of the connection to close
197
+ */
198
+ public async evict(sessionId: string): Promise<void> {
199
+ const session = this._sessions.get(sessionId);
200
+
201
+ if (session) session.state.quit = true;
202
+
203
+ await this._emitQuitters();
204
+ }
205
+
206
+ /**
207
+ * @description Closes all connections to this room, effectively destroying
208
+ * the room
209
+ */
210
+ public async evictAll(): Promise<void> {
211
+ const sessions = Array.from(this._sessions.values());
212
+
213
+ sessions.forEach((session) => {
214
+ session.state.quit = true;
215
+ });
216
+
217
+ await this._emitQuitters();
218
+ }
219
+
194
220
  public getSize(): number {
195
221
  const currentTime = new Date().getTime();
196
222
 
@@ -606,6 +632,7 @@ export class IORoom<
606
632
  message: message as InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>,
607
633
  room: this.id,
608
634
  user: session.user,
635
+ webSocket: session.webSocket.webSocket,
609
636
  });
610
637
 
611
638
  const sessionId = session.id;
package/src/PluvServer.ts CHANGED
@@ -3,7 +3,7 @@ import { noop } from "@pluv/crdt";
3
3
  import type {
4
4
  BaseIOAuthorize,
5
5
  IOAuthorize,
6
- IORouterLike,
6
+ IOLike,
7
7
  Id,
8
8
  InferIOAuthorize,
9
9
  InferIOAuthorizeUser,
@@ -66,7 +66,7 @@ export class PluvServer<
66
66
  TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
67
67
  TContext extends Record<string, any> = {},
68
68
  TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
69
- > implements IORouterLike<TEvents>
69
+ > implements IOLike<TAuthorize, TEvents>
70
70
  {
71
71
  public readonly version: string = __PLUV_VERSION as any;
72
72
 
@@ -120,7 +120,7 @@ export class PluvServer<
120
120
  },
121
121
  };
122
122
  })
123
- .self(async (data, { context, doc, room }) => {
123
+ .self(async (data, { context, doc, room, session }) => {
124
124
  const oldState = await this._platform.persistence.getStorageState(room);
125
125
  const update = (data as any)?.update as Maybe<string>;
126
126
 
@@ -134,7 +134,13 @@ export class PluvServer<
134
134
 
135
135
  await this._platform.persistence.setStorageState(room, encodedState);
136
136
 
137
- this._getListeners().onStorageUpdated({ context, encodedState, room });
137
+ this._getListeners().onStorageUpdated({
138
+ context,
139
+ encodedState,
140
+ room,
141
+ user: session?.user,
142
+ webSocket: session?.webSocket.webSocket,
143
+ });
138
144
  }
139
145
 
140
146
  const state = (await this._platform.persistence.getStorageState(room)) ?? doc.getEncodedState();
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export type {
40
40
  GetInitialStorageFn,
41
41
  IORoomListenerEvent,
42
42
  IORoomMessageEvent,
43
+ IOStorageUpdatedEvent,
43
44
  PluvIOListeners,
44
45
  WebSocketSerializedState,
45
46
  WebSocketSession,
package/src/types.ts CHANGED
@@ -18,7 +18,7 @@ import type {
18
18
  InferPlatformWebSocketType,
19
19
  InferRoomContextType,
20
20
  } from "./AbstractPlatform";
21
- import type { AbstractWebSocket } from "./AbstractWebSocket";
21
+ import type { AbstractWebSocket, InferWebSocketSource } from "./AbstractWebSocket";
22
22
  import type { PluvRouterEventConfig } from "./PluvRouter";
23
23
 
24
24
  declare global {
@@ -122,7 +122,7 @@ export interface PluvIOListeners<
122
122
  > {
123
123
  onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
124
124
  onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
125
- onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
125
+ onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
126
126
  }
127
127
 
128
128
  export type IORoomListenerEvent<
@@ -144,6 +144,17 @@ export type IORoomMessageEvent<
144
144
  > = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
145
145
  message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
146
146
  user?: InferIOAuthorizeUser<TAuthorize>;
147
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
148
+ };
149
+
150
+ export type IOStorageUpdatedEvent<
151
+ TPlatform extends AbstractPlatform<any>,
152
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
153
+ TContext extends Record<string, any>,
154
+ TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
155
+ > = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
156
+ user?: InferIOAuthorizeUser<TAuthorize>;
157
+ webSocket?: InferPlatformWebSocketSource<TPlatform>;
147
158
  };
148
159
 
149
160
  export type WebSocketType<TPlatform extends AbstractPlatform> =
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.32.1'
2
+ export const version = '0.32.3'