Skip to content

Commit 1c747ad

Browse files
robhoganfacebook-github-bot
authored andcommitted
Flow types for Node createServer APIs (#55462)
Summary: Node.js `createServer` options for the `net`, `tls`, `http` and `https` modules are currently unclearly typed as just `Object`. This adds full typing for all options as of Node.js 24. Changelog: [Internal] Differential Revision: D92393810
1 parent 7e7f491 commit 1c747ad

File tree

1 file changed

+104
-9
lines changed

1 file changed

+104
-9
lines changed

flow-typed/environment/node.js

Lines changed: 104 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,25 @@ type http$requestOptions = {
27162716
...
27172717
};
27182718

2719+
type http$createServerOptions = Readonly<{
2720+
...net$createServerOptions,
2721+
connectionsCheckingInterval?: number,
2722+
headersTimeout?: number,
2723+
insecureHTTPParser?: boolean,
2724+
IncomingMessage?: Class<http$IncomingMessage<net$Socket>>,
2725+
joinDuplicateHeaders?: boolean,
2726+
keepAliveTimeout?: number,
2727+
maxHeaderSize?: number,
2728+
requestTimeout?: number,
2729+
requireHostHeader?: boolean,
2730+
rejectNonStandardBodyWrites?: boolean,
2731+
ServerResponse?: Class<http$ServerResponse>,
2732+
uniqueHeaders?: ReadonlyArray<string | ReadonlyArray<string>>,
2733+
}>;
2734+
27192735
declare module 'http' {
2736+
export type ServerOptions = http$createServerOptions;
2737+
27202738
declare class Server extends http$Server {}
27212739
declare class Agent extends http$Agent<net$Socket> {
27222740
createConnection(
@@ -2728,6 +2746,13 @@ declare module 'http' {
27282746
declare class IncomingMessage extends http$IncomingMessage<net$Socket> {}
27292747
declare class ServerResponse extends http$ServerResponse {}
27302748

2749+
declare function createServer(
2750+
options: http$createServerOptions,
2751+
requestListener?: (
2752+
request: IncomingMessage,
2753+
response: ServerResponse,
2754+
) => void,
2755+
): Server;
27312756
declare function createServer(
27322757
requestListener?: (
27332758
request: IncomingMessage,
@@ -2758,6 +2783,11 @@ declare module 'http' {
27582783
declare var globalAgent: Agent;
27592784
}
27602785

2786+
type https$createServerOptions = Readonly<{
2787+
...http$createServerOptions,
2788+
...tls$createServerOptions,
2789+
}>;
2790+
27612791
type https$requestOptions = {
27622792
...requestOptions,
27632793
agent?: boolean | http$Agent<tls$TLSSocket>,
@@ -2769,6 +2799,8 @@ type https$requestOptions = {
27692799
};
27702800

27712801
declare module 'https' {
2802+
export type ServerOptions = https$createServerOptions;
2803+
27722804
declare class Server extends https$Server {}
27732805
declare class Agent extends http$Agent<tls$TLSSocket> {
27742806
createConnection(
@@ -2785,7 +2817,7 @@ declare module 'https' {
27852817
declare class ServerResponse extends http$ServerResponse {}
27862818

27872819
declare function createServer(
2788-
options: Object,
2820+
options: https$createServerOptions,
27892821
requestListener?: (
27902822
request: IncomingMessage,
27912823
response: ServerResponse,
@@ -2903,7 +2935,18 @@ type net$connectOptions = {
29032935
...
29042936
};
29052937

2938+
type net$createServerOptions = Readonly<{
2939+
allowHalfOpen?: boolean,
2940+
highWaterMark?: number,
2941+
keepAlive?: boolean,
2942+
keepAliveInitialDelay?: number,
2943+
noDelay?: boolean,
2944+
pauseOnConnect?: boolean,
2945+
}>;
2946+
29062947
declare module 'net' {
2948+
export type ServerOptions = net$createServerOptions;
2949+
29072950
declare class Server extends net$Server {}
29082951
declare class Socket extends net$Socket {}
29092952

@@ -2913,13 +2956,10 @@ declare module 'net' {
29132956

29142957
declare type connectionListener = (socket: Socket) => any;
29152958
declare function createServer(
2916-
options?:
2917-
| {
2918-
allowHalfOpen?: boolean,
2919-
pauseOnConnect?: boolean,
2920-
...
2921-
}
2922-
| connectionListener,
2959+
options: net$createServerOptions,
2960+
connectionListener?: connectionListener,
2961+
): Server;
2962+
declare function createServer(
29232963
connectionListener?: connectionListener,
29242964
): Server;
29252965

@@ -3947,6 +3987,56 @@ type tls$connectOptions = {
39473987
...
39483988
};
39493989

3990+
type tls$createServerOptions = Readonly<{
3991+
ALPNProtocols?: ReadonlyArray<string> | Uint8Array,
3992+
ca?: string | Buffer | ReadonlyArray<string | Buffer>,
3993+
cert?: string | Buffer | ReadonlyArray<string | Buffer>,
3994+
ciphers?: string,
3995+
clientCertEngine?: string,
3996+
crl?: string | Buffer | ReadonlyArray<string | Buffer>,
3997+
dhparam?: string | Buffer,
3998+
ecdhCurve?: string,
3999+
enableTrace?: boolean,
4000+
handshakeTimeout?: number,
4001+
honorCipherOrder?: boolean,
4002+
key?:
4003+
| string
4004+
| Buffer
4005+
| ReadonlyArray<
4006+
| string
4007+
| Buffer
4008+
| Readonly<{pem: string | Buffer, passphrase?: string, ...}>,
4009+
>,
4010+
maxVersion?: 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1',
4011+
minVersion?: 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1',
4012+
passphrase?: string,
4013+
pfx?:
4014+
| string
4015+
| Buffer
4016+
| ReadonlyArray<
4017+
| string
4018+
| Buffer
4019+
| Readonly<{buf: string | Buffer, passphrase?: string, ...}>,
4020+
>,
4021+
privateKeyIdentifier?: string,
4022+
privateKeyEngine?: string,
4023+
pskCallback?: (socket: tls$TLSSocket, identity: string) => Buffer | null,
4024+
pskIdentityHint?: string,
4025+
rejectUnauthorized?: boolean,
4026+
requestCert?: boolean,
4027+
secureContext?: Object,
4028+
secureOptions?: number,
4029+
secureProtocol?: string,
4030+
sessionIdContext?: string,
4031+
sessionTimeout?: number,
4032+
sigalgs?: string,
4033+
SNICallback?: (
4034+
servername: string,
4035+
callback: (err: Error | null, ctx?: Object) => void,
4036+
) => void,
4037+
ticketKeys?: Buffer,
4038+
}>;
4039+
39504040
type tls$Certificate$Subject = {
39514041
C?: string,
39524042
ST?: string,
@@ -4019,6 +4109,8 @@ declare class tls$Server extends net$Server {
40194109
}
40204110

40214111
declare module 'tls' {
4112+
export type ServerOptions = tls$createServerOptions;
4113+
40224114
declare var CLIENT_RENEG_LIMIT: number;
40234115
declare var CLIENT_RENEG_WINDOW: number;
40244116
declare var SLAB_BUFFER_SIZE: number;
@@ -4039,7 +4131,10 @@ declare module 'tls' {
40394131
declare var TLSSocket: typeof tls$TLSSocket;
40404132
declare var Server: typeof tls$Server;
40414133
declare function createServer(
4042-
options: Object,
4134+
options: tls$createServerOptions,
4135+
secureConnectionListener?: Function,
4136+
): tls$Server;
4137+
declare function createServer(
40434138
secureConnectionListener?: Function,
40444139
): tls$Server;
40454140
declare function connect(

0 commit comments

Comments
 (0)