@pluv/platform-node 0.3.2 → 0.3.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.
- package/.turbo/turbo-build.log +8 -7
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +64 -0
- package/package.json +9 -10
- package/src/NodePlatform.ts +1 -1
- package/src/NodeWebSocket.ts +5 -5
- package/src/createPluvHandler.ts +7 -7
- package/src/platformNode.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-node@0.3.
|
|
2
|
+
> @pluv/platform-node@0.3.3 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
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v7.
|
|
7
|
+
[34mCLI[39m tsup v7.1.0
|
|
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[32m6.16 KB[39m
|
|
12
|
-
[32mESM[39m ⚡️ Build success in 89ms
|
|
13
11
|
[32mCJS[39m [1mdist/index.js [22m[32m7.98 KB[39m
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 85ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m6.16 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 88ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9398ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m2.75 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.75 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @pluv/platform-node
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8fba48b: fix including incorrect dependency
|
|
8
|
+
- 8997c65: bumped dependencies
|
|
9
|
+
- Updated dependencies [8fba48b]
|
|
10
|
+
- Updated dependencies [8997c65]
|
|
11
|
+
- @pluv/types@0.2.2
|
|
12
|
+
- @pluv/io@0.7.1
|
|
13
|
+
|
|
3
14
|
## 0.3.2
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPersistance, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, PluvIO } from '@pluv/io';
|
|
2
|
+
import { MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
|
|
3
|
+
import Http, { IncomingMessage } from 'http';
|
|
4
|
+
import WS, { WebSocket } from 'ws';
|
|
5
|
+
export { WebSocket } from 'ws';
|
|
6
|
+
|
|
7
|
+
type NodeWebSocketConfig = AbstractWebSocketConfig;
|
|
8
|
+
declare class NodeWebSocket extends AbstractWebSocket {
|
|
9
|
+
webSocket: WebSocket;
|
|
10
|
+
get readyState(): 0 | 1 | 2 | 3;
|
|
11
|
+
constructor(webSocket: WebSocket, config: NodeWebSocketConfig);
|
|
12
|
+
addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void;
|
|
13
|
+
close(code?: number | undefined, reason?: string | undefined): void;
|
|
14
|
+
initialize(): Promise<() => void>;
|
|
15
|
+
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
16
|
+
terminate(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type NodePlatformOptions = {
|
|
20
|
+
persistance?: undefined;
|
|
21
|
+
pubSub?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
persistance: AbstractPersistance;
|
|
24
|
+
pubSub: AbstractPubSub;
|
|
25
|
+
};
|
|
26
|
+
declare class NodePlatform extends AbstractPlatform<WebSocket, {
|
|
27
|
+
req: IncomingMessage;
|
|
28
|
+
}> {
|
|
29
|
+
constructor(options?: NodePlatformOptions);
|
|
30
|
+
convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket;
|
|
31
|
+
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
32
|
+
randomUUID(): string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface AuthorizeFunctionContext {
|
|
36
|
+
req: Http.IncomingMessage;
|
|
37
|
+
res: Http.ServerResponse;
|
|
38
|
+
roomId: string;
|
|
39
|
+
}
|
|
40
|
+
type AuthorizeFunction<TPluv extends PluvIO<NodePlatform>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
|
|
41
|
+
type CreatePluvHandlerConfig<TPluv extends PluvIO<NodePlatform>> = {
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
io: TPluv;
|
|
44
|
+
server: Http.Server;
|
|
45
|
+
} & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true ? {
|
|
46
|
+
authorize: AuthorizeFunction<TPluv>;
|
|
47
|
+
} : {
|
|
48
|
+
authorize?: undefined;
|
|
49
|
+
});
|
|
50
|
+
type RequestHandler = (req: Http.IncomingMessage, res: Http.ServerResponse, next?: () => void) => void;
|
|
51
|
+
interface WebSocketHandlerResult {
|
|
52
|
+
matched: boolean;
|
|
53
|
+
}
|
|
54
|
+
type WebSocketHandler = (ws: WS.WebSocket, req: Http.IncomingMessage) => Promise<WebSocketHandlerResult>;
|
|
55
|
+
interface CreatePluvHandlerResult {
|
|
56
|
+
createWsServer: () => WS.Server;
|
|
57
|
+
handler: RequestHandler;
|
|
58
|
+
wsHandler: WebSocketHandler;
|
|
59
|
+
}
|
|
60
|
+
declare const createPluvHandler: <TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any>>(config: CreatePluvHandlerConfig<TPluv>) => CreatePluvHandlerResult;
|
|
61
|
+
|
|
62
|
+
declare const platformNode: (options?: NodePlatformOptions) => NodePlatform;
|
|
63
|
+
|
|
64
|
+
export { AuthorizeFunction, AuthorizeFunctionContext, CreatePluvHandlerConfig, NodePlatformOptions, createPluvHandler, platformNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "@pluv/io adapter for node.js",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,20 +17,19 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@types/
|
|
22
|
-
"@types/react": "^18.2.13",
|
|
20
|
+
"@types/node": "^20.4.2",
|
|
21
|
+
"@types/react": "^18.2.15",
|
|
23
22
|
"@types/ws": "^8.5.5",
|
|
24
23
|
"path-to-regexp": "^6.2.1",
|
|
25
|
-
"@pluv/io": "^0.7.
|
|
26
|
-
"@pluv/types": "^0.2.
|
|
24
|
+
"@pluv/io": "^0.7.1",
|
|
25
|
+
"@pluv/types": "^0.2.2"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"tsup": "^7.
|
|
30
|
-
"typescript": "^5.1.
|
|
28
|
+
"tsup": "^7.1.0",
|
|
29
|
+
"typescript": "^5.1.6",
|
|
31
30
|
"ws": "^8.13.0",
|
|
32
|
-
"@pluv/tsconfig": "^0.1.
|
|
33
|
-
"eslint-config-pluv": "^0.1.
|
|
31
|
+
"@pluv/tsconfig": "^0.1.8",
|
|
32
|
+
"eslint-config-pluv": "^0.1.14"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"ws": "^8.0.0"
|
package/src/NodePlatform.ts
CHANGED
package/src/NodeWebSocket.ts
CHANGED
|
@@ -34,7 +34,7 @@ export class NodeWebSocket extends AbstractWebSocket {
|
|
|
34
34
|
|
|
35
35
|
public addEventListener<TType extends keyof AbstractEventMap>(
|
|
36
36
|
type: TType,
|
|
37
|
-
handler: AbstractListener<TType
|
|
37
|
+
handler: AbstractListener<TType>,
|
|
38
38
|
): void {
|
|
39
39
|
switch (type) {
|
|
40
40
|
case "close":
|
|
@@ -43,7 +43,7 @@ export class NodeWebSocket extends AbstractWebSocket {
|
|
|
43
43
|
(handler as AbstractListener<"close">)({
|
|
44
44
|
code,
|
|
45
45
|
reason: reason.toString("utf-8"),
|
|
46
|
-
})
|
|
46
|
+
}),
|
|
47
47
|
);
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -54,7 +54,7 @@ export class NodeWebSocket extends AbstractWebSocket {
|
|
|
54
54
|
(handler as AbstractListener<"error">)({
|
|
55
55
|
error,
|
|
56
56
|
message: error.message,
|
|
57
|
-
})
|
|
57
|
+
}),
|
|
58
58
|
);
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -64,7 +64,7 @@ export class NodeWebSocket extends AbstractWebSocket {
|
|
|
64
64
|
await Promise.resolve(
|
|
65
65
|
(handler as AbstractListener<"message">)({
|
|
66
66
|
data,
|
|
67
|
-
})
|
|
67
|
+
}),
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -75,7 +75,7 @@ export class NodeWebSocket extends AbstractWebSocket {
|
|
|
75
75
|
|
|
76
76
|
public close(code?: number | undefined, reason?: string | undefined): void {
|
|
77
77
|
const canClose = [this.CONNECTING, this.OPEN].some(
|
|
78
|
-
(readyState) => readyState === this.readyState
|
|
78
|
+
(readyState) => readyState === this.readyState,
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
if (!canClose) return;
|
package/src/createPluvHandler.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface AuthorizeFunctionContext {
|
|
|
18
18
|
roomId: string;
|
|
19
19
|
}
|
|
20
20
|
export type AuthorizeFunction<TPluv extends PluvIO<NodePlatform>> = (
|
|
21
|
-
ctx: AuthorizeFunctionContext
|
|
21
|
+
ctx: AuthorizeFunctionContext,
|
|
22
22
|
) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
|
|
23
23
|
|
|
24
24
|
export type CreatePluvHandlerConfig<TPluv extends PluvIO<NodePlatform>> = {
|
|
@@ -50,7 +50,7 @@ const handle = (ws: WS.WebSocket) => ({
|
|
|
50
50
|
export type RequestHandler = (
|
|
51
51
|
req: Http.IncomingMessage,
|
|
52
52
|
res: Http.ServerResponse,
|
|
53
|
-
next?: () => void
|
|
53
|
+
next?: () => void,
|
|
54
54
|
) => void;
|
|
55
55
|
|
|
56
56
|
export interface WebSocketHandlerResult {
|
|
@@ -59,7 +59,7 @@ export interface WebSocketHandlerResult {
|
|
|
59
59
|
|
|
60
60
|
export type WebSocketHandler = (
|
|
61
61
|
ws: WS.WebSocket,
|
|
62
|
-
req: Http.IncomingMessage
|
|
62
|
+
req: Http.IncomingMessage,
|
|
63
63
|
) => Promise<WebSocketHandlerResult>;
|
|
64
64
|
|
|
65
65
|
export interface CreatePluvHandlerResult {
|
|
@@ -69,9 +69,9 @@ export interface CreatePluvHandlerResult {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export const createPluvHandler = <
|
|
72
|
-
TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any
|
|
72
|
+
TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any>,
|
|
73
73
|
>(
|
|
74
|
-
config: CreatePluvHandlerConfig<TPluv
|
|
74
|
+
config: CreatePluvHandlerConfig<TPluv>,
|
|
75
75
|
): CreatePluvHandlerResult => {
|
|
76
76
|
const { authorize, endpoint = "/api/pluv", io, server } = config;
|
|
77
77
|
|
|
@@ -79,7 +79,7 @@ export const createPluvHandler = <
|
|
|
79
79
|
|
|
80
80
|
const wsHandler = async (
|
|
81
81
|
ws: WS.WebSocket,
|
|
82
|
-
req: Http.IncomingMessage
|
|
82
|
+
req: Http.IncomingMessage,
|
|
83
83
|
): Promise<WebSocketHandlerResult> => {
|
|
84
84
|
const url = req.url;
|
|
85
85
|
const onError = handle(ws);
|
|
@@ -124,7 +124,7 @@ export const createPluvHandler = <
|
|
|
124
124
|
const handler = async (
|
|
125
125
|
req: Http.IncomingMessage,
|
|
126
126
|
res: Http.ServerResponse,
|
|
127
|
-
next?: () => void
|
|
127
|
+
next?: () => void,
|
|
128
128
|
): Promise<Http.ServerResponse | null> => {
|
|
129
129
|
if (!authorize) return next?.() ?? null;
|
|
130
130
|
if (req.method !== "GET") return next?.() ?? null;
|
package/src/platformNode.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { NodePlatformOptions } from "./NodePlatform";
|
|
|
2
2
|
import { NodePlatform } from "./NodePlatform";
|
|
3
3
|
|
|
4
4
|
export const platformNode = (
|
|
5
|
-
options: NodePlatformOptions = {}
|
|
5
|
+
options: NodePlatformOptions = {},
|
|
6
6
|
): NodePlatform => {
|
|
7
7
|
return new NodePlatform(options);
|
|
8
8
|
};
|