refactor: tsify net module (#23618)

This commit is contained in:
Jeremy Apthorp 2020-05-18 10:22:48 -07:00 committed by GitHub
parent 8879a3db58
commit 7e841ceb5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 54 deletions

View file

@ -45,6 +45,49 @@ declare namespace NodeJS {
getWeaklyTrackedValues(): any[];
}
type DataPipe = {
write: (buf: Uint8Array) => Promise<void>;
done: () => void;
};
type BodyFunc = (pipe: DataPipe) => void;
type CreateURLLoaderOptions = {
method: string;
url: string;
extraHeaders?: Record<string, string>;
useSessionCookies?: boolean;
body: Uint8Array | BodyFunc;
session?: Electron.Session;
partition?: string;
}
type ResponseHead = {
statusCode: number;
statusMessage: string;
httpVersion: { major: number, minor: number };
rawHeaders: { key: string, value: string }[];
};
type RedirectInfo = {
statusCode: number;
newMethod: string;
newUrl: string;
newSiteForCookies: string;
newReferrer: string;
insecureSchemeWasUpgraded: boolean;
isSignedExchangeFallbackRedirect: boolean;
}
interface URLLoader extends EventEmitter {
cancel(): void;
on(eventName: 'data', listener: (event: any, data: ArrayBuffer) => void): this;
on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
on(eventName: 'complete', listener: (event: any) => void): this;
on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
}
interface Process {
/**
* DO NOT USE DIRECTLY, USE process.electronBinding
@ -57,6 +100,13 @@ declare namespace NodeJS {
electronBinding(name: 'app'): { app: Electron.App, App: Function };
electronBinding(name: 'command_line'): Electron.CommandLine;
electronBinding(name: 'desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer };
electronBinding(name: 'net'): {
isValidHeaderName: (headerName: string) => boolean;
isValidHeaderValue: (headerValue: string) => boolean;
Net: any;
net: any;
createURLLoader(options: CreateURLLoaderOptions): URLLoader;
};
log: NodeJS.WriteStream['write'];
activateUvLoop(): void;