redweb 0.4.3 → 0.4.4

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.
Files changed (2) hide show
  1. package/index.d.ts +141 -0
  2. package/package.json +2 -2
package/index.d.ts ADDED
@@ -0,0 +1,141 @@
1
+ declare module 'redweb' {
2
+ import { Request, Response } from 'express';
3
+ import { Server as HTTPServer } from 'http';
4
+ import { Server as HTTPSServer } from 'https';
5
+ import { WebSocket } from 'ws';
6
+
7
+ /**
8
+ * RedWeb encoding types.
9
+ */
10
+ export type RedWebEncoding = 'json' | 'urlencoded';
11
+
12
+ /**
13
+ * RedWeb options object.
14
+ */
15
+ export interface RedWebOptions {
16
+ port?: number;
17
+ bind?: string;
18
+ publicPaths?: string[];
19
+ services?: Array<{ serviceName: string; method: string; function: (req: Request, res: Response) => void; }>;
20
+ listenCallback?: () => void;
21
+ encoding?: RedWebEncoding;
22
+ ssl?: {
23
+ key: string;
24
+ cert: string;
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Socket server options.
30
+ */
31
+ export interface SocketServerOptions {
32
+ port?: number;
33
+ connectionOpenCallback?: (socket: WebSocket) => void;
34
+ connectionCloseCallback?: (socket: WebSocket) => void;
35
+ messageCallback?: (socket: WebSocket, message: string) => void;
36
+ messageHandlers?: {
37
+ [type: string]: (socket: WebSocket, data: any) => void;
38
+ };
39
+ ssl?: {
40
+ key: string;
41
+ cert: string;
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Base HTTP server.
47
+ */
48
+ export class BaseHttpServer {
49
+ app: any;
50
+ port: number;
51
+ publicPaths: string[];
52
+ services: Array<{ serviceName: string; method: string; function: (req: Request, res: Response) => void; }>;
53
+ listenCallback?: () => void;
54
+ encoding: RedWebEncoding;
55
+ ssl?: { key: string; cert: string; };
56
+
57
+ constructor(options?: RedWebOptions);
58
+
59
+ // Additional methods can be added as needed.
60
+ }
61
+
62
+ /**
63
+ * HTTP server.
64
+ */
65
+ export class HttpServer extends BaseHttpServer {
66
+ constructor(options?: RedWebOptions);
67
+ }
68
+
69
+ /**
70
+ * HTTPS server.
71
+ */
72
+ export class HttpsServer extends BaseHttpServer {
73
+ constructor(options?: RedWebOptions);
74
+ }
75
+
76
+ /**
77
+ * Base socket server.
78
+ */
79
+ export class BaseSocketServer {
80
+ wss: any;
81
+ clients: Map<string, WebSocket>;
82
+ port: number;
83
+ connectionOpenCallback?: (socket: WebSocket) => void;
84
+ connectionCloseCallback?: (socket: WebSocket) => void;
85
+ messageCallback?: (socket: WebSocket, message: string) => void;
86
+ messageHandlers?: { [type: string]: (socket: WebSocket, data: any) => void; };
87
+ ssl?: { key: string; cert: string; };
88
+
89
+ constructor(server: HTTPServer | HTTPSServer, options?: SocketServerOptions);
90
+
91
+ handleConnection(socket: WebSocket, req: any): void;
92
+ handleMessage(socket: WebSocket, message: string, ip: string): void;
93
+ handleClose(socket: WebSocket, ip: string): void;
94
+ handleError(socket: WebSocket, error: Error, ip: string): void;
95
+ }
96
+
97
+ /**
98
+ * WebSocket server.
99
+ */
100
+ export class SocketServer extends BaseSocketServer {
101
+ constructor(options?: SocketServerOptions);
102
+ }
103
+
104
+ /**
105
+ * Secure WebSocket server.
106
+ */
107
+ export class SecureSocketServer extends BaseSocketServer {
108
+ constructor(options?: SocketServerOptions);
109
+ }
110
+
111
+ /**
112
+ * SSL configuration loader.
113
+ */
114
+ export function loadSslConfig(sslOptions: { key: string; cert: string; }): { key: string; cert: string; };
115
+
116
+ /**
117
+ * Constants for encoding types.
118
+ */
119
+ export const ENCODINGS: {
120
+ json: 'json';
121
+ urlencoded: 'urlencoded';
122
+ };
123
+
124
+ /**
125
+ * Constants for HTTP methods.
126
+ */
127
+ export const METHODS: {
128
+ POST: 'post';
129
+ GET: 'get';
130
+ };
131
+
132
+ /**
133
+ * Default HTTP options.
134
+ */
135
+ export const HTTP_OPTIONS: RedWebOptions;
136
+
137
+ /**
138
+ * Default socket options.
139
+ */
140
+ export const SOCKET_OPTIONS: SocketServerOptions;
141
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "redweb",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "A way to quickly set up an express server",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node tester.js"
8
8
  },
9
9
  "files": [
10
- "src/*"
10
+ "src/*", "index.d.ts"
11
11
  ],
12
12
  "keywords": [],
13
13
  "author": "",