@pluv/platform-node 0.18.0 → 0.19.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/.turbo/turbo-build.log +15 -15
- package/CHANGELOG.md +7 -0
- package/dist/index.js +14 -28
- package/dist/index.mjs +14 -28
- package/package.json +8 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-node@0.
|
|
2
|
+
> @pluv/platform-node@0.19.0 build /home/runner/work/pluv/pluv/packages/platform-node
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
CLI Building entry: src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v8.1.0
|
|
8
|
+
CLI Target: es6
|
|
9
|
+
ESM Build start
|
|
10
|
+
CJS Build start
|
|
11
|
+
ESM dist/index.mjs 6.12 KB
|
|
12
|
+
ESM ⚡️ Build success in 82ms
|
|
13
|
+
CJS dist/index.js 7.93 KB
|
|
14
|
+
CJS ⚡️ Build success in 86ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 4070ms
|
|
17
|
+
DTS dist/index.d.mts 2.92 KB
|
|
18
|
+
DTS dist/index.d.ts 2.92 KB
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -86,18 +86,14 @@ var createPluvHandler = (config) => {
|
|
|
86
86
|
}
|
|
87
87
|
const parsed = import_node_url.default.parse(url, true);
|
|
88
88
|
const { pathname } = parsed;
|
|
89
|
-
if (!pathname)
|
|
90
|
-
return onError.invalidEndpoint();
|
|
89
|
+
if (!pathname) return onError.invalidEndpoint();
|
|
91
90
|
const matcher = (0, import_path_to_regexp.match)(`${endpoint}/room/:roomId`);
|
|
92
91
|
const matched = matcher(pathname);
|
|
93
|
-
if (!matched)
|
|
94
|
-
return onError.invalidEndpoint();
|
|
92
|
+
if (!matched) return onError.invalidEndpoint();
|
|
95
93
|
const { roomId } = matched.params;
|
|
96
|
-
if (!roomId)
|
|
97
|
-
return onError.invalidRoom();
|
|
94
|
+
if (!roomId) return onError.invalidRoom();
|
|
98
95
|
const token = ((_a = parsed.query) == null ? void 0 : _a.token) || void 0;
|
|
99
|
-
if (Array.isArray(token))
|
|
100
|
-
return onError.invalidToken();
|
|
96
|
+
if (Array.isArray(token)) return onError.invalidToken();
|
|
101
97
|
const room = io.getRoom(roomId, { req });
|
|
102
98
|
yield room.register(ws, { req, token });
|
|
103
99
|
return { matched: true };
|
|
@@ -109,21 +105,16 @@ var createPluvHandler = (config) => {
|
|
|
109
105
|
};
|
|
110
106
|
const handler = (req, res, next) => __async(void 0, null, function* () {
|
|
111
107
|
var _a, _b, _c, _d, _e, _f;
|
|
112
|
-
if (!authorize)
|
|
113
|
-
|
|
114
|
-
if (req.method !== "GET")
|
|
115
|
-
return (_b = next == null ? void 0 : next()) != null ? _b : null;
|
|
108
|
+
if (!authorize) return (_a = next == null ? void 0 : next()) != null ? _a : null;
|
|
109
|
+
if (req.method !== "GET") return (_b = next == null ? void 0 : next()) != null ? _b : null;
|
|
116
110
|
const url = req.url;
|
|
117
|
-
if (!url)
|
|
118
|
-
return (_c = next == null ? void 0 : next()) != null ? _c : null;
|
|
111
|
+
if (!url) return (_c = next == null ? void 0 : next()) != null ? _c : null;
|
|
119
112
|
const parsed = import_node_url.default.parse(url, true);
|
|
120
113
|
const { pathname } = parsed;
|
|
121
|
-
if (!pathname)
|
|
122
|
-
return (_d = next == null ? void 0 : next()) != null ? _d : null;
|
|
114
|
+
if (!pathname) return (_d = next == null ? void 0 : next()) != null ? _d : null;
|
|
123
115
|
const matcher = (0, import_path_to_regexp.match)(`${endpoint}/authorize`);
|
|
124
116
|
const matched = matcher(pathname);
|
|
125
|
-
if (!matched)
|
|
126
|
-
return (_e = next == null ? void 0 : next()) != null ? _e : null;
|
|
117
|
+
if (!matched) return (_e = next == null ? void 0 : next()) != null ? _e : null;
|
|
127
118
|
const roomId = ((_f = parsed.query) == null ? void 0 : _f.room) || void 0;
|
|
128
119
|
if (typeof roomId !== "string" || !roomId) {
|
|
129
120
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
@@ -131,8 +122,7 @@ var createPluvHandler = (config) => {
|
|
|
131
122
|
}
|
|
132
123
|
try {
|
|
133
124
|
const user = yield authorize({ res, req, roomId });
|
|
134
|
-
if (!user)
|
|
135
|
-
throw new Error();
|
|
125
|
+
if (!user) throw new Error();
|
|
136
126
|
const token = yield io.createToken({
|
|
137
127
|
req,
|
|
138
128
|
room: roomId,
|
|
@@ -204,8 +194,7 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
204
194
|
}
|
|
205
195
|
close(code, reason) {
|
|
206
196
|
const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
|
|
207
|
-
if (!canClose)
|
|
208
|
-
return;
|
|
197
|
+
if (!canClose) return;
|
|
209
198
|
this.webSocket.close(code, reason);
|
|
210
199
|
}
|
|
211
200
|
initialize() {
|
|
@@ -214,11 +203,9 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
214
203
|
});
|
|
215
204
|
}
|
|
216
205
|
send(message) {
|
|
217
|
-
if (this.readyState !== this.OPEN)
|
|
218
|
-
return;
|
|
206
|
+
if (this.readyState !== this.OPEN) return;
|
|
219
207
|
this.webSocket.send(message, (error) => {
|
|
220
|
-
if (error)
|
|
221
|
-
throw error;
|
|
208
|
+
if (error) throw error;
|
|
222
209
|
});
|
|
223
210
|
}
|
|
224
211
|
terminate() {
|
|
@@ -236,8 +223,7 @@ var NodePlatform = class extends import_io2.AbstractPlatform {
|
|
|
236
223
|
return new NodeWebSocket(webSocket, config);
|
|
237
224
|
}
|
|
238
225
|
parseData(data) {
|
|
239
|
-
if (typeof data === "string")
|
|
240
|
-
return JSON.parse(data);
|
|
226
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
241
227
|
const decoder = new import_util.TextDecoder("utf8");
|
|
242
228
|
return JSON.parse(decoder.decode(data));
|
|
243
229
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -50,18 +50,14 @@ var createPluvHandler = (config) => {
|
|
|
50
50
|
}
|
|
51
51
|
const parsed = Url.parse(url, true);
|
|
52
52
|
const { pathname } = parsed;
|
|
53
|
-
if (!pathname)
|
|
54
|
-
return onError.invalidEndpoint();
|
|
53
|
+
if (!pathname) return onError.invalidEndpoint();
|
|
55
54
|
const matcher = match(`${endpoint}/room/:roomId`);
|
|
56
55
|
const matched = matcher(pathname);
|
|
57
|
-
if (!matched)
|
|
58
|
-
return onError.invalidEndpoint();
|
|
56
|
+
if (!matched) return onError.invalidEndpoint();
|
|
59
57
|
const { roomId } = matched.params;
|
|
60
|
-
if (!roomId)
|
|
61
|
-
return onError.invalidRoom();
|
|
58
|
+
if (!roomId) return onError.invalidRoom();
|
|
62
59
|
const token = ((_a = parsed.query) == null ? void 0 : _a.token) || void 0;
|
|
63
|
-
if (Array.isArray(token))
|
|
64
|
-
return onError.invalidToken();
|
|
60
|
+
if (Array.isArray(token)) return onError.invalidToken();
|
|
65
61
|
const room = io.getRoom(roomId, { req });
|
|
66
62
|
yield room.register(ws, { req, token });
|
|
67
63
|
return { matched: true };
|
|
@@ -73,21 +69,16 @@ var createPluvHandler = (config) => {
|
|
|
73
69
|
};
|
|
74
70
|
const handler = (req, res, next) => __async(void 0, null, function* () {
|
|
75
71
|
var _a, _b, _c, _d, _e, _f;
|
|
76
|
-
if (!authorize)
|
|
77
|
-
|
|
78
|
-
if (req.method !== "GET")
|
|
79
|
-
return (_b = next == null ? void 0 : next()) != null ? _b : null;
|
|
72
|
+
if (!authorize) return (_a = next == null ? void 0 : next()) != null ? _a : null;
|
|
73
|
+
if (req.method !== "GET") return (_b = next == null ? void 0 : next()) != null ? _b : null;
|
|
80
74
|
const url = req.url;
|
|
81
|
-
if (!url)
|
|
82
|
-
return (_c = next == null ? void 0 : next()) != null ? _c : null;
|
|
75
|
+
if (!url) return (_c = next == null ? void 0 : next()) != null ? _c : null;
|
|
83
76
|
const parsed = Url.parse(url, true);
|
|
84
77
|
const { pathname } = parsed;
|
|
85
|
-
if (!pathname)
|
|
86
|
-
return (_d = next == null ? void 0 : next()) != null ? _d : null;
|
|
78
|
+
if (!pathname) return (_d = next == null ? void 0 : next()) != null ? _d : null;
|
|
87
79
|
const matcher = match(`${endpoint}/authorize`);
|
|
88
80
|
const matched = matcher(pathname);
|
|
89
|
-
if (!matched)
|
|
90
|
-
return (_e = next == null ? void 0 : next()) != null ? _e : null;
|
|
81
|
+
if (!matched) return (_e = next == null ? void 0 : next()) != null ? _e : null;
|
|
91
82
|
const roomId = ((_f = parsed.query) == null ? void 0 : _f.room) || void 0;
|
|
92
83
|
if (typeof roomId !== "string" || !roomId) {
|
|
93
84
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
@@ -95,8 +86,7 @@ var createPluvHandler = (config) => {
|
|
|
95
86
|
}
|
|
96
87
|
try {
|
|
97
88
|
const user = yield authorize({ res, req, roomId });
|
|
98
|
-
if (!user)
|
|
99
|
-
throw new Error();
|
|
89
|
+
if (!user) throw new Error();
|
|
100
90
|
const token = yield io.createToken({
|
|
101
91
|
req,
|
|
102
92
|
room: roomId,
|
|
@@ -168,8 +158,7 @@ var NodeWebSocket = class extends AbstractWebSocket {
|
|
|
168
158
|
}
|
|
169
159
|
close(code, reason) {
|
|
170
160
|
const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
|
|
171
|
-
if (!canClose)
|
|
172
|
-
return;
|
|
161
|
+
if (!canClose) return;
|
|
173
162
|
this.webSocket.close(code, reason);
|
|
174
163
|
}
|
|
175
164
|
initialize() {
|
|
@@ -178,11 +167,9 @@ var NodeWebSocket = class extends AbstractWebSocket {
|
|
|
178
167
|
});
|
|
179
168
|
}
|
|
180
169
|
send(message) {
|
|
181
|
-
if (this.readyState !== this.OPEN)
|
|
182
|
-
return;
|
|
170
|
+
if (this.readyState !== this.OPEN) return;
|
|
183
171
|
this.webSocket.send(message, (error) => {
|
|
184
|
-
if (error)
|
|
185
|
-
throw error;
|
|
172
|
+
if (error) throw error;
|
|
186
173
|
});
|
|
187
174
|
}
|
|
188
175
|
terminate() {
|
|
@@ -200,8 +187,7 @@ var NodePlatform = class extends AbstractPlatform {
|
|
|
200
187
|
return new NodeWebSocket(webSocket, config);
|
|
201
188
|
}
|
|
202
189
|
parseData(data) {
|
|
203
|
-
if (typeof data === "string")
|
|
204
|
-
return JSON.parse(data);
|
|
190
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
205
191
|
const decoder = new TextDecoder("utf8");
|
|
206
192
|
return JSON.parse(decoder.decode(data));
|
|
207
193
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
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": "^20.
|
|
20
|
+
"@types/node": "^20.14.9",
|
|
21
21
|
"@types/ws": "^8.5.10",
|
|
22
|
-
"path-to-regexp": "^
|
|
23
|
-
"@pluv/io": "^0.
|
|
24
|
-
"@pluv/types": "^0.
|
|
22
|
+
"path-to-regexp": "^7.0.0",
|
|
23
|
+
"@pluv/io": "^0.19.0",
|
|
24
|
+
"@pluv/types": "^0.19.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"eslint": "^8.57.0",
|
|
28
|
-
"tsup": "^8.0
|
|
28
|
+
"tsup": "^8.1.0",
|
|
29
29
|
"typescript": "^5.4.5",
|
|
30
30
|
"ws": "^8.17.0",
|
|
31
|
-
"@pluv/tsconfig": "^0.
|
|
32
|
-
"eslint-config-pluv": "^0.
|
|
31
|
+
"@pluv/tsconfig": "^0.19.0",
|
|
32
|
+
"eslint-config-pluv": "^0.19.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ws": "^8.0.0"
|