@pluv/platform-node 0.17.3 → 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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/platform-node@0.17.3 build /home/runner/work/pluv/pluv/packages/platform-node
2
+ > @pluv/platform-node@0.18.0 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
- CJS dist/index.js 8.03 KB
12
- CJS ⚡️ Build success in 102ms
13
- ESM dist/index.mjs 6.20 KB
14
- ESM ⚡️ Build success in 102ms
11
+ ESM dist/index.mjs 6.21 KB
12
+ ESM ⚡️ Build success in 90ms
13
+ CJS dist/index.js 8.01 KB
14
+ CJS ⚡️ Build success in 92ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3957ms
17
- DTS dist/index.d.mts 2.77 KB
18
- DTS dist/index.d.ts 2.77 KB
16
+ DTS ⚡️ Build success in 3353ms
17
+ DTS dist/index.d.mts 2.92 KB
18
+ DTS dist/index.d.ts 2.92 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,109 @@
1
1
  # @pluv/platform-node
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 99b5ca9: ## Breaking Changes
8
+
9
+ - `@pluv/io` has been updated to introduce `PluvProcedure`, `PluvRouter` and `PluvServer`. This change is intended to improve the ergonomics of declaring events and simplifying inferences of event types.
10
+
11
+ ### Before:
12
+
13
+ ```ts
14
+ // backend/io.ts
15
+
16
+ import { createIO } from "@pluv/io";
17
+ import { createPluvHandler, platformNode } from "@pluv/platform-node";
18
+ import { z } from "zod";
19
+
20
+ export const io = createIO({
21
+ platform: platformNode(),
22
+ })
23
+ .event("SEND_MESSAGE", {
24
+ input: z.object({ message: z.string() }),
25
+ resolver: ({ message }) => ({ RECEIVE_MESSAGE: { message } }),
26
+ })
27
+ .event("DOUBLE_VALUE", {
28
+ input: z.object({ value: z.number() }),
29
+ resolver: ({ value }) => ({ VALUE_DOUBLED: { value: value * 2 } }),
30
+ });
31
+
32
+ const Pluv = createPluvHandler({
33
+ io,
34
+ /* ... */
35
+ });
36
+ ```
37
+
38
+ ```ts
39
+ // frontend/pluv.ts
40
+
41
+ import { createClient } from "@pluv/react";
42
+ import type { io } from "../backend/io";
43
+
44
+ const client = createClient<typeof io>({
45
+ /* ... */
46
+ });
47
+ ```
48
+
49
+ ### Now:
50
+
51
+ ```ts
52
+ import { createIO } from "@pluv/io";
53
+ import { createPluvHandler, platformNode } from "@pluv/platform-node";
54
+ import { z } from "zod";
55
+
56
+ const io = createIO({
57
+ platform: platformNode(),
58
+ });
59
+
60
+ const router = io.router({
61
+ SEND_MESSAGE: io.procedure
62
+ .input(z.object({ message: z.string() }))
63
+ .broadcast(({ message }) => ({
64
+ RECEIVE_MESSAGE: { message },
65
+ })),
66
+ DOUBLE_VALUE: io.procedure
67
+ .input(z.object({ value: z.number() }))
68
+ .broadcast(({ value }) => ({
69
+ VALUE_DOUBLED: { value: value * 2 },
70
+ })),
71
+ });
72
+
73
+ export const ioServer = io.server({ router });
74
+
75
+ const Pluv = createPluvHandler({
76
+ io: ioServer, // <- This uses the PluvServer now
77
+ /* ... */
78
+ });
79
+ ```
80
+
81
+ ```ts
82
+ // frontend/pluv.ts
83
+
84
+ import { createClient } from "@pluv/react";
85
+ import type { ioServer } from "../backend/io";
86
+
87
+ // This users the PluvServer type now
88
+ const client = createClient<typeof ioServer>({
89
+ /* ... */
90
+ });
91
+ ```
92
+
93
+ - `PluvRouter` instances can also be merged via the `mergeRouters` method, which effectively performs an `Object.assign` of the events object and returns a new `PluvRouter` with the correct types:
94
+
95
+ ```ts
96
+ const router = io.mergeRouters(router1, router2);
97
+ ```
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [428c21c]
102
+ - Updated dependencies [329dbcd]
103
+ - Updated dependencies [99b5ca9]
104
+ - @pluv/io@0.18.0
105
+ - @pluv/types@0.18.0
106
+
3
107
  ## 0.17.3
4
108
 
5
109
  ### Patch Changes
package/README.md CHANGED
@@ -52,9 +52,8 @@ import { platformNode } from "@pluv/platform-node";
52
52
  import Http from "http";
53
53
  import WebSocket from "ws";
54
54
 
55
- export const io = createIO({
56
- platform: platformNode(),
57
- });
55
+ export const io = createIO({ platform: platformNode() });
56
+ export const ioServer = io.server();
58
57
 
59
58
  const server = Http.createServer();
60
59
  const wsServer = new WebSocket.Server({ server });
@@ -65,7 +64,7 @@ const parseRoomId = (url: string): string => {
65
64
 
66
65
  wsServer.on("connection", async (ws, req) => {
67
66
  const roomId = parseRoomId(req.url);
68
- const room = io.getRoom(roomId);
67
+ const room = ioServer.getRoom(roomId);
69
68
 
70
69
  await room.register(ws);
71
70
  });
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPersistance, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, PluvIO } from '@pluv/io';
1
+ import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPersistance, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, PluvServer } from '@pluv/io';
2
2
  import { MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
3
- import Http, { IncomingMessage } from 'http';
4
- import WS, { WebSocket } from 'ws';
3
+ import { IncomingMessage as IncomingMessage$1, ServerResponse, Server } from 'node:http';
4
+ import { WebSocket, Server as Server$1 } from 'ws';
5
5
  export { WebSocket } from 'ws';
6
+ import { IncomingMessage } from 'http';
6
7
 
7
8
  type NodeWebSocketConfig = AbstractWebSocketConfig;
8
9
  declare class NodeWebSocket extends AbstractWebSocket {
@@ -33,31 +34,31 @@ declare class NodePlatform extends AbstractPlatform<WebSocket, {
33
34
  }
34
35
 
35
36
  interface AuthorizeFunctionContext {
36
- req: Http.IncomingMessage;
37
- res: Http.ServerResponse;
37
+ req: IncomingMessage$1;
38
+ res: ServerResponse;
38
39
  roomId: string;
39
40
  }
40
- type AuthorizeFunction<TPluv extends PluvIO<NodePlatform>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
41
- type CreatePluvHandlerConfig<TPluv extends PluvIO<NodePlatform>> = {
41
+ type AuthorizeFunction<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluvServer>>>>;
42
+ type CreatePluvHandlerConfig<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = {
42
43
  endpoint?: string;
43
- io: TPluv;
44
- server: Http.Server;
45
- } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true ? {
46
- authorize: AuthorizeFunction<TPluv>;
44
+ io: TPluvServer;
45
+ server: Server;
46
+ } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluvServer>> extends true ? {
47
+ authorize: AuthorizeFunction<TPluvServer>;
47
48
  } : {
48
49
  authorize?: undefined;
49
50
  });
50
- type RequestHandler = (req: Http.IncomingMessage, res: Http.ServerResponse, next?: () => void) => void;
51
+ type RequestHandler = (req: IncomingMessage$1, res: ServerResponse, next?: () => void) => void;
51
52
  interface WebSocketHandlerResult {
52
53
  matched: boolean;
53
54
  }
54
- type WebSocketHandler = (ws: WS.WebSocket, req: Http.IncomingMessage) => Promise<WebSocketHandlerResult>;
55
+ type WebSocketHandler = (ws: WebSocket, req: IncomingMessage$1) => Promise<WebSocketHandlerResult>;
55
56
  interface CreatePluvHandlerResult {
56
- createWsServer: () => WS.Server;
57
+ createWsServer: () => Server$1;
57
58
  handler: RequestHandler;
58
59
  wsHandler: WebSocketHandler;
59
60
  }
60
- declare const createPluvHandler: <TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any>>(config: CreatePluvHandlerConfig<TPluv>) => CreatePluvHandlerResult;
61
+ declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
61
62
 
62
63
  declare const platformNode: (options?: NodePlatformOptions) => NodePlatform;
63
64
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPersistance, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, PluvIO } from '@pluv/io';
1
+ import { AbstractWebSocket, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPersistance, AbstractPubSub, AbstractPlatform, ConvertWebSocketConfig, PluvServer } from '@pluv/io';
2
2
  import { MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired } from '@pluv/types';
3
- import Http, { IncomingMessage } from 'http';
4
- import WS, { WebSocket } from 'ws';
3
+ import { IncomingMessage as IncomingMessage$1, ServerResponse, Server } from 'node:http';
4
+ import { WebSocket, Server as Server$1 } from 'ws';
5
5
  export { WebSocket } from 'ws';
6
+ import { IncomingMessage } from 'http';
6
7
 
7
8
  type NodeWebSocketConfig = AbstractWebSocketConfig;
8
9
  declare class NodeWebSocket extends AbstractWebSocket {
@@ -33,31 +34,31 @@ declare class NodePlatform extends AbstractPlatform<WebSocket, {
33
34
  }
34
35
 
35
36
  interface AuthorizeFunctionContext {
36
- req: Http.IncomingMessage;
37
- res: Http.ServerResponse;
37
+ req: IncomingMessage$1;
38
+ res: ServerResponse;
38
39
  roomId: string;
39
40
  }
40
- type AuthorizeFunction<TPluv extends PluvIO<NodePlatform>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
41
- type CreatePluvHandlerConfig<TPluv extends PluvIO<NodePlatform>> = {
41
+ type AuthorizeFunction<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = (ctx: AuthorizeFunctionContext) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluvServer>>>>;
42
+ type CreatePluvHandlerConfig<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = {
42
43
  endpoint?: string;
43
- io: TPluv;
44
- server: Http.Server;
45
- } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true ? {
46
- authorize: AuthorizeFunction<TPluv>;
44
+ io: TPluvServer;
45
+ server: Server;
46
+ } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluvServer>> extends true ? {
47
+ authorize: AuthorizeFunction<TPluvServer>;
47
48
  } : {
48
49
  authorize?: undefined;
49
50
  });
50
- type RequestHandler = (req: Http.IncomingMessage, res: Http.ServerResponse, next?: () => void) => void;
51
+ type RequestHandler = (req: IncomingMessage$1, res: ServerResponse, next?: () => void) => void;
51
52
  interface WebSocketHandlerResult {
52
53
  matched: boolean;
53
54
  }
54
- type WebSocketHandler = (ws: WS.WebSocket, req: Http.IncomingMessage) => Promise<WebSocketHandlerResult>;
55
+ type WebSocketHandler = (ws: WebSocket, req: IncomingMessage$1) => Promise<WebSocketHandlerResult>;
55
56
  interface CreatePluvHandlerResult {
56
- createWsServer: () => WS.Server;
57
+ createWsServer: () => Server$1;
57
58
  handler: RequestHandler;
58
59
  wsHandler: WebSocketHandler;
59
60
  }
60
- declare const createPluvHandler: <TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any>>(config: CreatePluvHandlerConfig<TPluv>) => CreatePluvHandlerResult;
61
+ declare const createPluvHandler: <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer>) => CreatePluvHandlerResult;
61
62
 
62
63
  declare const platformNode: (options?: NodePlatformOptions) => NodePlatform;
63
64
 
package/dist/index.js CHANGED
@@ -56,9 +56,9 @@ __export(src_exports, {
56
56
  module.exports = __toCommonJS(src_exports);
57
57
 
58
58
  // src/createPluvHandler.ts
59
+ var import_node_url = __toESM(require("url"));
59
60
  var import_path_to_regexp = require("path-to-regexp");
60
- var import_url = __toESM(require("url"));
61
- var import_ws = __toESM(require("ws"));
61
+ var import_ws = require("ws");
62
62
  var handle = (ws) => ({
63
63
  invalidEndpoint: () => {
64
64
  ws.close(1011, "Invalid WebSocket endpoint");
@@ -75,7 +75,7 @@ var handle = (ws) => ({
75
75
  });
76
76
  var createPluvHandler = (config) => {
77
77
  const { authorize, endpoint = "/api/pluv", io, server } = config;
78
- const wsServer = new import_ws.default.Server({ server });
78
+ const wsServer = new import_ws.Server({ server });
79
79
  const wsHandler = (ws, req) => __async(void 0, null, function* () {
80
80
  var _a;
81
81
  const url = req.url;
@@ -84,7 +84,7 @@ var createPluvHandler = (config) => {
84
84
  onError.invalidEndpoint();
85
85
  return { matched: false };
86
86
  }
87
- const parsed = import_url.default.parse(url, true);
87
+ const parsed = import_node_url.default.parse(url, true);
88
88
  const { pathname } = parsed;
89
89
  if (!pathname)
90
90
  return onError.invalidEndpoint();
@@ -116,7 +116,7 @@ var createPluvHandler = (config) => {
116
116
  const url = req.url;
117
117
  if (!url)
118
118
  return (_c = next == null ? void 0 : next()) != null ? _c : null;
119
- const parsed = import_url.default.parse(url, true);
119
+ const parsed = import_node_url.default.parse(url, true);
120
120
  const { pathname } = parsed;
121
121
  if (!pathname)
122
122
  return (_d = next == null ? void 0 : next()) != null ? _d : null;
@@ -203,9 +203,7 @@ var NodeWebSocket = class extends import_io.AbstractWebSocket {
203
203
  }
204
204
  }
205
205
  close(code, reason) {
206
- const canClose = [this.CONNECTING, this.OPEN].some(
207
- (readyState) => readyState === this.readyState
208
- );
206
+ const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
209
207
  if (!canClose)
210
208
  return;
211
209
  this.webSocket.close(code, reason);
package/dist/index.mjs CHANGED
@@ -20,9 +20,9 @@ var __async = (__this, __arguments, generator) => {
20
20
  };
21
21
 
22
22
  // src/createPluvHandler.ts
23
- import { match } from "path-to-regexp";
24
23
  import Url from "url";
25
- import WS from "ws";
24
+ import { match } from "path-to-regexp";
25
+ import { Server as WsServer } from "ws";
26
26
  var handle = (ws) => ({
27
27
  invalidEndpoint: () => {
28
28
  ws.close(1011, "Invalid WebSocket endpoint");
@@ -39,7 +39,7 @@ var handle = (ws) => ({
39
39
  });
40
40
  var createPluvHandler = (config) => {
41
41
  const { authorize, endpoint = "/api/pluv", io, server } = config;
42
- const wsServer = new WS.Server({ server });
42
+ const wsServer = new WsServer({ server });
43
43
  const wsHandler = (ws, req) => __async(void 0, null, function* () {
44
44
  var _a;
45
45
  const url = req.url;
@@ -167,9 +167,7 @@ var NodeWebSocket = class extends AbstractWebSocket {
167
167
  }
168
168
  }
169
169
  close(code, reason) {
170
- const canClose = [this.CONNECTING, this.OPEN].some(
171
- (readyState) => readyState === this.readyState
172
- );
170
+ const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
173
171
  if (!canClose)
174
172
  return;
175
173
  this.webSocket.close(code, reason);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-node",
3
- "version": "0.17.3",
3
+ "version": "0.18.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.12.7",
20
+ "@types/node": "^20.12.13",
21
21
  "@types/ws": "^8.5.10",
22
22
  "path-to-regexp": "^6.2.2",
23
- "@pluv/io": "^0.17.3",
24
- "@pluv/types": "^0.17.3"
23
+ "@pluv/io": "^0.18.0",
24
+ "@pluv/types": "^0.18.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "eslint": "^8.57.0",
28
28
  "tsup": "^8.0.2",
29
29
  "typescript": "^5.4.5",
30
- "ws": "^8.16.0",
31
- "@pluv/tsconfig": "^0.17.3",
32
- "eslint-config-pluv": "^0.17.3"
30
+ "ws": "^8.17.0",
31
+ "@pluv/tsconfig": "^0.18.0",
32
+ "eslint-config-pluv": "^0.18.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "ws": "^8.0.0"
@@ -13,20 +13,14 @@ export type NodePlatformOptions =
13
13
  pubSub: AbstractPubSub;
14
14
  };
15
15
 
16
- export class NodePlatform extends AbstractPlatform<
17
- WebSocket,
18
- { req: IncomingMessage }
19
- > {
16
+ export class NodePlatform extends AbstractPlatform<WebSocket, { req: IncomingMessage }> {
20
17
  constructor(options: NodePlatformOptions = {}) {
21
18
  const { persistance, pubSub } = options;
22
19
 
23
20
  super(persistance && pubSub ? { persistance, pubSub } : {});
24
21
  }
25
22
 
26
- public convertWebSocket(
27
- webSocket: WebSocket,
28
- config: ConvertWebSocketConfig,
29
- ): NodeWebSocket {
23
+ public convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): NodeWebSocket {
30
24
  return new NodeWebSocket(webSocket, config);
31
25
  }
32
26
 
@@ -32,10 +32,7 @@ export class NodeWebSocket extends AbstractWebSocket {
32
32
  this.webSocket = webSocket;
33
33
  }
34
34
 
35
- public addEventListener<TType extends keyof AbstractEventMap>(
36
- type: TType,
37
- handler: AbstractListener<TType>,
38
- ): void {
35
+ public addEventListener<TType extends keyof AbstractEventMap>(type: TType, handler: AbstractListener<TType>): void {
39
36
  switch (type) {
40
37
  case "close":
41
38
  this.webSocket.on("close", async (code, reason) => {
@@ -74,9 +71,7 @@ export class NodeWebSocket extends AbstractWebSocket {
74
71
  }
75
72
 
76
73
  public close(code?: number | undefined, reason?: string | undefined): void {
77
- const canClose = [this.CONNECTING, this.OPEN].some(
78
- (readyState) => readyState === this.readyState,
79
- );
74
+ const canClose = [this.CONNECTING, this.OPEN].some((readyState) => readyState === this.readyState);
80
75
 
81
76
  if (!canClose) return;
82
77
 
@@ -1,35 +1,36 @@
1
- import type { PluvIO } from "@pluv/io";
2
- import {
1
+ import type { PluvServer } from "@pluv/io";
2
+ import type {
3
3
  InferIOAuthorize,
4
4
  InferIOAuthorizeRequired,
5
5
  InferIOAuthorizeUser,
6
6
  Maybe,
7
7
  MaybePromise,
8
8
  } from "@pluv/types";
9
- import Http from "http";
9
+ import type { Server as HttpServer, IncomingMessage, ServerResponse } from "node:http";
10
+ import Url from "node:url";
10
11
  import { match } from "path-to-regexp";
11
- import Url from "url";
12
- import WS from "ws";
12
+ import type { WebSocket } from "ws";
13
+ import { Server as WsServer } from "ws";
13
14
  import { NodePlatform } from "./NodePlatform";
14
15
 
15
16
  export interface AuthorizeFunctionContext {
16
- req: Http.IncomingMessage;
17
- res: Http.ServerResponse;
17
+ req: IncomingMessage;
18
+ res: ServerResponse;
18
19
  roomId: string;
19
20
  }
20
- export type AuthorizeFunction<TPluv extends PluvIO<NodePlatform>> = (
21
+ export type AuthorizeFunction<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = (
21
22
  ctx: AuthorizeFunctionContext,
22
- ) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluv>>>>;
23
+ ) => MaybePromise<Maybe<InferIOAuthorizeUser<InferIOAuthorize<TPluvServer>>>>;
23
24
 
24
- export type CreatePluvHandlerConfig<TPluv extends PluvIO<NodePlatform>> = {
25
+ export type CreatePluvHandlerConfig<TPluvServer extends PluvServer<NodePlatform, any, any, any>> = {
25
26
  endpoint?: string;
26
- io: TPluv;
27
- server: Http.Server;
28
- } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluv>> extends true
29
- ? { authorize: AuthorizeFunction<TPluv> }
27
+ io: TPluvServer;
28
+ server: HttpServer;
29
+ } & (InferIOAuthorizeRequired<InferIOAuthorize<TPluvServer>> extends true
30
+ ? { authorize: AuthorizeFunction<TPluvServer> }
30
31
  : { authorize?: undefined });
31
32
 
32
- const handle = (ws: WS.WebSocket) => ({
33
+ const handle = (ws: WebSocket) => ({
33
34
  invalidEndpoint: () => {
34
35
  ws.close(1011, "Invalid WebSocket endpoint");
35
36
 
@@ -47,40 +48,28 @@ const handle = (ws: WS.WebSocket) => ({
47
48
  },
48
49
  });
49
50
 
50
- export type RequestHandler = (
51
- req: Http.IncomingMessage,
52
- res: Http.ServerResponse,
53
- next?: () => void,
54
- ) => void;
51
+ export type RequestHandler = (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
55
52
 
56
53
  export interface WebSocketHandlerResult {
57
54
  matched: boolean;
58
55
  }
59
56
 
60
- export type WebSocketHandler = (
61
- ws: WS.WebSocket,
62
- req: Http.IncomingMessage,
63
- ) => Promise<WebSocketHandlerResult>;
57
+ export type WebSocketHandler = (ws: WebSocket, req: IncomingMessage) => Promise<WebSocketHandlerResult>;
64
58
 
65
59
  export interface CreatePluvHandlerResult {
66
- createWsServer: () => WS.Server;
60
+ createWsServer: () => WsServer;
67
61
  handler: RequestHandler;
68
62
  wsHandler: WebSocketHandler;
69
63
  }
70
64
 
71
- export const createPluvHandler = <
72
- TPluv extends PluvIO<NodePlatform, any, any, any, any, any, any>,
73
- >(
74
- config: CreatePluvHandlerConfig<TPluv>,
65
+ export const createPluvHandler = <TPluvServer extends PluvServer<NodePlatform, any, any, any>>(
66
+ config: CreatePluvHandlerConfig<TPluvServer>,
75
67
  ): CreatePluvHandlerResult => {
76
68
  const { authorize, endpoint = "/api/pluv", io, server } = config;
77
69
 
78
- const wsServer = new WS.Server({ server });
70
+ const wsServer = new WsServer({ server });
79
71
 
80
- const wsHandler = async (
81
- ws: WS.WebSocket,
82
- req: Http.IncomingMessage,
83
- ): Promise<WebSocketHandlerResult> => {
72
+ const wsHandler = async (ws: WebSocket, req: IncomingMessage): Promise<WebSocketHandlerResult> => {
84
73
  const url = req.url;
85
74
  const onError = handle(ws);
86
75
 
@@ -122,10 +111,10 @@ export const createPluvHandler = <
122
111
  };
123
112
 
124
113
  const handler = async (
125
- req: Http.IncomingMessage,
126
- res: Http.ServerResponse,
114
+ req: IncomingMessage,
115
+ res: ServerResponse,
127
116
  next?: () => void,
128
- ): Promise<Http.ServerResponse | null> => {
117
+ ): Promise<ServerResponse | null> => {
129
118
  if (!authorize) return next?.() ?? null;
130
119
  if (req.method !== "GET") return next?.() ?? null;
131
120
 
package/src/index.ts CHANGED
@@ -1,8 +1,4 @@
1
- export type {
2
- AuthorizeFunction,
3
- AuthorizeFunctionContext,
4
- CreatePluvHandlerConfig,
5
- } from "./createPluvHandler";
1
+ export type { AuthorizeFunction, AuthorizeFunctionContext, CreatePluvHandlerConfig } from "./createPluvHandler";
6
2
  export { createPluvHandler } from "./createPluvHandler";
7
3
  export type { WebSocket } from "ws";
8
4
  export type { NodePlatformOptions } from "./NodePlatform";
@@ -1,8 +1,6 @@
1
1
  import type { NodePlatformOptions } from "./NodePlatform";
2
2
  import { NodePlatform } from "./NodePlatform";
3
3
 
4
- export const platformNode = (
5
- options: NodePlatformOptions = {},
6
- ): NodePlatform => {
4
+ export const platformNode = (options: NodePlatformOptions = {}): NodePlatform => {
7
5
  return new NodePlatform(options);
8
6
  };