From b3083c9d2ca4c3aa2d4b828ec697096fb7411226 Mon Sep 17 00:00:00 2001 From: Fedor Kirpichev Date: Wed, 4 Oct 2017 21:16:16 +0300 Subject: [PATCH] Updated package name for newer versions of Atmosphere package (#20100) * Updated package name for newer versions of Atmosphere * Fixed header * Created new folder for atmosphere typings and placed deprecation comments. * Fixed tests name * Fixed name in tsconfig --- types/atmosphere.js/atmosphere.js-tests.ts | 46 +++++++++ types/atmosphere.js/index.d.ts | 110 +++++++++++++++++++++ types/atmosphere.js/tsconfig.json | 23 +++++ types/atmosphere/index.d.ts | 5 +- 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 types/atmosphere.js/atmosphere.js-tests.ts create mode 100644 types/atmosphere.js/index.d.ts create mode 100644 types/atmosphere.js/tsconfig.json diff --git a/types/atmosphere.js/atmosphere.js-tests.ts b/types/atmosphere.js/atmosphere.js-tests.ts new file mode 100644 index 0000000000..b353c2c947 --- /dev/null +++ b/types/atmosphere.js/atmosphere.js-tests.ts @@ -0,0 +1,46 @@ + + +var socket = atmosphere; + +var request1:Atmosphere.Request = new atmosphere.AtmosphereRequest(); + +request1.url = document.location.toString() + 'chat'; +request1.contentType = "application/json"; +request1.transport = 'websocket'; +request1.fallbackTransport = 'long-polling'; + +var request2:Atmosphere.Request = { + url: 'http://localhost:8080/chat', + contentType: "application/json", + logLevel: 'debug', + transport: 'websocket', + fallbackTransport: 'long-polling' +}; + +request1.onError = function (response?:Atmosphere.Response) {}; +request1.onClose = function (response?:Atmosphere.Response) {}; +request1.onOpen = function (response?:Atmosphere.Response) {}; +request1.onMessage = function (response:Atmosphere.Response) {}; +request1.onReopen = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {}; +request1.onReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {}; +request1.onMessagePublished = function (response?:Atmosphere.Response) {}; +request1.onTransportFailure = function (reason?:string, response?:Atmosphere.Response) {}; +request1.onLocalMessage = function (request?:Atmosphere.Request) {}; +request1.onFailureToReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {}; +request1.onClientTimeout = function (request?:Atmosphere.Request) {}; + +request1.subscribe = function (options:Atmosphere.Request) {}; +request1.execute = function () {}; +request1.close = function () {}; +request1.disconnect = function () {}; +request1.getUrl = function ():string { return "http://www.toedter.com" }; +request1.push = function (message:string, dispatchUrl?:string) {}; +request1.getUUID = function () {}; +request1.pushLocal = function (message:string) {}; + +var subSocket:Atmosphere.Request = socket.subscribe(request1); +var subSocket2:Atmosphere.Request = socket.subscribe('http://chat.com', function() {}, request2); +subSocket2.close(); + +subSocket.push("test"); +socket.unsubscribe(); \ No newline at end of file diff --git a/types/atmosphere.js/index.d.ts b/types/atmosphere.js/index.d.ts new file mode 100644 index 0000000000..0c0bfa3c3a --- /dev/null +++ b/types/atmosphere.js/index.d.ts @@ -0,0 +1,110 @@ +// Type definitions for Atmosphere v2.1.5 +// Project: https://github.com/Atmosphere/atmosphere-javascript +// Definitions by: Kai Toedter +// Fedor Kirpichev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Use this typings in future instead of deprecated 'atmosphere'. + +declare namespace Atmosphere { + interface Atmosphere { + /** + * The atmosphere API is a little bit special here: the first parameter can either be + * a URL string or a Request object. If it is a URL string, then the additional parameters are expected. + */ + subscribe?: (requestOrUrl:any, callback?:Function, request?:Request) => Request; + unsubscribe?: () => void; + + AtmosphereRequest?: AtmosphereRequest; + } + + // needed to fit JavaScript "new atmosphere.AtmosphereRequest()" + // and compile with --noImplicitAny + interface AtmosphereRequest { + new(): Request; + } + + interface Request { + timeout?: number; + method?: string; + headers?: any; + contentType?: string; + callback?: Function; + url?: string; + data?: string; + suspend?: boolean; + maxRequest?: number; + reconnect?: boolean; + maxStreamingLength?: number; + lastIndex?: number; + logLevel?: string; + requestCount?: number; + fallbackMethod?: string; + fallbackTransport?: string; + transport?: string; + webSocketImpl?: any; + webSocketBinaryType?: any; + dispatchUrl?: string; + webSocketPathDelimiter?: string; + enableXDR?: boolean; + rewriteURL?: boolean; + attachHeadersAsQueryString?: boolean; + executeCallbackBeforeReconnect?: boolean; + readyState?: number; + lastTimestamp?: number; + withCredentials?: boolean; + trackMessageLength?: boolean; + messageDelimiter?: string; + connectTimeout?: number; + reconnectInterval?: number; + dropHeaders?: boolean; + uuid?: string; + async?: boolean; + shared?: boolean; + readResponsesHeaders?: boolean; + maxReconnectOnClose?: number; + enableProtocol?: boolean; + pollingInterval?: number; + + onError?: (response?:Response) => void; + onClose?: (response?:Response) => void; + onOpen?: (response?:Response) => void; + onMessage?: (response:Response) => void; + onReopen?: (request?:Request, response?:Response) => void; + onReconnect?: (request?:Request, response?:Response) => void; + onMessagePublished?: (response?:Response) => void; + onTransportFailure?: (reason?:string, response?:Response) => void; + onLocalMessage?: (request?:Request) => void; + onFailureToReconnect?: (request?:Request, response?:Response) => void; + onClientTimeout?: (request?:Request) => void; + + subscribe?: (options:Request) => void; + execute?: () => void; + close?: () => void; + disconnect?: () => void; + getUrl?: () => string; + push?: (message:string, dispatchUrl?:string) => void; + getUUID?: () => void; + pushLocal?: (message:string) => void; + } + + interface Response { + status?: number; + reasonPhrase?: string; + responseBody?: string; + messages?: string[]; + headers?: string[]; + state?: string; + transport?: string; + error?: string; + request?: Request; + partialMessage?: string; + errorHandled?: boolean; + closedByClientTimeout?: boolean; + } +} + +declare var atmosphere:Atmosphere.Atmosphere; +declare module 'atmosphere.js' { + export = atmosphere; +} diff --git a/types/atmosphere.js/tsconfig.json b/types/atmosphere.js/tsconfig.json new file mode 100644 index 0000000000..8c2e633212 --- /dev/null +++ b/types/atmosphere.js/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "atmosphere.js-tests.ts" + ] +} \ No newline at end of file diff --git a/types/atmosphere/index.d.ts b/types/atmosphere/index.d.ts index 5e88c2c8fb..7b5565cb1d 100644 --- a/types/atmosphere/index.d.ts +++ b/types/atmosphere/index.d.ts @@ -1,8 +1,11 @@ // Type definitions for Atmosphere v2.1.5 // Project: https://github.com/Atmosphere/atmosphere-javascript -// Definitions by: Kai Toedter +// Definitions by: Kai Toedter +// Fedor Kirpichev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// This is deprecated due to module name change. Please use 'atmosphere.js' for future development.. + declare namespace Atmosphere { interface Atmosphere { /**