Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Jul 13, 2024
1 parent fec908d commit 8ec7219
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 49 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
11 changes: 1 addition & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit",
"quickfix.biome": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
}
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
},
"dependencies": {
"fastify-plugin": "^4.5.1",
"fastq": "^1.13.0",
"ipaddr.js": "^2.0.1",
"fastq": "^1.17.1",
"ipaddr.js": "^2.2.0",
"nanoerror": "^2.0.0",
"streamx": "^2.18.0",
"tempy": "^1.0.1",
"tempy": "^3.1.0",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0"
},
"devDependencies": {
Expand All @@ -70,9 +70,9 @@
"@types/node": "^20.8.10",
"@types/streamx": "^2.9.3",
"eslint": "^8.57.0",
"eslint-config-standard-ext": "^0.0.25",
"eslint-config-standard-ext": "^0.0.27",
"execa": "^8.0.1",
"fastify": "file:tests/fastify/module",
"fastify": "^4.28.1",
"require-inject": "^1.4.4",
"simple-get": "^4.0.1",
"tap": "^16.3.0",
Expand Down
1 change: 0 additions & 1 deletion src/http-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const localAddressIpv6 = Buffer.from([

const toHex = (buf, start, end) => buf.slice(start, end).toString('hex')

// biome-ignore lint/suspicious/noEmptyBlockStatements: noop
const noop = () => {}

/**
Expand Down
1 change: 0 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { WebSocket, WebSocketServer } from './websocket-server.js'
* @param {WebSocket} conn
* @param {import('fastify').FastifyRequest} request
*/
// biome-ignore lint/correctness/noUnusedVariables: ignore
function defaultErrorHandler(err, conn, request) {
request.log.error(err)
request.raw.destroy(err)
Expand Down
3 changes: 1 addition & 2 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Readable } from 'streamx'

import { kHeaders, kReq, kUrl } from './symbols.js'

// biome-ignore lint/suspicious/noEmptyBlockStatements: noop
const noop = () => {}

function onAbort() {
Expand All @@ -11,7 +10,7 @@ function onAbort() {

export class Request extends Readable {
constructor(req, socket, method) {
super({ highWaterMark: 0 })
super()

this.socket = socket
this.method = method
Expand Down
1 change: 0 additions & 1 deletion src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function onAbort() {
this.emit('aborted')
}

// biome-ignore lint/suspicious/noEmptyBlockStatements: noop
const noop = () => {}

const options = {
Expand Down
9 changes: 4 additions & 5 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import EventEmitter from 'node:events'
import { writeFileSync } from 'node:fs'

import ipaddr from 'ipaddr.js'
import tempy from 'tempy'
import { temporaryFile } from 'tempy'
import uws from 'uWebSockets.js'

import {
ERR_ADDRINUSE,
ERR_ENOTFOUND,
ERR_SERVER_DESTROYED,
ERR_SOCKET_BAD_PORT,
ERR_UWS_APP_NOT_FOUND,
ERR_SERVER_DESTROYED,
} from './errors.js'
import { HTTPSocket } from './http-socket.js'
import { Request } from './request.js'
Expand All @@ -49,15 +49,14 @@ import {
kWs,
} from './symbols.js'

// biome-ignore lint/suspicious/noEmptyBlockStatements: noop
const noop = () => {}

function createApp(https) {
if (!https) return uws.App()
if (!https.key) return uws.SSLApp(https)
const keyFile = tempy.file()
const keyFile = temporaryFile()
writeFileSync(keyFile, https.key)
const certFile = tempy.file()
const certFile = temporaryFile()
writeFileSync(certFile, https.cert)
return uws.SSLApp({
key_file_name: keyFile,
Expand Down
2 changes: 1 addition & 1 deletion src/websocket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/**
* @typedef {{
* closeOnBackpressureLimit?: number;
* closeOnBackpressureLimit?: boolean;
* compression?: number;
* idleTimeout?: number;
* maxBackpressure?: number;
Expand Down
1 change: 1 addition & 0 deletions types/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const ERR_STREAM_DESTROYED: any;
export const ERR_UWS_APP_NOT_FOUND: any;
export const ERR_ENOTFOUND: any;
export const ERR_SOCKET_BAD_PORT: any;
export const ERR_SERVER_DESTROYED: any;
2 changes: 1 addition & 1 deletion types/fastify-overload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare module 'fastify' {
}

interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>,
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>,
websocketServer: WebSocketServer,
}

Expand Down
2 changes: 1 addition & 1 deletion types/http-socket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class HTTPSocket {
bytesWritten: number;
writableEnded: boolean;
errored: any;
get readyState(): "open" | "opening" | "readOnly" | "writeOnly";
get readyState(): "open" | "readOnly" | "writeOnly" | "opening";
get writable(): boolean;
get readable(): boolean;
get encrypted(): boolean;
Expand Down
9 changes: 4 additions & 5 deletions types/plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference types="node" />
declare const _default: typeof fastifyUws;
export default _default;
export type FastifyPluginCallback<T> = import('fastify').FastifyPluginCallback<T>;
export type WSOptions = import('./websocket-server.js').WSOptions;
export type Request = import('./request.js').Request;
export type FastifyPluginCallback<T> = import("fastify").FastifyPluginCallback<T>;
export type WSOptions = import("./websocket-server.js").WSOptions;
export type Request = import("./request.js").Request;
declare function fastifyUws(instance: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, opts: {
errorHandler?: typeof defaultErrorHandler;
} & import("./websocket-server.js").WSOptions, done: (err?: Error) => void): void;
Expand All @@ -13,6 +12,6 @@ declare function fastifyUws(instance: import("fastify").FastifyInstance<import("
* @param {WebSocket} conn
* @param {import('fastify').FastifyRequest} request
*/
declare function defaultErrorHandler(this: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, err: Error, conn: WebSocket, request: import('fastify').FastifyRequest): void;
declare function defaultErrorHandler(this: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, err: Error, conn: WebSocket, request: import("fastify").FastifyRequest): void;
import { WebSocket } from './websocket-server.js';
import "./fastify-overload.d.ts"
2 changes: 1 addition & 1 deletion types/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Request extends Readable<any, any, any, true, false, import("stream
httpVersion: string;
readableEnded: boolean;
get aborted(): any;
set url(arg: any);
set url(url: any);
get url(): any;
get headers(): any;
setEncoding(encoding: any): void;
Expand Down
25 changes: 18 additions & 7 deletions types/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class Server {
timeout: number;
/** @type {boolean} */
get encrypted(): boolean;
/** @type {boolean} */
get listening(): boolean;
/**
* @param {number} timeout
*/
Expand All @@ -20,13 +22,18 @@ export class Server {
};
/**
*
* @param {{ host: string, port: number }} listenOptions
* @param {() => void} cb
* @param {{
* host: string
* port: number
* signal: AbortSignal
* }} listenOptions
*/
listen(listenOptions: {
host: string;
port: number;
}, cb: () => void): void;
signal: AbortSignal;
}): void;
closeIdleConnections(): void;
/**
* @param {() => void} [cb]
*/
Expand All @@ -43,17 +50,19 @@ export class Server {
cert: string;
};
/** @type {import('./websocket-server.js').WebSocketServer} */
[kWs]: import('./websocket-server.js').WebSocketServer;
[kWs]: import("./websocket-server.js").WebSocketServer;
[kAddress]: any;
[kListenSocket]: any;
[kApp]: any;
[kClosed]: boolean;
[kListenAll]: boolean;
[kListening]: boolean;
}
/** @type {FastifyServerFactory} */
export const serverFactory: FastifyServerFactory;
export function getUws(fastify: import('fastify').FastifyInstance): TemplatedApp;
export function getUws(fastify: import("fastify").FastifyInstance): TemplatedApp;
export { WebSocketStream } from "./websocket-server.js";
export type TemplatedApp = import('uWebSockets.js').TemplatedApp;
export type TemplatedApp = import("uWebSockets.js").TemplatedApp;
export type SSLApp = typeof import("uWebSockets.js").SSLApp;
export type ServerOptions = {
connectionTimeout?: number;
Expand All @@ -62,7 +71,7 @@ export type ServerOptions = {
cert: string;
} | Parameters<SSLApp>[0];
};
export type FastifyServerFactory = import('fastify').FastifyServerFactory;
export type FastifyServerFactory = import("fastify").FastifyServerFactory;
import { kListen } from './symbols.js';
import { kHandler } from './symbols.js';
import { Request } from './request.js';
Expand All @@ -73,4 +82,6 @@ import { kAddress } from './symbols.js';
import { kListenSocket } from './symbols.js';
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";
2 changes: 2 additions & 0 deletions types/symbols.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ 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;
export const kListening: unique symbol;
16 changes: 8 additions & 8 deletions types/websocket-server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class WebSocket {
* @param {T} eventName
* @param {WebsocketEvent[T]} listener
*/
once<T_1 extends keyof WebsocketEvent>(eventName: T_1, listener: WebsocketEvent[T_1]): any;
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 @@ -123,7 +123,7 @@ export class WebSocketServer {
compression: any;
maxPayloadLength: number;
idleTimeout: number;
closeOnBackpressureLimit?: number;
closeOnBackpressureLimit?: boolean;
maxBackpressure?: number;
maxLifetime?: number;
sendPingsAutomatically?: boolean;
Expand All @@ -132,7 +132,7 @@ export class WebSocketServer {
/**
* @param {import('./server.js').Server} server
*/
addServer(server: import('./server.js').Server): void;
addServer(server: import("./server.js").Server): void;
/**
* @template {keyof WebsocketServerEvent} T
* @param {T} eventName
Expand All @@ -144,11 +144,11 @@ export class WebSocketServer {
* @param {T} eventName
* @param {WebsocketServerEvent[T]} listener
*/
once<T_1 extends keyof WebsocketServerEvent>(eventName: T_1, listener: WebsocketServerEvent[T_1]): any;
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;
export type RecognizedString = import('uWebSockets.js').RecognizedString;
export type UWebSocket<T> = import("uWebSockets.js").WebSocket<T>;
export type TemplatedApp = import("uWebSockets.js").TemplatedApp;
export type RecognizedString = import("uWebSockets.js").RecognizedString;
export type UserData = {
req: Request;
handler: (ws: UWebSocket<UserData>) => void;
Expand All @@ -158,7 +158,7 @@ export type UWSocket = UWebSocket<UserData> & {
websocket: WebSocket;
};
export type WSOptions = {
closeOnBackpressureLimit?: number;
closeOnBackpressureLimit?: boolean;
compression?: number;
idleTimeout?: number;
maxBackpressure?: number;
Expand Down

0 comments on commit 8ec7219

Please sign in to comment.