Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Sep 10, 2024
1 parent bb5697b commit 6aa5dc6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
25 changes: 23 additions & 2 deletions types/http-socket.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class HTTPSocket {
export class HTTPSocket extends EventEmitter<string | symbol, any> {
constructor(server: any, res: any, writeOnly: any);
aborted: boolean;
writableNeedDrain: boolean;
Expand All @@ -21,5 +21,26 @@ export class HTTPSocket {
end(data: any, _: any, cb?: () => void): void;
write(data: any, _: any, cb?: () => void): boolean;
_clearTimeout(): void;
_onWrite(data: any, cb: any): void;
[kServer]: any;
[kRes]: any;
[kWriteOnly]: any;
[kReadyState]: {
read: boolean;
write: boolean;
};
[kEncoding]: any;
[kRemoteAdress]: any;
[kUwsRemoteAddress]: any;
[kHead]: any;
[kTimeoutRef]: NodeJS.Timeout;
}
import { EventEmitter } from 'eventemitter3';
import { kServer } from './symbols.js';
import { kRes } from './symbols.js';
import { kWriteOnly } from './symbols.js';
import { kReadyState } from './symbols.js';
import { kEncoding } from './symbols.js';
import { kRemoteAdress } from './symbols.js';
import { kUwsRemoteAddress } from './symbols.js';
import { kHead } from './symbols.js';
import { kTimeoutRef } from './symbols.js';
5 changes: 3 additions & 2 deletions types/server.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Server {
export class Server extends EventEmitter<string | symbol, any> {
/**
* @param {(req: Request, res: Response) => void} handler
* @param {ServerOptions} opts
Expand Down Expand Up @@ -72,6 +72,7 @@ export type ServerOptions = {
} | Parameters<SSLApp>[0];
};
export type FastifyServerFactory = import("fastify").FastifyServerFactory;
import { EventEmitter } from 'eventemitter3';
import { kListen } from './symbols.js';
import { kHandler } from './symbols.js';
import { Request } from './request.js';
Expand All @@ -84,4 +85,4 @@ import { kApp } from './symbols.js';
import { kClosed } from './symbols.js';
import { kListenAll } from './symbols.js';
import { kListening } from './symbols.js';
export { DEDICATED_COMPRESSOR_128KB, DEDICATED_COMPRESSOR_16KB, DEDICATED_COMPRESSOR_256KB, DEDICATED_COMPRESSOR_32KB, DEDICATED_COMPRESSOR_3KB, DEDICATED_COMPRESSOR_4KB, DEDICATED_COMPRESSOR_64KB, DEDICATED_COMPRESSOR_8KB, DEDICATED_DECOMPRESSOR, DEDICATED_DECOMPRESSOR_16KB, DEDICATED_DECOMPRESSOR_1KB, DEDICATED_DECOMPRESSOR_2KB, DEDICATED_DECOMPRESSOR_32KB, DEDICATED_DECOMPRESSOR_4KB, DEDICATED_DECOMPRESSOR_512B, DEDICATED_DECOMPRESSOR_8KB, DISABLED, SHARED_COMPRESSOR, SHARED_DECOMPRESSOR } from "uWebSockets.js";
export { DEDICATED_COMPRESSOR_3KB, DEDICATED_COMPRESSOR_4KB, DEDICATED_COMPRESSOR_8KB, DEDICATED_COMPRESSOR_16KB, DEDICATED_COMPRESSOR_32KB, DEDICATED_COMPRESSOR_64KB, DEDICATED_COMPRESSOR_128KB, DEDICATED_COMPRESSOR_256KB, DEDICATED_DECOMPRESSOR, DEDICATED_DECOMPRESSOR_1KB, DEDICATED_DECOMPRESSOR_2KB, DEDICATED_DECOMPRESSOR_4KB, DEDICATED_DECOMPRESSOR_8KB, DEDICATED_DECOMPRESSOR_16KB, DEDICATED_DECOMPRESSOR_32KB, DEDICATED_DECOMPRESSOR_512B, DISABLED, SHARED_COMPRESSOR, SHARED_DECOMPRESSOR } from "uWebSockets.js";
1 change: 0 additions & 1 deletion types/symbols.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const kWs: unique symbol;
export const kTopic: unique symbol;
export const kDestroyError: unique symbol;
export const kUwsRemoteAddress: unique symbol;
export const kQueue: unique symbol;
export const kHead: unique symbol;
export const kWebSocketOptions: unique symbol;
export const kListenAll: unique symbol;
Expand Down
35 changes: 9 additions & 26 deletions types/websocket-server.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export class WebSocket {
/**
* @extends {EventEmitter<keyof WebsocketEvent, WebsocketEvent[keyof WebsocketEvent]>}
*/
export class WebSocket extends EventEmitter<keyof WebsocketEvent, ((code: number, message: ArrayBuffer) => void) | (() => void) | ((message: ArrayBuffer, isBinary: boolean) => void) | ((message: ArrayBuffer) => void) | ((message: ArrayBuffer) => void)> {
/**
* @param {Buffer} namespace
* @param {Buffer | string} topic
Expand Down Expand Up @@ -58,18 +61,6 @@ export class WebSocket {
* @param {RecognizedString} message
*/
ping(message: RecognizedString): number;
/**
* @template {keyof WebsocketEvent} T
* @param {T} eventName
* @param {WebsocketEvent[T]} listener
*/
on<T extends keyof WebsocketEvent>(eventName: T, listener: WebsocketEvent[T]): any;
/**
* @template {keyof WebsocketEvent} T
* @param {T} eventName
* @param {WebsocketEvent[T]} listener
*/
once<T extends keyof WebsocketEvent>(eventName: T, listener: WebsocketEvent[T]): any;
[kEnded]: boolean;
}
export class WebSocketStream extends Duplex<any, any, any, any, true, true, import("streamx").DuplexEvents<any, any>> {
Expand Down Expand Up @@ -114,7 +105,10 @@ export class WebSocketStream extends Duplex<any, any, any, any, true, true, impo
_close(cb: any): void;
_write(packet: any, cb: any): void;
}
export class WebSocketServer {
/**
* @extends {EventEmitter<keyof WebsocketServerEvent, WebsocketServerEvent[keyof WebsocketServerEvent]>}
*/
export class WebSocketServer extends EventEmitter<keyof WebsocketServerEvent, ((ws: UWSocket) => void) | ((ws: UWSocket, code: number, message: ArrayBuffer) => void) | ((ws: UWSocket) => void) | ((ws: UWSocket, message: ArrayBuffer, isBinary: boolean) => void) | ((ws: UWSocket, message: ArrayBuffer) => void) | ((ws: UWSocket, message: ArrayBuffer) => void)> {
/**
* @param {WSOptions} options
*/
Expand All @@ -133,18 +127,6 @@ export class WebSocketServer {
* @param {import('./server.js').Server} server
*/
addServer(server: import("./server.js").Server): void;
/**
* @template {keyof WebsocketServerEvent} T
* @param {T} eventName
* @param {WebsocketServerEvent[T]} listener
*/
on<T extends keyof WebsocketServerEvent>(eventName: T, listener: WebsocketServerEvent[T]): any;
/**
* @template {keyof WebsocketServerEvent} T
* @param {T} eventName
* @param {WebsocketServerEvent[T]} listener
*/
once<T extends keyof WebsocketServerEvent>(eventName: T, listener: WebsocketServerEvent[T]): any;
}
export type UWebSocket<T> = import("uWebSockets.js").WebSocket<T>;
export type TemplatedApp = import("uWebSockets.js").TemplatedApp;
Expand Down Expand Up @@ -181,6 +163,7 @@ export type WebsocketServerEvent = {
ping: (ws: UWSocket, message: ArrayBuffer) => void;
pong: (ws: UWSocket, message: ArrayBuffer) => void;
};
import { EventEmitter } from 'eventemitter3';
import { kEnded } from './symbols.js';
import { Duplex } from 'streamx';
import { Request } from './request.js';

0 comments on commit 6aa5dc6

Please sign in to comment.