From 0fe09ccd9d5b7bd39b1056aa02533820ae458ceb Mon Sep 17 00:00:00 2001 From: "Jimi (Dimitris) Charalampidis" Date: Thu, 10 Nov 2016 22:09:38 +0200 Subject: [PATCH] Add stompjs types 2.0 definitions. (#12605) --- stompjs/index.d.ts | 67 +++++++++++++++++++++++++++++++ stompjs/stompjs-tests.ts | 87 ++++++++++++++++++++++++++++++++++++++++ stompjs/tsconfig.json | 19 +++++++++ 3 files changed, 173 insertions(+) create mode 100644 stompjs/index.d.ts create mode 100644 stompjs/stompjs-tests.ts create mode 100644 stompjs/tsconfig.json diff --git a/stompjs/index.d.ts b/stompjs/index.d.ts new file mode 100644 index 0000000000..607be77162 --- /dev/null +++ b/stompjs/index.d.ts @@ -0,0 +1,67 @@ +// Type definitions for stompjs 2.3 +// Project: https://github.com/jmesnil/stomp-websocket +// Definitions by: Jimi Charalampidis +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export const VERSIONS: { + V1_0: string, + V1_1: string, + V1_2: string, + supportedVersions: () => Array +}; + +export class Client { + + connected: boolean; + counter: number; + heartbeat: { + incoming: number, + outgoing: number + }; + maxWebSocketFrameSize: number; + subscriptions: {}; + ws: WebSocket; + + debug(...args: string[]): any; + + connect(...args: any[]): any; + disconnect(disconnectCallback: () => any, headers?: {}): any; + + send(destination: string, headers?: {}, body?: string): any; + subscribe(destination: string, callback?: (message: Message) => any, headers?: {}): any; + unsubscribe(): any; + + begin(transaction: string): any; + commit(transaction: string): any; + abort(transaction: string): any; + + ack(messageID: string, subscription: string, headers?: {}): any; + nack(messageID: string, subscription: string, headers?: {}): any; +} + +export interface Message { + command: string; + headers: {}; + body: string; + + ack(headers?: {}): any; + nack(headers?: {}): any; +} + +export class Frame { + constructor(command: string, headers?: {}, body?: string); + + toString(): string; + sizeOfUTF8(s: string): number; + unmarshall(datas: any): any; + marshall(command: string, headers?: {}, body?: string): any; +} + +export function client(url: string, protocols?: string | Array): Client; +export function over(ws: WebSocket): Client; +export function overTCP(host: string, port: number): Client; +export function overWS(url: string): Client; +export function setInterval(interval: number, f: (...args: any[]) => void): NodeJS.Timer; +export function clearInterval(id: NodeJS.Timer): void; diff --git a/stompjs/stompjs-tests.ts b/stompjs/stompjs-tests.ts new file mode 100644 index 0000000000..68320259a9 --- /dev/null +++ b/stompjs/stompjs-tests.ts @@ -0,0 +1,87 @@ +import * as Stomp from 'stompjs'; + +let interval = Stomp.setInterval(1000, () => { }); +Stomp.clearInterval(interval); + +let client: Stomp.Client; + +client = Stomp.client('url'); +client = Stomp.client('url', Stomp.VERSIONS.supportedVersions()); +client = Stomp.client('url', Stomp.VERSIONS.V1_0); +client = Stomp.client('url', Stomp.VERSIONS.V1_1); + +client = Stomp.over(new WebSocket('url')); +client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.supportedVersions())); +client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.V1_0)); +client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.V1_1)); + +client = Stomp.overTCP('host', 0); + +client = Stomp.overWS('url'); + +client.connected = false; +client.counter = 0; +client.heartbeat = { incoming: 20000, outgoing: 20000 }; +client.maxWebSocketFrameSize = 16 * 1024; +client.subscriptions = { 'sub-0': {}, 'sub-1': () => { } }; +client.ws = new WebSocket('url'); + +client.debug(); + +client.connect(); +client.connect('', () => { }, {}); + +client.disconnect(() => { }); +client.disconnect(() => { }, {}); + +client.send('destination'); +client.send('destination', {}); +client.send('destination', {}, 'body'); + +client.subscribe('destination', (message) => { }); +client.subscribe('destination', (message) => { }, {}); + +client.unsubscribe(); + +client.begin('transaction'); + +client.commit('transaction'); + +client.abort('transaction'); + +client.ack('messageID', 'subscription'); +client.nack('messageID', 'subscription', {}); + +let message: Stomp.Message = { + command: 'command', + headers: {}, + body: 'body', + + ack({}) { }, + nack({}) { } +} + +message.ack(); +message.ack({}); + +message.nack(); +message.nack({}); + +let frame: Stomp.Frame; + +frame = new Stomp.Frame('command'); +frame = new Stomp.Frame('command', {}); +frame = new Stomp.Frame('command', {}, 'body'); + +frame.toString(); + +frame.sizeOfUTF8('abc'); + +frame.unmarshall(0); +frame.unmarshall('data'); +frame.unmarshall({}); +frame.unmarshall([{}, {}]); + +frame.marshall('command'); +frame.marshall('command', {}); +frame.marshall('command', {}, 'body'); diff --git a/stompjs/tsconfig.json b/stompjs/tsconfig.json new file mode 100644 index 0000000000..2377e6b1b7 --- /dev/null +++ b/stompjs/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "stompjs-tests.ts" + ] +}