@pluv/platform-node 1.0.0 → 1.0.2
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 +6 -6
- package/CHANGELOG.md +15 -0
- package/dist/index.js +11 -3
- package/dist/index.mjs +11 -3
- package/package.json +5 -5
- package/src/NodePlatform.ts +12 -3
- package/src/NodeWebSocket.ts +10 -3
- package/src/createPluvHandler.ts +18 -4
- package/src/index.ts +5 -1
- package/src/infer.ts +2 -1
- package/src/platformNode.ts +7 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-node@1.0.
|
|
2
|
+
> @pluv/platform-node@1.0.2 build /home/runner/work/pluv/pluv/packages/platform-node
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m9.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m11.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m9.54 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 85ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.33 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 89ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5403ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m6.50 KB[39m
|
|
18
18
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m6.50 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/platform-node
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/io@1.0.2
|
|
8
|
+
- @pluv/types@1.0.2
|
|
9
|
+
|
|
10
|
+
## 1.0.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [c583be9]
|
|
15
|
+
- @pluv/io@1.0.1
|
|
16
|
+
- @pluv/types@1.0.1
|
|
17
|
+
|
|
3
18
|
## 1.0.0
|
|
4
19
|
|
|
5
20
|
### Major Changes
|
package/dist/index.js
CHANGED
|
@@ -248,7 +248,9 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
248
248
|
case "error":
|
|
249
249
|
this.webSocket.on("error", (error) => __async(this, null, function* () {
|
|
250
250
|
const message = error.message;
|
|
251
|
-
yield Promise.resolve(
|
|
251
|
+
yield Promise.resolve(
|
|
252
|
+
handler({ error, message })
|
|
253
|
+
);
|
|
252
254
|
}));
|
|
253
255
|
return;
|
|
254
256
|
case "message":
|
|
@@ -260,7 +262,9 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
|
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
close(code, reason) {
|
|
263
|
-
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
265
|
+
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
266
|
+
(readyState) => readyState === this.readyState
|
|
267
|
+
);
|
|
264
268
|
if (!canClose) return;
|
|
265
269
|
this.webSocket.close(code, reason);
|
|
266
270
|
}
|
|
@@ -305,7 +309,11 @@ var NodePlatform = class _NodePlatform extends import_io2.AbstractPlatform {
|
|
|
305
309
|
}
|
|
306
310
|
convertWebSocket(webSocket, config) {
|
|
307
311
|
const { room } = config;
|
|
308
|
-
return new NodeWebSocket(webSocket, {
|
|
312
|
+
return new NodeWebSocket(webSocket, {
|
|
313
|
+
persistence: this.persistence,
|
|
314
|
+
platform: this,
|
|
315
|
+
room
|
|
316
|
+
});
|
|
309
317
|
}
|
|
310
318
|
getLastPing(webSocket) {
|
|
311
319
|
return null;
|
package/dist/index.mjs
CHANGED
|
@@ -213,7 +213,9 @@ var NodeWebSocket = class extends AbstractWebSocket {
|
|
|
213
213
|
case "error":
|
|
214
214
|
this.webSocket.on("error", (error) => __async(this, null, function* () {
|
|
215
215
|
const message = error.message;
|
|
216
|
-
yield Promise.resolve(
|
|
216
|
+
yield Promise.resolve(
|
|
217
|
+
handler({ error, message })
|
|
218
|
+
);
|
|
217
219
|
}));
|
|
218
220
|
return;
|
|
219
221
|
case "message":
|
|
@@ -225,7 +227,9 @@ var NodeWebSocket = class extends AbstractWebSocket {
|
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
229
|
close(code, reason) {
|
|
228
|
-
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
230
|
+
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
231
|
+
(readyState) => readyState === this.readyState
|
|
232
|
+
);
|
|
229
233
|
if (!canClose) return;
|
|
230
234
|
this.webSocket.close(code, reason);
|
|
231
235
|
}
|
|
@@ -270,7 +274,11 @@ var NodePlatform = class _NodePlatform extends AbstractPlatform {
|
|
|
270
274
|
}
|
|
271
275
|
convertWebSocket(webSocket, config) {
|
|
272
276
|
const { room } = config;
|
|
273
|
-
return new NodeWebSocket(webSocket, {
|
|
277
|
+
return new NodeWebSocket(webSocket, {
|
|
278
|
+
persistence: this.persistence,
|
|
279
|
+
platform: this,
|
|
280
|
+
room
|
|
281
|
+
});
|
|
274
282
|
}
|
|
275
283
|
getLastPing(webSocket) {
|
|
276
284
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "@pluv/io adapter for node.js",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"@types/node": "^22.15.3",
|
|
21
21
|
"@types/ws": "^8.18.1",
|
|
22
22
|
"path-to-regexp": "^8.2.0",
|
|
23
|
-
"@pluv/io": "^1.0.
|
|
24
|
-
"@pluv/types": "^1.0.
|
|
23
|
+
"@pluv/io": "^1.0.2",
|
|
24
|
+
"@pluv/types": "^1.0.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"eslint": "^9.25.1",
|
|
28
28
|
"tsup": "^8.4.0",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
30
30
|
"ws": "^8.18.1",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"eslint-config-pluv": "^1.0.2",
|
|
32
|
+
"@pluv/tsconfig": "^1.0.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ws": "^8.0.0"
|
package/src/NodePlatform.ts
CHANGED
|
@@ -18,7 +18,9 @@ export type NodePlatformRoomContext<TMeta extends Record<string, Json>> = keyof
|
|
|
18
18
|
? { meta?: undefined }
|
|
19
19
|
: { meta: TMeta };
|
|
20
20
|
|
|
21
|
-
export type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
21
|
+
export type NodePlatformConfig<TMeta extends Record<string, Json>> = {
|
|
22
|
+
mode?: WebSocketRegistrationMode;
|
|
23
|
+
} & (
|
|
22
24
|
| { persistence?: undefined; pubSub?: undefined }
|
|
23
25
|
| { persistence: AbstractPersistence; pubSub: AbstractPubSub }
|
|
24
26
|
) & { roomContext?: NodePlatformRoomContext<TMeta> };
|
|
@@ -80,10 +82,17 @@ export class NodePlatform<
|
|
|
80
82
|
return Promise.resolve(undefined);
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
public convertWebSocket(
|
|
85
|
+
public convertWebSocket(
|
|
86
|
+
webSocket: WebSocket,
|
|
87
|
+
config: ConvertWebSocketConfig,
|
|
88
|
+
): NodeWebSocket<TAuthorize> {
|
|
84
89
|
const { room } = config;
|
|
85
90
|
|
|
86
|
-
return new NodeWebSocket<TAuthorize>(webSocket, {
|
|
91
|
+
return new NodeWebSocket<TAuthorize>(webSocket, {
|
|
92
|
+
persistence: this.persistence,
|
|
93
|
+
platform: this,
|
|
94
|
+
room,
|
|
95
|
+
});
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
public getLastPing(webSocket: NodeWebSocket<TAuthorize>): number | null {
|
package/src/NodeWebSocket.ts
CHANGED
|
@@ -87,7 +87,10 @@ export class NodeWebSocket<
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
public addEventListener<TType extends keyof AbstractEventMap>(
|
|
90
|
+
public addEventListener<TType extends keyof AbstractEventMap>(
|
|
91
|
+
type: TType,
|
|
92
|
+
handler: AbstractListener<TType>,
|
|
93
|
+
): void {
|
|
91
94
|
switch (type) {
|
|
92
95
|
case "close":
|
|
93
96
|
this.webSocket.on("close", async (code, buffer) => {
|
|
@@ -101,7 +104,9 @@ export class NodeWebSocket<
|
|
|
101
104
|
this.webSocket.on("error", async (error) => {
|
|
102
105
|
const message = error.message;
|
|
103
106
|
|
|
104
|
-
await Promise.resolve(
|
|
107
|
+
await Promise.resolve(
|
|
108
|
+
(handler as AbstractListener<"error">)({ error, message }),
|
|
109
|
+
);
|
|
105
110
|
});
|
|
106
111
|
|
|
107
112
|
return;
|
|
@@ -116,7 +121,9 @@ export class NodeWebSocket<
|
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
public close(code?: number | undefined, reason?: string | undefined): void {
|
|
119
|
-
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
124
|
+
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
125
|
+
(readyState) => readyState === this.readyState,
|
|
126
|
+
);
|
|
120
127
|
|
|
121
128
|
if (!canClose) return;
|
|
122
129
|
|
package/src/createPluvHandler.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { InferInitContextType, PluvServer } from "@pluv/io";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
BaseUser,
|
|
4
|
+
InferIOAuthorize,
|
|
5
|
+
InferIOAuthorizeUser,
|
|
6
|
+
Maybe,
|
|
7
|
+
MaybePromise,
|
|
8
|
+
} from "@pluv/types";
|
|
3
9
|
import type { Server as HttpServer, IncomingMessage, ServerResponse } from "node:http";
|
|
4
10
|
import Url from "node:url";
|
|
5
11
|
import { match } from "path-to-regexp";
|
|
@@ -9,7 +15,9 @@ import { NodePlatform } from "./NodePlatform";
|
|
|
9
15
|
|
|
10
16
|
export type AuthorizeFunctionContext<TPluvServer extends PluvServer<any, any, any, any>> = {
|
|
11
17
|
room: string;
|
|
12
|
-
} & InferInitContextType<
|
|
18
|
+
} & InferInitContextType<
|
|
19
|
+
TPluvServer extends PluvServer<infer IPlatform, any, any, any> ? IPlatform : never
|
|
20
|
+
>;
|
|
13
21
|
|
|
14
22
|
export type AuthorizeFunction<TPluvServer extends PluvServer<any, any, any, any>> = (
|
|
15
23
|
ctx: AuthorizeFunctionContext<TPluvServer>,
|
|
@@ -47,7 +55,10 @@ export interface WebSocketHandlerResult {
|
|
|
47
55
|
matched: boolean;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
export type WebSocketHandler = (
|
|
58
|
+
export type WebSocketHandler = (
|
|
59
|
+
ws: WebSocket,
|
|
60
|
+
req: IncomingMessage,
|
|
61
|
+
) => Promise<WebSocketHandlerResult>;
|
|
51
62
|
|
|
52
63
|
export interface CreatePluvHandlerResult {
|
|
53
64
|
createWsServer: () => WebSocketServer;
|
|
@@ -91,7 +102,10 @@ export const createPluvHandler = <TPluvServer extends PluvServer<NodePlatform<an
|
|
|
91
102
|
return newRoom;
|
|
92
103
|
};
|
|
93
104
|
|
|
94
|
-
const wsHandler = async (
|
|
105
|
+
const wsHandler = async (
|
|
106
|
+
ws: WebSocket,
|
|
107
|
+
req: IncomingMessage,
|
|
108
|
+
): Promise<WebSocketHandlerResult> => {
|
|
95
109
|
const url = req.url;
|
|
96
110
|
const onError = handle(ws);
|
|
97
111
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export type { WebSocket } from "ws";
|
|
2
2
|
export { createPluvHandler } from "./createPluvHandler";
|
|
3
|
-
export type {
|
|
3
|
+
export type {
|
|
4
|
+
AuthorizeFunction,
|
|
5
|
+
AuthorizeFunctionContext,
|
|
6
|
+
CreatePluvHandlerConfig,
|
|
7
|
+
} from "./createPluvHandler";
|
|
4
8
|
export { infer } from "./infer";
|
|
5
9
|
export type { InferCallback } from "./infer";
|
|
6
10
|
export type { NodePlatform, NodePlatformConfig } from "./NodePlatform";
|
package/src/infer.ts
CHANGED
|
@@ -5,4 +5,5 @@ export type InferCallback<TMeta extends Record<string, Json> = {}> = (i: typeof
|
|
|
5
5
|
meta?: (io: TMeta) => TMeta;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const infer = <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) =>
|
|
8
|
+
export const infer = <TMeta extends Record<string, Json> = {}>(callback: InferCallback<TMeta>) =>
|
|
9
|
+
callback;
|
package/src/platformNode.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CreateIOParams,
|
|
3
|
+
InferInitContextType,
|
|
4
|
+
PluvContext,
|
|
5
|
+
PluvIOAuthorize,
|
|
6
|
+
PluvIOLimits,
|
|
7
|
+
} from "@pluv/io";
|
|
2
8
|
import type { BaseUser, Id, IOAuthorize, Json } from "@pluv/types";
|
|
3
9
|
import type { NodePlatformConfig } from "./NodePlatform";
|
|
4
10
|
import { NodePlatform } from "./NodePlatform";
|