From b7fda303fb276e3a5c8cd4709651beedf5cd46ce Mon Sep 17 00:00:00 2001 From: "T. Michael Keesey" Date: Mon, 3 Mar 2014 23:55:10 -0800 Subject: [PATCH] PhantomJS: Made compliant with --noImplicitAny and added more details to many of the declarations. --- phantomjs/phantomjs.d.ts | 243 +++++++++++++++++++++++---------------- 1 file changed, 143 insertions(+), 100 deletions(-) diff --git a/phantomjs/phantomjs.d.ts b/phantomjs/phantomjs.d.ts index b85e356a96..21b3b0fe43 100644 --- a/phantomjs/phantomjs.d.ts +++ b/phantomjs/phantomjs.d.ts @@ -1,6 +1,6 @@ // Type definitions for PlantomJS v1.8.0 API // Project: https://github.com/ariya/phantomjs/wiki/API-Reference -// Definitions by: Jed Hunsaker +// Definitions by: Jed Hunsaker and Mike Keesey // Definitions: https://github.com/borisyankov/DefinitelyTyped interface Phantom { @@ -11,33 +11,35 @@ interface Phantom { cookiesEnabled: boolean; libraryPath: string; scriptName: string; // DEPRECATED - version: any; + version: { + major: number; + minor: number; + patch: number; + }; // Functions addCookie(cookie: Cookie): boolean; - clearCookies(); + clearCookies(): void; deleteCookie(cookieName: string): boolean; - exit(returnValue: any): boolean; + exit(returnValue?: any): boolean; injectJs(filename: string): boolean; // Callbacks - onError: Function; + onError: (msg: string, trace: string[]) => any; } interface System { pid: number; platform: string; - os: OS; - env: any; + os: { + architecture: string; + name: string; + version: string; + }; + env: { [name: string]: string; }; args: string[]; } -interface OS { - architecture: string; - name: string; - version: string; -} - interface WebPage { // Properties @@ -46,8 +48,8 @@ interface WebPage { clipRect: ClipRect; content: string; cookies: Cookie[]; - customHeaders: any; - event; + customHeaders: { [name: string]: string; }; + event: any; // :TODO: elaborate this when documentation improves focusedFrameName: string; frameContent: string; frameName: string; @@ -55,13 +57,13 @@ interface WebPage { frameTitle: string; frameUrl: string; framesCount: number; - framesName; + framesName: any; // :TODO: elaborate this when documentation improves libraryPath: string; navigationLocked: boolean; offlineStoragePath: string; offlineStorageQuota: number; ownsPages: boolean; - pages; + pages: WebPage[]; pagesWindowName: string; paperSize: PaperSize; plainText: string; @@ -77,76 +79,113 @@ interface WebPage { addCookie(cookie: Cookie): boolean; childFramesCount(): number; // DEPRECATED childFramesName(): string; // DEPRECATED - clearCookies(); - close(); + clearCookies(): void; + close(): void; currentFrameName(): string; // DEPRECATED deleteCookie(cookieName: string): boolean; evaluate(fn: Function, ...args: any[]): any; - evaluateAsync(fn: Function); - evaluateJavascript(str: string); - getPage(windowName: string); - go(index: number); - goBack(); - goForward(); - includeJs(url: string, callback: Function); + evaluateAsync(fn: Function): void; + evaluateJavascript(str: string): any; // :TODO: elaborate this when documentation improves + getPage(windowName: string): WebPage; + go(index: number): void; + goBack(): void; + goForward(): void; + includeJs(url: string, callback: Function): void; injectJs(filename: string): boolean; - open(url: string, callback: (status: string) => void); - openUrl(url: string, httpConf: any, settings: any); - release(); // DEPRECATED - reload(); - render(filename: string); - renderBase64(format: any): string; + open(url: string, callback: (status: string) => any): void; + open(url: string, method: string, callback: (status: string) => any): void; + open(url: string, method: string, data: any, callback: (status: string) => any): void; + openUrl(url: string, httpConf: any, settings: any): void; // :TODO: elaborate this when documentation improves + release(): void; // DEPRECATED + reload(): void; + render(filename: string): void; + renderBase64(format: string): string; sendEvent(mouseEventType: string, mouseX?: number, mouseY?: number, button?: string); - sendEvent(keyboardEventType: string, keyOrKeys, aNull?, bNull?, modifier?); - setContent(content: string, url: string); - stop(); - switchToFocusedFrame(); - switchToFrame(frameName: string); - switchToFrame(framePosition); - switchToChildFrame(frameName: string); - switchToChildFrame(framePosition); - switchToMainFrame(); // DEPRECATED - switchToParentFrame(); // DEPRECATED - uploadFile(selector: string, filename: string); + sendEvent(keyboardEventType: string, keyOrKeys: any, aNull?: any, bNull?: any, modifier?: number); + setContent(content: string, url: string): void; + stop(): void; + switchToFocusedFrame(): void; + switchToFrame(frameName: string): void; + switchToFrame(framePosition: number): void; + switchToChildFrame(frameName: string): void; + switchToChildFrame(framePosition: number): void; + switchToMainFrame(): void; // DEPRECATED + switchToParentFrame(): void; // DEPRECATED + uploadFile(selector: string, filename: string): void; // Callbacks - onAlert: Function; + onAlert: (msg: string) => any; onCallback: Function; // EXPERIMENTAL - onClosing: Function; - onConfirm: Function; - onConsoleMessage: Function; - onError: Function; - onFilePicker: Function; - onInitialized: Function; - onLoadFinished: Function; - onLoadStarted: Function; - onNavigationRequested: Function; - onPageCreated: Function; - onPrompt: Function; - onResourceRequested: Function; - onResourceReceived: Function; - onUrlChanged: Function; + onClosing: (closingPage: WebPage) => any; + onConfirm: (msg: string) => boolean; + onConsoleMessage: (msg: string, lineNum?: number, sourceId?: string) => any; + onError: (msg: string, trace: string[]) => any; + onFilePicker: (oldFile: string) => string; + onInitialized: () => any; + onLoadFinished: (status: string) => any; + onLoadStarted: () => any; + onNavigationRequested: (url: string, type: string, willNavigate: boolean, main: boolean) => any; + onPageCreated: (newPage: WebPage) => any; + onPrompt: (msg: string, defaultVal: string) => string; + onResourceError: (resourceError: ResourceError) => any; + onResourceReceived: (response: ResourceResponse) => any; + onResourceRequested: (requestData: ResourceRequest, networkRequest: NetworkRequest) => any; + onUrlChanged: (targetUrl: string) => any; // Callback triggers - closing(page); - initialized(); - javaScriptAlertSent(message: string); - javaScriptConsoleMessageSent(message: string); - loadFinished(status); - loadStarted(); - navigationRequested(url: string, navigationType, navigationLocked, isMainFrame: boolean); - rawPageCreated(page); - resourceReceived(request); - resourceRequested(resource); - urlChanged(url: string); + closing(closingPage: WebPage): void; + initialized(): void; + javaScriptAlertSent(msg: string): void; + javaScriptConsoleMessageSent(msg: string, lineNum?: number, sourceId?: string): void; + loadFinished(status: string): void; + loadStarted(): void; + navigationRequested(url: string, type: string, willNavigate: boolean, main: boolean): void; + rawPageCreated(newPage: WebPage): void; + resourceReceived(response: ResourceResponse): void; + resourceRequested(requestData: ResourceRequest, networkRequest: NetworkRequest): void; + urlChanged(targetUrl: string); +} + +interface ResourceError { + id: number; + url: string; + errorCode: string; + errorString: string; +} + +interface ResourceResponse { + id: number; + url: string; + time: Date; + headers: { [name: string]: string; }; + bodySize: number; + contentType?: string; + redirectURL?: string; + stage: string; + status: number; + statusText: string; +} + +interface ResourceRequest { + id: number; + method: string; + ur: string; + time: Date; + headers: { [name: string]: string; }; +} + +interface NetworkRequest { + abort(): void; + changeUrl(url: string): void; + setHeader(name: string, value: string); } interface PaperSize { - width: string; - height: string; + width?: string; + height?: string; border: string; - format: string; - orientation: string; + format?: string; + orientation?: string; } interface WebPageSettings { @@ -154,9 +193,11 @@ interface WebPageSettings { loadImages: boolean; localToRemoteUrlAccessEnabled: boolean; userAgent: string; + userName: string; password: string; XSSAuditingEnabled: boolean; webSecurityEnabled: boolean; + resourceTimeout: number; } interface FileSystem { @@ -181,59 +222,62 @@ interface FileSystem { readLink(path: string): string; // Directory Functions - changeWorkingDirectory(path: string); - makeDirectory(path: string); - makeTree(path: string); - removeDirectory(path: string); - removeTree(path: string); - copyTree(source: string, destination: string); + changeWorkingDirectory(path: string): void; + makeDirectory(path: string): void; + makeTree(path: string): void; + removeDirectory(path: string): void; + removeTree(path: string): void; + copyTree(source: string, destination: string): void; // File Functions open(path: string, mode: string): Stream; + open(path: string, options: { mode: string; charset?: string; }): Stream; read(path: string): string; - write(path: string, content: string, mode: string); + write(path: string, content: string, mode: string): void; size(path: string): number; - remove(path: string); - copy(source: string, destination: string); - move(source: string, destination: string); - touch(path: string); + remove(path: string): void; + copy(source: string, destination: string): void; + move(source: string, destination: string): void; + touch(path: string): void; } interface Stream { + atEnd(): boolean; + close(): void; + flush(): void; read(): string; readLine(): string; - write(data: string); - writeLine(data: string); - flush(); - close(); + seek(position: number): void; + write(data: string): void; + writeLine(data: string): void; } interface WebServer { port: number; - listen(port: number, cb?:(request, response) => void): boolean; - listen(ipAddressPort: string, cb?:(request, response) => void): boolean; - close(); + listen(port: number, cb?: (request: WebServerRequest, response: WebServerResponse) => void): boolean; + listen(ipAddressPort: string, cb?: (request: WebServerRequest, response: WebServerResponse) => void): boolean; + close(): void; } -interface Request { +interface WebServerRequest { method: string; url: string; httpVersion: number; - headers: any; + headers: { [name: string]: string; }; post: string; postRaw: string; } -interface Response { - headers: any; +interface WebServerResponse { + headers: { [name: string]: string; }; setHeader(name: string, value: string); header(name: string): string; statusCode: number; setEncoding(encoding: string); write(data: string); - writeHead(statusCode: number, headers?: any); - close(); - closeGracefully(); + writeHead(statusCode: number, headers?: { [name: string]: string; }); + close(): void; + closeGracefully(): void; } interface TopLeft { @@ -247,11 +291,10 @@ interface Size { } interface ClipRect extends TopLeft, Size { - width: number; - height: number; } interface Cookie { name: string; value: string; + domain?: string; }