elit 2.0.0 → 3.0.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/README.md +436 -237
- package/dist/build.d.mts +10 -1
- package/dist/build.d.ts +10 -1
- package/dist/build.js +670 -1
- package/dist/build.mjs +641 -1
- package/dist/chokidar.d.mts +134 -0
- package/dist/chokidar.d.ts +134 -0
- package/dist/chokidar.js +240 -0
- package/dist/chokidar.mjs +221 -0
- package/dist/cli.js +2792 -495
- package/dist/dom.d.mts +10 -3
- package/dist/dom.d.ts +10 -3
- package/dist/dom.js +676 -1
- package/dist/dom.mjs +647 -1
- package/dist/el.d.mts +16 -36
- package/dist/el.d.ts +16 -36
- package/dist/el.js +789 -1
- package/dist/el.mjs +583 -1
- package/dist/fs.d.mts +255 -0
- package/dist/fs.d.ts +255 -0
- package/dist/fs.js +513 -0
- package/dist/fs.mjs +469 -0
- package/dist/hmr.js +112 -1
- package/dist/hmr.mjs +91 -1
- package/dist/http.d.mts +163 -0
- package/dist/http.d.ts +163 -0
- package/dist/http.js +632 -0
- package/dist/http.mjs +605 -0
- package/dist/https.d.mts +108 -0
- package/dist/https.d.ts +108 -0
- package/dist/https.js +907 -0
- package/dist/https.mjs +901 -0
- package/dist/index.d.mts +613 -33
- package/dist/index.d.ts +613 -33
- package/dist/index.js +2589 -1
- package/dist/index.mjs +2312 -1
- package/dist/mime-types.d.mts +48 -0
- package/dist/mime-types.d.ts +48 -0
- package/dist/mime-types.js +197 -0
- package/dist/mime-types.mjs +166 -0
- package/dist/path.d.mts +163 -0
- package/dist/path.d.ts +163 -0
- package/dist/path.js +350 -0
- package/dist/path.mjs +310 -0
- package/dist/router.d.mts +3 -1
- package/dist/router.d.ts +3 -1
- package/dist/router.js +830 -1
- package/dist/router.mjs +801 -1
- package/dist/runtime.d.mts +97 -0
- package/dist/runtime.d.ts +97 -0
- package/dist/runtime.js +43 -0
- package/dist/runtime.mjs +15 -0
- package/dist/server.d.mts +5 -1
- package/dist/server.d.ts +5 -1
- package/dist/server.js +3267 -1
- package/dist/server.mjs +3241 -1
- package/dist/state.d.mts +3 -1
- package/dist/state.d.ts +3 -1
- package/dist/state.js +1036 -1
- package/dist/state.mjs +992 -1
- package/dist/style.d.mts +47 -1
- package/dist/style.d.ts +47 -1
- package/dist/style.js +551 -1
- package/dist/style.mjs +483 -1
- package/dist/{types-DOAdFFJB.d.ts → types-C0nGi6MX.d.mts} +29 -13
- package/dist/{types-DOAdFFJB.d.mts → types-Du6kfwTm.d.ts} +29 -13
- package/dist/types.d.mts +452 -3
- package/dist/types.d.ts +452 -3
- package/dist/types.js +18 -1
- package/dist/ws.d.mts +195 -0
- package/dist/ws.d.ts +195 -0
- package/dist/ws.js +380 -0
- package/dist/ws.mjs +358 -0
- package/dist/wss.d.mts +108 -0
- package/dist/wss.d.ts +108 -0
- package/dist/wss.js +1306 -0
- package/dist/wss.mjs +1300 -0
- package/package.json +53 -6
- package/dist/client.d.mts +0 -9
- package/dist/client.d.ts +0 -9
- package/dist/client.js +0 -1
- package/dist/client.mjs +0 -1
package/dist/ws.mjs
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import {createRequire as __createRequire} from 'module';const require = __createRequire(import.meta.url);
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/ws.ts
|
|
10
|
+
import { EventEmitter } from "events";
|
|
11
|
+
|
|
12
|
+
// src/runtime.ts
|
|
13
|
+
var runtime = (() => {
|
|
14
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
15
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
16
|
+
return "node";
|
|
17
|
+
})();
|
|
18
|
+
|
|
19
|
+
// src/ws.ts
|
|
20
|
+
var ReadyState = /* @__PURE__ */ ((ReadyState2) => {
|
|
21
|
+
ReadyState2[ReadyState2["CONNECTING"] = 0] = "CONNECTING";
|
|
22
|
+
ReadyState2[ReadyState2["OPEN"] = 1] = "OPEN";
|
|
23
|
+
ReadyState2[ReadyState2["CLOSING"] = 2] = "CLOSING";
|
|
24
|
+
ReadyState2[ReadyState2["CLOSED"] = 3] = "CLOSED";
|
|
25
|
+
return ReadyState2;
|
|
26
|
+
})(ReadyState || {});
|
|
27
|
+
var CLOSE_CODES = {
|
|
28
|
+
NORMAL: 1e3,
|
|
29
|
+
GOING_AWAY: 1001,
|
|
30
|
+
PROTOCOL_ERROR: 1002,
|
|
31
|
+
UNSUPPORTED_DATA: 1003,
|
|
32
|
+
NO_STATUS: 1005,
|
|
33
|
+
ABNORMAL: 1006,
|
|
34
|
+
INVALID_DATA: 1007,
|
|
35
|
+
POLICY_VIOLATION: 1008,
|
|
36
|
+
MESSAGE_TOO_BIG: 1009,
|
|
37
|
+
EXTENSION_REQUIRED: 1010,
|
|
38
|
+
INTERNAL_ERROR: 1011,
|
|
39
|
+
SERVICE_RESTART: 1012,
|
|
40
|
+
TRY_AGAIN_LATER: 1013,
|
|
41
|
+
BAD_GATEWAY: 1014,
|
|
42
|
+
TLS_HANDSHAKE_FAIL: 1015
|
|
43
|
+
};
|
|
44
|
+
function queueCallback(callback, error) {
|
|
45
|
+
if (callback) {
|
|
46
|
+
queueMicrotask(() => callback(error));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function createNativeWebSocket(url, protocols) {
|
|
50
|
+
if (runtime === "node" && typeof globalThis.WebSocket === "undefined") {
|
|
51
|
+
throw new Error("WebSocket is not available. Please use Node.js 18+ or install ws package.");
|
|
52
|
+
}
|
|
53
|
+
return new globalThis.WebSocket(url, protocols);
|
|
54
|
+
}
|
|
55
|
+
var WebSocket = class extends EventEmitter {
|
|
56
|
+
constructor(address, protocols, _options) {
|
|
57
|
+
super();
|
|
58
|
+
this.readyState = 0 /* CONNECTING */;
|
|
59
|
+
this.protocol = "";
|
|
60
|
+
this.extensions = "";
|
|
61
|
+
this.binaryType = "nodebuffer";
|
|
62
|
+
this.url = typeof address === "string" ? address : address.toString();
|
|
63
|
+
const protocolsArray = Array.isArray(protocols) ? protocols : protocols ? [protocols] : void 0;
|
|
64
|
+
this._socket = createNativeWebSocket(this.url, protocolsArray);
|
|
65
|
+
this._setupNativeSocket();
|
|
66
|
+
}
|
|
67
|
+
_setupNativeSocket() {
|
|
68
|
+
this._socket.onopen = () => {
|
|
69
|
+
this.readyState = 1 /* OPEN */;
|
|
70
|
+
this.emit("open");
|
|
71
|
+
};
|
|
72
|
+
this._socket.onmessage = (event) => {
|
|
73
|
+
const isBinary = event.data instanceof ArrayBuffer || event.data instanceof Blob;
|
|
74
|
+
this.emit("message", event.data, isBinary);
|
|
75
|
+
};
|
|
76
|
+
this._socket.onclose = (event) => {
|
|
77
|
+
this.readyState = 3 /* CLOSED */;
|
|
78
|
+
this.emit("close", event.code, event.reason);
|
|
79
|
+
};
|
|
80
|
+
this._socket.onerror = () => {
|
|
81
|
+
this.emit("error", new Error("WebSocket error"));
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Send data through WebSocket
|
|
86
|
+
*/
|
|
87
|
+
send(data, options, callback) {
|
|
88
|
+
const cb = typeof options === "function" ? options : callback;
|
|
89
|
+
if (this.readyState !== 1 /* OPEN */) {
|
|
90
|
+
return queueCallback(cb, new Error("WebSocket is not open"));
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
this._socket.send(data);
|
|
94
|
+
queueCallback(cb);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
queueCallback(cb, error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Close the WebSocket connection
|
|
101
|
+
*/
|
|
102
|
+
close(code, reason) {
|
|
103
|
+
if (this.readyState === 3 /* CLOSED */ || this.readyState === 2 /* CLOSING */) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.readyState = 2 /* CLOSING */;
|
|
107
|
+
this._socket.close(code, typeof reason === "string" ? reason : reason?.toString());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Pause the socket (no-op for native WebSocket)
|
|
111
|
+
*/
|
|
112
|
+
pause() {
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resume the socket (no-op for native WebSocket)
|
|
116
|
+
*/
|
|
117
|
+
resume() {
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Send a ping frame (no-op for native WebSocket)
|
|
121
|
+
*/
|
|
122
|
+
ping(_data, _mask, callback) {
|
|
123
|
+
queueCallback(callback);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Send a pong frame (no-op for native WebSocket)
|
|
127
|
+
*/
|
|
128
|
+
pong(_data, _mask, callback) {
|
|
129
|
+
queueCallback(callback);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Terminate the connection
|
|
133
|
+
*/
|
|
134
|
+
terminate() {
|
|
135
|
+
this._socket.close();
|
|
136
|
+
this.readyState = 3 /* CLOSED */;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get buffered amount
|
|
140
|
+
*/
|
|
141
|
+
get bufferedAmount() {
|
|
142
|
+
return this._socket.bufferedAmount || 0;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var WebSocketServer = class extends EventEmitter {
|
|
146
|
+
constructor(options, callback) {
|
|
147
|
+
super();
|
|
148
|
+
this.clients = /* @__PURE__ */ new Set();
|
|
149
|
+
this.options = options || {};
|
|
150
|
+
this.path = options?.path || "/";
|
|
151
|
+
if (runtime === "node") {
|
|
152
|
+
if (options?.server) {
|
|
153
|
+
this._httpServer = options.server;
|
|
154
|
+
this._setupUpgradeHandler();
|
|
155
|
+
} else if (options?.noServer) {
|
|
156
|
+
} else {
|
|
157
|
+
const http = __require("http");
|
|
158
|
+
this._httpServer = http.createServer();
|
|
159
|
+
this._setupUpgradeHandler();
|
|
160
|
+
if (options?.port) {
|
|
161
|
+
this._httpServer.listen(options.port, options.host, callback);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
queueCallback(callback);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
_setupUpgradeHandler() {
|
|
169
|
+
this._httpServer.on("upgrade", (request, socket, head) => {
|
|
170
|
+
console.log("[WebSocket] Upgrade request:", request.url, "Expected:", this.path);
|
|
171
|
+
if (this.path && this.path !== "/" && request.url !== this.path) {
|
|
172
|
+
console.log("[WebSocket] Path mismatch, ignoring");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.handleUpgrade(request, socket, head, (client) => {
|
|
176
|
+
console.log("[WebSocket] Client connected");
|
|
177
|
+
this.emit("connection", client, request);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Handle HTTP upgrade for WebSocket
|
|
183
|
+
*/
|
|
184
|
+
handleUpgrade(request, socket, _head, callback) {
|
|
185
|
+
const key = request.headers["sec-websocket-key"];
|
|
186
|
+
if (!key) {
|
|
187
|
+
socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const crypto = __require("crypto");
|
|
191
|
+
const acceptKey = crypto.createHash("sha1").update(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
192
|
+
const headers = [
|
|
193
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
194
|
+
"Upgrade: websocket",
|
|
195
|
+
"Connection: Upgrade",
|
|
196
|
+
`Sec-WebSocket-Accept: ${acceptKey}`,
|
|
197
|
+
"",
|
|
198
|
+
""
|
|
199
|
+
];
|
|
200
|
+
socket.write(headers.join("\r\n"));
|
|
201
|
+
const client = this._createClientFromSocket(socket);
|
|
202
|
+
if (this.options.clientTracking !== false) {
|
|
203
|
+
this.clients.add(client);
|
|
204
|
+
client.on("close", () => {
|
|
205
|
+
this.clients.delete(client);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
callback(client);
|
|
209
|
+
}
|
|
210
|
+
_createClientFromSocket(socket) {
|
|
211
|
+
const client = Object.create(WebSocket.prototype);
|
|
212
|
+
EventEmitter.call(client);
|
|
213
|
+
client.readyState = 1 /* OPEN */;
|
|
214
|
+
client.url = "ws://localhost";
|
|
215
|
+
client.protocol = "";
|
|
216
|
+
client.extensions = "";
|
|
217
|
+
client.binaryType = "nodebuffer";
|
|
218
|
+
client._socket = socket;
|
|
219
|
+
socket.on("data", (data) => {
|
|
220
|
+
try {
|
|
221
|
+
const message = this._parseFrame(data);
|
|
222
|
+
if (message) {
|
|
223
|
+
client.emit("message", message, false);
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
client.emit("error", error);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
socket.on("end", () => {
|
|
230
|
+
client.readyState = 3 /* CLOSED */;
|
|
231
|
+
client.emit("close", CLOSE_CODES.NORMAL, "");
|
|
232
|
+
});
|
|
233
|
+
socket.on("error", (error) => {
|
|
234
|
+
client.emit("error", error);
|
|
235
|
+
});
|
|
236
|
+
client.send = (data, _options, callback) => {
|
|
237
|
+
try {
|
|
238
|
+
const frame = this._createFrame(data);
|
|
239
|
+
socket.write(frame);
|
|
240
|
+
queueCallback(callback);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
queueCallback(callback, error);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
client.close = (_code, _reason) => {
|
|
246
|
+
socket.end();
|
|
247
|
+
client.readyState = 3 /* CLOSED */;
|
|
248
|
+
};
|
|
249
|
+
return client;
|
|
250
|
+
}
|
|
251
|
+
_parseFrame(data) {
|
|
252
|
+
if (data.length < 2) return null;
|
|
253
|
+
const firstByte = data[0];
|
|
254
|
+
const secondByte = data[1];
|
|
255
|
+
const opcode = firstByte & 15;
|
|
256
|
+
const isMasked = (secondByte & 128) === 128;
|
|
257
|
+
let payloadLength = secondByte & 127;
|
|
258
|
+
let offset = 2;
|
|
259
|
+
if (payloadLength === 126) {
|
|
260
|
+
payloadLength = data.readUInt16BE(2);
|
|
261
|
+
offset = 4;
|
|
262
|
+
} else if (payloadLength === 127) {
|
|
263
|
+
payloadLength = Number(data.readBigUInt64BE(2));
|
|
264
|
+
offset = 10;
|
|
265
|
+
}
|
|
266
|
+
let payload = data.subarray(offset);
|
|
267
|
+
if (isMasked) {
|
|
268
|
+
const maskKey = data.subarray(offset, offset + 4);
|
|
269
|
+
payload = data.subarray(offset + 4, offset + 4 + payloadLength);
|
|
270
|
+
for (let i = 0; i < payload.length; i++) {
|
|
271
|
+
payload[i] ^= maskKey[i % 4];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (opcode === 1) {
|
|
275
|
+
return payload.toString("utf8");
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
_createFrame(data) {
|
|
280
|
+
const payload = typeof data === "string" ? Buffer.from(data) : data;
|
|
281
|
+
const payloadLength = Buffer.isBuffer(payload) ? payload.length : 0;
|
|
282
|
+
let frame;
|
|
283
|
+
let offset = 2;
|
|
284
|
+
if (payloadLength < 126) {
|
|
285
|
+
frame = Buffer.allocUnsafe(2 + payloadLength);
|
|
286
|
+
frame[1] = payloadLength;
|
|
287
|
+
} else if (payloadLength < 65536) {
|
|
288
|
+
frame = Buffer.allocUnsafe(4 + payloadLength);
|
|
289
|
+
frame[1] = 126;
|
|
290
|
+
frame.writeUInt16BE(payloadLength, 2);
|
|
291
|
+
offset = 4;
|
|
292
|
+
} else {
|
|
293
|
+
frame = Buffer.allocUnsafe(10 + payloadLength);
|
|
294
|
+
frame[1] = 127;
|
|
295
|
+
frame.writeBigUInt64BE(BigInt(payloadLength), 2);
|
|
296
|
+
offset = 10;
|
|
297
|
+
}
|
|
298
|
+
frame[0] = 129;
|
|
299
|
+
if (Buffer.isBuffer(payload)) {
|
|
300
|
+
payload.copy(frame, offset);
|
|
301
|
+
}
|
|
302
|
+
return frame;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Close the server
|
|
306
|
+
*/
|
|
307
|
+
close(callback) {
|
|
308
|
+
this.clients.forEach((client) => client.close());
|
|
309
|
+
this.clients.clear();
|
|
310
|
+
if (this._httpServer) {
|
|
311
|
+
this._httpServer.close(callback);
|
|
312
|
+
} else {
|
|
313
|
+
this.emit("close");
|
|
314
|
+
queueCallback(callback);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Check if server should handle request
|
|
319
|
+
*/
|
|
320
|
+
shouldHandle(request) {
|
|
321
|
+
if (this.path && request.url !== this.path) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get server address
|
|
328
|
+
*/
|
|
329
|
+
address() {
|
|
330
|
+
if (this._httpServer && this._httpServer.address) {
|
|
331
|
+
return this._httpServer.address();
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
function createWebSocketServer(options, callback) {
|
|
337
|
+
return new WebSocketServer(options, callback);
|
|
338
|
+
}
|
|
339
|
+
function getRuntime() {
|
|
340
|
+
return runtime;
|
|
341
|
+
}
|
|
342
|
+
var ws_default = {
|
|
343
|
+
WebSocket,
|
|
344
|
+
WebSocketServer,
|
|
345
|
+
createWebSocketServer,
|
|
346
|
+
ReadyState,
|
|
347
|
+
CLOSE_CODES,
|
|
348
|
+
getRuntime
|
|
349
|
+
};
|
|
350
|
+
export {
|
|
351
|
+
CLOSE_CODES,
|
|
352
|
+
ReadyState,
|
|
353
|
+
WebSocket,
|
|
354
|
+
WebSocketServer,
|
|
355
|
+
createWebSocketServer,
|
|
356
|
+
ws_default as default,
|
|
357
|
+
getRuntime
|
|
358
|
+
};
|
package/dist/wss.d.mts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { IncomingMessage } from './http.mjs';
|
|
3
|
+
import { WebSocket, ServerOptions, ReadyState } from './ws.mjs';
|
|
4
|
+
export { CLOSE_CODES, Data } from './ws.mjs';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WebSocket Secure (WSS) module with unified API across runtimes
|
|
9
|
+
* Pure implementation without external dependencies
|
|
10
|
+
* Compatible with 'ws' package WSS API
|
|
11
|
+
* - Node.js: uses native WebSocket with HTTPS
|
|
12
|
+
* - Bun: uses native WebSocket with TLS
|
|
13
|
+
* - Deno: uses native WebSocket with TLS
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WSS Server options (extends WebSocket ServerOptions with TLS)
|
|
18
|
+
*/
|
|
19
|
+
interface WSSServerOptions extends ServerOptions {
|
|
20
|
+
key?: string | Buffer;
|
|
21
|
+
cert?: string | Buffer;
|
|
22
|
+
ca?: string | Buffer;
|
|
23
|
+
passphrase?: string;
|
|
24
|
+
rejectUnauthorized?: boolean;
|
|
25
|
+
requestCert?: boolean;
|
|
26
|
+
httpsServer?: any;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* WebSocket Secure client class
|
|
30
|
+
*/
|
|
31
|
+
declare class WSSClient extends WebSocket {
|
|
32
|
+
constructor(address: string | URL, protocols?: string | string[], options?: any);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* WebSocket Secure Server class
|
|
36
|
+
*/
|
|
37
|
+
declare class WSSServer extends EventEmitter {
|
|
38
|
+
clients: Set<WebSocket>;
|
|
39
|
+
options: WSSServerOptions;
|
|
40
|
+
path: string;
|
|
41
|
+
private _httpsServer;
|
|
42
|
+
private _wsServer;
|
|
43
|
+
constructor(options?: WSSServerOptions, callback?: () => void);
|
|
44
|
+
private _setupServer;
|
|
45
|
+
/**
|
|
46
|
+
* Handle HTTP upgrade for WebSocket
|
|
47
|
+
*/
|
|
48
|
+
handleUpgrade(request: IncomingMessage, socket: any, head: Buffer, callback: (client: WebSocket) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Check if server should handle request
|
|
51
|
+
*/
|
|
52
|
+
shouldHandle(request: IncomingMessage): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Close the server
|
|
55
|
+
*/
|
|
56
|
+
close(callback?: (err?: Error) => void): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get server address
|
|
59
|
+
*/
|
|
60
|
+
address(): {
|
|
61
|
+
port: number;
|
|
62
|
+
family: string;
|
|
63
|
+
address: string;
|
|
64
|
+
} | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create WebSocket Secure client
|
|
68
|
+
*/
|
|
69
|
+
declare function createWSSClient(address: string | URL, protocols?: string | string[], options?: any): WSSClient;
|
|
70
|
+
/**
|
|
71
|
+
* Create WebSocket Secure server
|
|
72
|
+
*/
|
|
73
|
+
declare function createWSSServer(options?: WSSServerOptions, callback?: () => void): WSSServer;
|
|
74
|
+
/**
|
|
75
|
+
* Get current runtime
|
|
76
|
+
*/
|
|
77
|
+
declare function getRuntime(): 'node' | 'bun' | 'deno';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Default export
|
|
81
|
+
*/
|
|
82
|
+
declare const _default: {
|
|
83
|
+
WSSClient: typeof WSSClient;
|
|
84
|
+
WSSServer: typeof WSSServer;
|
|
85
|
+
createWSSClient: typeof createWSSClient;
|
|
86
|
+
createWSSServer: typeof createWSSServer;
|
|
87
|
+
ReadyState: typeof ReadyState;
|
|
88
|
+
CLOSE_CODES: {
|
|
89
|
+
readonly NORMAL: 1000;
|
|
90
|
+
readonly GOING_AWAY: 1001;
|
|
91
|
+
readonly PROTOCOL_ERROR: 1002;
|
|
92
|
+
readonly UNSUPPORTED_DATA: 1003;
|
|
93
|
+
readonly NO_STATUS: 1005;
|
|
94
|
+
readonly ABNORMAL: 1006;
|
|
95
|
+
readonly INVALID_DATA: 1007;
|
|
96
|
+
readonly POLICY_VIOLATION: 1008;
|
|
97
|
+
readonly MESSAGE_TOO_BIG: 1009;
|
|
98
|
+
readonly EXTENSION_REQUIRED: 1010;
|
|
99
|
+
readonly INTERNAL_ERROR: 1011;
|
|
100
|
+
readonly SERVICE_RESTART: 1012;
|
|
101
|
+
readonly TRY_AGAIN_LATER: 1013;
|
|
102
|
+
readonly BAD_GATEWAY: 1014;
|
|
103
|
+
readonly TLS_HANDSHAKE_FAIL: 1015;
|
|
104
|
+
};
|
|
105
|
+
getRuntime: typeof getRuntime;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { ReadyState, ServerOptions, WSSClient, WSSServer, type WSSServerOptions, createWSSClient, createWSSServer, _default as default, getRuntime };
|
package/dist/wss.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { IncomingMessage } from './http.js';
|
|
3
|
+
import { WebSocket, ServerOptions, ReadyState } from './ws.js';
|
|
4
|
+
export { CLOSE_CODES, Data } from './ws.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WebSocket Secure (WSS) module with unified API across runtimes
|
|
9
|
+
* Pure implementation without external dependencies
|
|
10
|
+
* Compatible with 'ws' package WSS API
|
|
11
|
+
* - Node.js: uses native WebSocket with HTTPS
|
|
12
|
+
* - Bun: uses native WebSocket with TLS
|
|
13
|
+
* - Deno: uses native WebSocket with TLS
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WSS Server options (extends WebSocket ServerOptions with TLS)
|
|
18
|
+
*/
|
|
19
|
+
interface WSSServerOptions extends ServerOptions {
|
|
20
|
+
key?: string | Buffer;
|
|
21
|
+
cert?: string | Buffer;
|
|
22
|
+
ca?: string | Buffer;
|
|
23
|
+
passphrase?: string;
|
|
24
|
+
rejectUnauthorized?: boolean;
|
|
25
|
+
requestCert?: boolean;
|
|
26
|
+
httpsServer?: any;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* WebSocket Secure client class
|
|
30
|
+
*/
|
|
31
|
+
declare class WSSClient extends WebSocket {
|
|
32
|
+
constructor(address: string | URL, protocols?: string | string[], options?: any);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* WebSocket Secure Server class
|
|
36
|
+
*/
|
|
37
|
+
declare class WSSServer extends EventEmitter {
|
|
38
|
+
clients: Set<WebSocket>;
|
|
39
|
+
options: WSSServerOptions;
|
|
40
|
+
path: string;
|
|
41
|
+
private _httpsServer;
|
|
42
|
+
private _wsServer;
|
|
43
|
+
constructor(options?: WSSServerOptions, callback?: () => void);
|
|
44
|
+
private _setupServer;
|
|
45
|
+
/**
|
|
46
|
+
* Handle HTTP upgrade for WebSocket
|
|
47
|
+
*/
|
|
48
|
+
handleUpgrade(request: IncomingMessage, socket: any, head: Buffer, callback: (client: WebSocket) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Check if server should handle request
|
|
51
|
+
*/
|
|
52
|
+
shouldHandle(request: IncomingMessage): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Close the server
|
|
55
|
+
*/
|
|
56
|
+
close(callback?: (err?: Error) => void): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get server address
|
|
59
|
+
*/
|
|
60
|
+
address(): {
|
|
61
|
+
port: number;
|
|
62
|
+
family: string;
|
|
63
|
+
address: string;
|
|
64
|
+
} | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create WebSocket Secure client
|
|
68
|
+
*/
|
|
69
|
+
declare function createWSSClient(address: string | URL, protocols?: string | string[], options?: any): WSSClient;
|
|
70
|
+
/**
|
|
71
|
+
* Create WebSocket Secure server
|
|
72
|
+
*/
|
|
73
|
+
declare function createWSSServer(options?: WSSServerOptions, callback?: () => void): WSSServer;
|
|
74
|
+
/**
|
|
75
|
+
* Get current runtime
|
|
76
|
+
*/
|
|
77
|
+
declare function getRuntime(): 'node' | 'bun' | 'deno';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Default export
|
|
81
|
+
*/
|
|
82
|
+
declare const _default: {
|
|
83
|
+
WSSClient: typeof WSSClient;
|
|
84
|
+
WSSServer: typeof WSSServer;
|
|
85
|
+
createWSSClient: typeof createWSSClient;
|
|
86
|
+
createWSSServer: typeof createWSSServer;
|
|
87
|
+
ReadyState: typeof ReadyState;
|
|
88
|
+
CLOSE_CODES: {
|
|
89
|
+
readonly NORMAL: 1000;
|
|
90
|
+
readonly GOING_AWAY: 1001;
|
|
91
|
+
readonly PROTOCOL_ERROR: 1002;
|
|
92
|
+
readonly UNSUPPORTED_DATA: 1003;
|
|
93
|
+
readonly NO_STATUS: 1005;
|
|
94
|
+
readonly ABNORMAL: 1006;
|
|
95
|
+
readonly INVALID_DATA: 1007;
|
|
96
|
+
readonly POLICY_VIOLATION: 1008;
|
|
97
|
+
readonly MESSAGE_TOO_BIG: 1009;
|
|
98
|
+
readonly EXTENSION_REQUIRED: 1010;
|
|
99
|
+
readonly INTERNAL_ERROR: 1011;
|
|
100
|
+
readonly SERVICE_RESTART: 1012;
|
|
101
|
+
readonly TRY_AGAIN_LATER: 1013;
|
|
102
|
+
readonly BAD_GATEWAY: 1014;
|
|
103
|
+
readonly TLS_HANDSHAKE_FAIL: 1015;
|
|
104
|
+
};
|
|
105
|
+
getRuntime: typeof getRuntime;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { ReadyState, ServerOptions, WSSClient, WSSServer, type WSSServerOptions, createWSSClient, createWSSServer, _default as default, getRuntime };
|