@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.17.2",
3
+ "version": "0.18.0",
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.1.1",
21
- "jose": "^5.2.4",
21
+ "jose": "^5.3.0",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.4",
24
- "@pluv/crdt": "^0.17.2",
25
- "@pluv/types": "^0.17.2"
24
+ "@pluv/crdt": "^0.18.0",
25
+ "@pluv/types": "^0.18.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.0",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.0.2",
31
31
  "typescript": "^5.4.5",
32
- "@pluv/tsconfig": "^0.17.2",
33
- "eslint-config-pluv": "^0.17.2"
32
+ "@pluv/tsconfig": "^0.18.0",
33
+ "eslint-config-pluv": "^0.18.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
@@ -1,18 +1,11 @@
1
1
  import type { JsonObject } from "@pluv/types";
2
2
 
3
3
  export abstract class AbstractPersistance {
4
- public abstract addUser(
5
- room: string,
6
- connectionId: string,
7
- user: JsonObject | null,
8
- ): Promise<void>;
4
+ public abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
9
5
 
10
6
  public abstract deleteStorageState(room: string): Promise<void>;
11
7
 
12
- public abstract deleteUser(
13
- room: string,
14
- connectionId: string,
15
- ): Promise<void>;
8
+ public abstract deleteUser(room: string, connectionId: string): Promise<void>;
16
9
 
17
10
  public abstract deleteUsers(room: string): Promise<void>;
18
11
 
@@ -20,14 +13,9 @@ export abstract class AbstractPersistance {
20
13
 
21
14
  public abstract getStorageState(room: string): Promise<string | null>;
22
15
 
23
- public abstract getUser(
24
- room: string,
25
- connectionId: string,
26
- ): Promise<JsonObject | null>;
16
+ public abstract getUser(room: string, connectionId: string): Promise<JsonObject | null>;
27
17
 
28
- public abstract getUsers(
29
- room: string,
30
- ): Promise<readonly (JsonObject | null)[]>;
18
+ public abstract getUsers(room: string): Promise<readonly (JsonObject | null)[]>;
31
19
 
32
20
  public abstract setStorageState(room: string, state: string): Promise<void>;
33
21
  }
@@ -1,9 +1,6 @@
1
1
  import { AbstractPersistance } from "./AbstractPersistance";
2
2
  import type { AbstractPubSub } from "./AbstractPubSub";
3
- import type {
4
- AbstractWebSocket,
5
- AbstractWebSocketConfig,
6
- } from "./AbstractWebSocket";
3
+ import type { AbstractWebSocket, AbstractWebSocketConfig } from "./AbstractWebSocket";
7
4
  import { Persistance } from "./Persistance";
8
5
  import { PubSub } from "./PubSub";
9
6
 
@@ -11,14 +8,10 @@ export type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> =
11
8
  TPlatform extends AbstractPlatform<infer IWebSocket> ? IWebSocket : never;
12
9
 
13
10
  export type InferPlatformRoomContextType<TPlatform extends AbstractPlatform> =
14
- TPlatform extends AbstractPlatform<any, infer IIOContext>
15
- ? IIOContext
16
- : never;
11
+ TPlatform extends AbstractPlatform<any, infer IIOContext> ? IIOContext : never;
17
12
 
18
13
  export type InferPlatformEventContextType<TPlatform extends AbstractPlatform> =
19
- TPlatform extends AbstractPlatform<any, any, infer IRoomContext>
20
- ? IRoomContext
21
- : never;
14
+ TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
22
15
 
23
16
  export type AbstractPlatformConfig =
24
17
  | { persistance?: undefined; pubSub?: undefined }
@@ -47,10 +40,7 @@ export abstract class AbstractPlatform<
47
40
  this.pubSub = pubSub ?? new PubSub();
48
41
  }
49
42
 
50
- public abstract convertWebSocket(
51
- webSocket: TWebSocket,
52
- config: ConvertWebSocketConfig,
53
- ): AbstractWebSocket;
43
+ public abstract convertWebSocket(webSocket: TWebSocket, config: ConvertWebSocketConfig): AbstractWebSocket;
54
44
 
55
45
  public abstract parseData(data: string | ArrayBuffer): Record<string, any>;
56
46
 
@@ -9,10 +9,7 @@ export type IOPubSubEventMessage<
9
9
  };
10
10
 
11
11
  export abstract class AbstractPubSub {
12
- public abstract publish(
13
- roomName: string,
14
- payload: IOPubSubEventMessage<any>,
15
- ): Promise<void>;
12
+ public abstract publish(roomName: string, payload: IOPubSubEventMessage<any>): Promise<void>;
16
13
 
17
14
  public abstract subscribe(
18
15
  roomName: string,
@@ -28,7 +28,7 @@ export type EventType = keyof AbstractEventMap;
28
28
  export interface AbstractWebSocketHandleErrorParams {
29
29
  error: unknown;
30
30
  message?: string;
31
- session?: WebSocketSession;
31
+ session?: WebSocketSession<any>;
32
32
  }
33
33
 
34
34
  export type AbstractListener<TType extends keyof AbstractEventMap> = (
@@ -73,15 +73,9 @@ export abstract class AbstractWebSocket {
73
73
  * @author leedavidcs
74
74
  * @date August 28, 2022
75
75
  */
76
- public abstract addEventListener<TType extends EventType>(
77
- type: TType,
78
- handler: AbstractListener<TType>,
79
- ): void;
76
+ public abstract addEventListener<TType extends EventType>(type: TType, handler: AbstractListener<TType>): void;
80
77
 
81
- public abstract close(
82
- code?: number | undefined,
83
- reason?: string | undefined,
84
- ): void;
78
+ public abstract close(code?: number | undefined, reason?: string | undefined): void;
85
79
 
86
80
  public abstract initialize(): Promise<() => void>;
87
81
 
@@ -90,16 +84,9 @@ export abstract class AbstractWebSocket {
90
84
  public abstract terminate(): void;
91
85
 
92
86
  public handleError(params: AbstractWebSocketHandleErrorParams): void {
93
- const {
94
- error,
95
- message = error instanceof Error
96
- ? error.message
97
- : "Unexpected error",
98
- session,
99
- } = params;
87
+ const { error, message = error instanceof Error ? error.message : "Unexpected error", session } = params;
100
88
 
101
- const stack: string | null =
102
- error instanceof Error ? error.stack ?? null : null;
89
+ const stack: string | null = error instanceof Error ? error.stack ?? null : null;
103
90
 
104
91
  return this.sendMessage({
105
92
  connectionId: session?.id ?? null,
@@ -110,9 +97,7 @@ export abstract class AbstractWebSocket {
110
97
  });
111
98
  }
112
99
 
113
- public sendMessage<
114
- TMessage extends IOEventMessage<any> = IOEventMessage<any>,
115
- >(data: TMessage): void {
100
+ public sendMessage<TMessage extends IOEventMessage<any> = IOEventMessage<any>>(data: TMessage): void {
116
101
  return this.send(JSON.stringify(data));
117
102
  }
118
103
  }