From 40d73b536fe3b7c0625d9d7daa56a3cdc2b9846c Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Fri, 16 Jun 2017 00:52:15 -0300 Subject: [PATCH] [sockjs] Delete sockjs, rename sockjs-node to sockjs, add tslint.json @types/sockjs-node was impossible to use since the actual name of the package it's meant for on npm is sockjs, not sockjs-node. @types/sockjs already existed, however it was the type declaration file for an old version of sockjs-client, which already has its own up-to-date type declaration file under @types/sockjs-client. Fixes #17112 --- types/sockjs-node/index.d.ts | 56 ----------- types/sockjs-node/tsconfig.json | 22 ----- types/sockjs/index.d.ts | 94 +++++++++---------- .../sockjs-tests.ts} | 20 ++-- types/sockjs/tsconfig.json | 8 +- types/sockjs/tslint.json | 6 ++ 6 files changed, 65 insertions(+), 141 deletions(-) delete mode 100644 types/sockjs-node/index.d.ts delete mode 100644 types/sockjs-node/tsconfig.json rename types/{sockjs-node/sockjs-node-tests.ts => sockjs/sockjs-tests.ts} (64%) create mode 100644 types/sockjs/tslint.json diff --git a/types/sockjs-node/index.d.ts b/types/sockjs-node/index.d.ts deleted file mode 100644 index 1de35afd2a..0000000000 --- a/types/sockjs-node/index.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Type definitions for sockjs-node 0.3.x -// Project: https://github.com/sockjs/sockjs-node -// Definitions by: Phil McCloghry-Laing -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - - -import http = require('http'); - -export interface ServerOptions { - sockjs_url?: string; - prefix?: string; - response_limit?: number; - websocket?: boolean; - jsessionid?: any; - log?: (severity: string, message: string) => void; - heartbeat_delay?: number; - disconnect_delay?: number; -} - -export declare function createServer(options?: ServerOptions): Server; - -export interface Server extends NodeJS.EventEmitter { - installHandlers(server: http.Server, options?: ServerOptions): any; - - on(event: 'connection', listener: (conn: Connection) => any): this; - on(event: string, listener: Function): this; -} - -export interface Connection extends NodeJS.ReadWriteStream { - remoteAddress: string; - remotePort: number; - address: { - [key: string]: { - address: string; - port: number; - }; - }; - headers: { - [key: string]: string; - }; - url: string; - pathname: string; - prefix: string; - protocol: string; - readyState: number; - id: string; - - close(code?: string, reason?: string): boolean; - destroy(): void; - - on(event: 'data', listener: (message: string) => any): this; - on(event: 'close', listener: () => void): this; - on(event: string, listener: Function): this; -} diff --git a/types/sockjs-node/tsconfig.json b/types/sockjs-node/tsconfig.json deleted file mode 100644 index 9f87470aa5..0000000000 --- a/types/sockjs-node/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "sockjs-node-tests.ts" - ] -} \ No newline at end of file diff --git a/types/sockjs/index.d.ts b/types/sockjs/index.d.ts index e613db9f7d..50cd7fe05f 100644 --- a/types/sockjs/index.d.ts +++ b/types/sockjs/index.d.ts @@ -1,59 +1,55 @@ -// Type definitions for SockJS 0.3.x -// Project: https://github.com/sockjs/sockjs-client -// Definitions by: Emil Ivanov +// Type definitions for sockjs 0.3 +// Project: https://github.com/sockjs/sockjs-node +// Definitions by: Phil McCloghry-Laing // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export as namespace SockJS; -export = SockJS; +/// -interface SockJSSimpleEvent { - type: string; - toString(): string; +import http = require('http'); + +export interface ServerOptions { + sockjs_url?: string; + prefix?: string; + response_limit?: number; + websocket?: boolean; + jsessionid?: any; + log?(severity: string, message: string): void; + heartbeat_delay?: number; + disconnect_delay?: number; } -interface SJSOpenEvent extends SockJSSimpleEvent, Event { - type: string; +export function createServer(options?: ServerOptions): Server; + +export interface Server extends NodeJS.EventEmitter { + installHandlers(server: http.Server, options?: ServerOptions): any; + + on(event: 'connection', listener: (conn: Connection) => any): this; + on(event: string, listener: Function): this; } -interface SJSCloseEvent extends SockJSSimpleEvent, CloseEvent { - code: number; - reason: string; - wasClean: boolean; - type: string; -} +export interface Connection extends NodeJS.ReadWriteStream { + remoteAddress: string; + remotePort: number; + address: { + [key: string]: { + address: string; + port: number; + }; + }; + headers: { + [key: string]: string; + }; + url: string; + pathname: string; + prefix: string; + protocol: string; + readyState: number; + id: string; -interface SJSMessageEvent extends SockJSSimpleEvent, MessageEvent { - data: string; - type: string; -} + close(code?: string, reason?: string): boolean; + destroy(): void; -interface SockJS extends WebSocket { - protocol: string; - readyState: number; - onopen: (ev: SJSOpenEvent) => any; - onmessage: (ev: SJSMessageEvent) => any; - onclose: (ev: SJSCloseEvent) => any; - send(data: any): void; - close(code?: number, reason?: string): void; - OPEN: number; - CLOSING: number; - CONNECTING: number; - CLOSED: number; + on(event: 'data', listener: (message: string) => any): this; + on(event: 'close', listener: () => void): this; + on(event: string, listener: Function): this; } - -declare var SockJS: { - prototype: SockJS; - new (url: string, _reserved?: any, options?: { - debug?: boolean; - devel?: boolean; - protocols_whitelist?: string[]; - server?: string; - rtt?: number; - rto?: number; - info?: { - websocket?: boolean; - cookie_needed?: boolean; - null_origin?: boolean; - }; - }): SockJS; -}; \ No newline at end of file diff --git a/types/sockjs-node/sockjs-node-tests.ts b/types/sockjs/sockjs-tests.ts similarity index 64% rename from types/sockjs-node/sockjs-node-tests.ts rename to types/sockjs/sockjs-tests.ts index ca80b26e64..8da2d78afe 100644 --- a/types/sockjs-node/sockjs-node-tests.ts +++ b/types/sockjs/sockjs-tests.ts @@ -1,16 +1,16 @@ -import sockjs = require("sockjs-node"); -import http = require("http"); -import stream = require("stream"); +import * as sockjs from 'sockjs'; +import * as http from 'http'; +import * as stream from 'stream'; -var server: sockjs.Server, - serverOptions: sockjs.ServerOptions = {}; +let server: sockjs.Server; +let serverOptions: sockjs.ServerOptions = {}; // createServer method server = sockjs.createServer(); server = sockjs.createServer(serverOptions); // installHandlers method -var httpServer: http.Server = http.createServer(); +let httpServer: http.Server = http.createServer(); server.installHandlers(httpServer); server.installHandlers(httpServer, serverOptions); @@ -23,21 +23,21 @@ serverOptions.websocket = true; serverOptions.jsessionid = true; serverOptions.jsessionid = () => true; -serverOptions.log = (severity: any, message: any) => { }; +serverOptions.log = (severity: string, message: string) => { }; serverOptions.heartbeat_delay = 25000; serverOptions.disconnect_delay = 5000; // Connection -var connection: sockjs.Connection; +let connection: sockjs.Connection; // on('connection') passes a sockJS connection -server.on('connection', (conn: any) => { +server.on('connection', (conn: sockjs.Connection) => { connection = conn; conn = connection; }); // connection is a ReadWriteStream -var connectionAsReadWrite: NodeJS.ReadWriteStream = connection; +let connectionAsReadWrite: NodeJS.ReadWriteStream = connection; connection.on('data', (message: string) => { }); connection.on('close', () => { }); diff --git a/types/sockjs/tsconfig.json b/types/sockjs/tsconfig.json index 8a67eaf271..7381df8ce9 100644 --- a/types/sockjs/tsconfig.json +++ b/types/sockjs/tsconfig.json @@ -2,8 +2,7 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6", - "dom" + "es6" ], "noImplicitAny": true, "noImplicitThis": true, @@ -17,6 +16,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "sockjs-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/sockjs/tslint.json b/types/sockjs/tslint.json new file mode 100644 index 0000000000..5bc412fb1e --- /dev/null +++ b/types/sockjs/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "ban-types": false + } +}