@pluv/platform-node 0.23.0 → 0.24.1

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,5 +1,5 @@
1
1
 
2
- > @pluv/platform-node@0.23.0 build /home/runner/work/pluv/pluv/packages/platform-node
2
+ > @pluv/platform-node@0.24.1 build /home/runner/work/pluv/pluv/packages/platform-node
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 7.63 KB
12
- ESM ⚡️ Build success in 114ms
13
- CJS dist/index.js 9.40 KB
14
- CJS ⚡️ Build success in 113ms
11
+ ESM dist/index.mjs 8.05 KB
12
+ ESM ⚡️ Build success in 108ms
13
+ CJS dist/index.js 9.83 KB
14
+ CJS ⚡️ Build success in 109ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3641ms
16
+ DTS ⚡️ Build success in 4092ms
17
17
  DTS dist/index.d.mts 3.60 KB
18
18
  DTS dist/index.d.ts 3.60 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pluv/platform-node
2
2
 
3
+ ## 0.24.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/io@0.24.1
8
+ - @pluv/types@0.24.1
9
+
10
+ ## 0.24.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [6ac8a46]
15
+ - Updated dependencies [c26986d]
16
+ - @pluv/io@0.24.0
17
+ - @pluv/types@0.24.0
18
+
3
19
  ## 0.23.0
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -93,6 +93,21 @@ var createPluvHandler = (config) => {
93
93
  throw new Error("Cannot use createPluvHandler in detached mode for Node.js");
94
94
  }
95
95
  const wsServer = new import_ws.Server({ server });
96
+ const rooms = /* @__PURE__ */ new Map();
97
+ const getRoom = (roomId) => {
98
+ Array.from(rooms.values()).forEach((room) => {
99
+ if (!room.getSize()) rooms.delete(room.id);
100
+ });
101
+ const existing = rooms.get(roomId);
102
+ if (existing) return existing;
103
+ const newRoom = io.createRoom(roomId, {
104
+ onDestroy: (event) => {
105
+ rooms.delete(event.room);
106
+ }
107
+ });
108
+ rooms.set(roomId, newRoom);
109
+ return newRoom;
110
+ };
96
111
  const wsHandler = (ws, req) => __async(void 0, null, function* () {
97
112
  var _a;
98
113
  const url = req.url;
@@ -111,7 +126,7 @@ var createPluvHandler = (config) => {
111
126
  if (!roomId) return onError.invalidRoom();
112
127
  const token = ((_a = parsed.query) == null ? void 0 : _a.token) || void 0;
113
128
  if (Array.isArray(token)) return onError.invalidToken();
114
- const room = io.getRoom(roomId);
129
+ const room = getRoom(roomId);
115
130
  yield room.register(ws, { token });
116
131
  return { matched: true };
117
132
  });
package/dist/index.mjs CHANGED
@@ -59,6 +59,21 @@ var createPluvHandler = (config) => {
59
59
  throw new Error("Cannot use createPluvHandler in detached mode for Node.js");
60
60
  }
61
61
  const wsServer = new WsServer({ server });
62
+ const rooms = /* @__PURE__ */ new Map();
63
+ const getRoom = (roomId) => {
64
+ Array.from(rooms.values()).forEach((room) => {
65
+ if (!room.getSize()) rooms.delete(room.id);
66
+ });
67
+ const existing = rooms.get(roomId);
68
+ if (existing) return existing;
69
+ const newRoom = io.createRoom(roomId, {
70
+ onDestroy: (event) => {
71
+ rooms.delete(event.room);
72
+ }
73
+ });
74
+ rooms.set(roomId, newRoom);
75
+ return newRoom;
76
+ };
62
77
  const wsHandler = (ws, req) => __async(void 0, null, function* () {
63
78
  var _a;
64
79
  const url = req.url;
@@ -77,7 +92,7 @@ var createPluvHandler = (config) => {
77
92
  if (!roomId) return onError.invalidRoom();
78
93
  const token = ((_a = parsed.query) == null ? void 0 : _a.token) || void 0;
79
94
  if (Array.isArray(token)) return onError.invalidToken();
80
- const room = io.getRoom(roomId);
95
+ const room = getRoom(roomId);
81
96
  yield room.register(ws, { token });
82
97
  return { matched: true };
83
98
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-node",
3
- "version": "0.23.0",
3
+ "version": "0.24.1",
4
4
  "description": "@pluv/io adapter for node.js",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,19 +17,19 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@types/node": "^22.4.0",
20
+ "@types/node": "^22.5.0",
21
21
  "@types/ws": "^8.5.12",
22
22
  "path-to-regexp": "^7.1.0",
23
- "@pluv/io": "^0.23.0",
24
- "@pluv/types": "^0.23.0"
23
+ "@pluv/io": "^0.24.1",
24
+ "@pluv/types": "^0.24.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "eslint": "^8.57.0",
28
28
  "tsup": "^8.2.4",
29
29
  "typescript": "^5.5.4",
30
30
  "ws": "^8.18.0",
31
- "@pluv/tsconfig": "^0.23.0",
32
- "eslint-config-pluv": "^0.23.0"
31
+ "@pluv/tsconfig": "^0.24.1",
32
+ "eslint-config-pluv": "^0.24.1"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "ws": "^8.0.0"
@@ -72,6 +72,27 @@ export const createPluvHandler = <TPluvServer extends PluvServer<NodePlatform, a
72
72
  }
73
73
 
74
74
  const wsServer = new WsServer({ server });
75
+ const rooms = new Map<string, ReturnType<typeof io.createRoom>>();
76
+
77
+ const getRoom = (roomId: string): ReturnType<typeof io.createRoom> => {
78
+ Array.from(rooms.values()).forEach((room) => {
79
+ if (!room.getSize()) rooms.delete(room.id);
80
+ });
81
+
82
+ const existing = rooms.get(roomId);
83
+
84
+ if (existing) return existing;
85
+
86
+ const newRoom = io.createRoom(roomId, {
87
+ onDestroy: (event) => {
88
+ rooms.delete(event.room);
89
+ },
90
+ });
91
+
92
+ rooms.set(roomId, newRoom);
93
+
94
+ return newRoom;
95
+ };
75
96
 
76
97
  const wsHandler = async (ws: WebSocket, req: IncomingMessage): Promise<WebSocketHandlerResult> => {
77
98
  const url = req.url;
@@ -101,7 +122,7 @@ export const createPluvHandler = <TPluvServer extends PluvServer<NodePlatform, a
101
122
 
102
123
  if (Array.isArray(token)) return onError.invalidToken();
103
124
 
104
- const room = io.getRoom(roomId);
125
+ const room = getRoom(roomId);
105
126
 
106
127
  await room.register(ws, { token });
107
128