From 8ca677c1aab7059e2f929a176e56af0ca525a008 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Wed, 15 Feb 2017 18:30:49 +0100 Subject: [PATCH 1/5] Added type definitions for node-xmpp-client --- node-xmpp-client/index.d.ts | 73 ++++++++++++++++++++++ node-xmpp-client/node-xmpp-client-tests.ts | 21 +++++++ node-xmpp-client/tsconfig.json | 13 ++++ 3 files changed, 107 insertions(+) create mode 100644 node-xmpp-client/index.d.ts create mode 100644 node-xmpp-client/node-xmpp-client-tests.ts create mode 100644 node-xmpp-client/tsconfig.json diff --git a/node-xmpp-client/index.d.ts b/node-xmpp-client/index.d.ts new file mode 100644 index 0000000000..894c3dead8 --- /dev/null +++ b/node-xmpp-client/index.d.ts @@ -0,0 +1,73 @@ +// Type definitions for Node Xmpp Client 3.1.3 +// Project: https://github.com/node-xmpp/node-xmpp/tree/master/packages/node-xmpp-client/ +// Definitions by: PJakcson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export declare class Client { + static Stanza: Stanza; + + constructor(options: XmppOptions); + + /** + * Connect to Xmpp-Server + */ + connect(): void; + + disconnect(): void; + + on(event: string, c: (err: any, r: any) => any): void; + + send(stanza: any): void; + + end(): void; +} + +interface Stanza extends Element { + new(name: string, attr: any): Stanza; + from: string; + to: string; + id: string; + type: string; +} + +interface Element { + is(name: string, xmlns: string): boolean; + getName(): string; + getNS(): string; + findNS(prefix: string): string; + getXmlns(): string; + setAttrs(attrs: any): void; + getAttrs(): any; + + up(): Element; + c(name: string, attrs?: any): Element; + cnode(child: Element): Element; + t(text: string): Element; + remove(el: Element, xmnls: string): Element; + attr(attr: any, val: any): any; + + toString(): string; + toJSON(): any; +} + +interface XmppOptions { + jid: string; + password: string; + host?: string; + port?: number; + reconnect?: boolean; + autostart?: boolean; // if we start connecting to a given port + register?: boolean; // register account before authentication + legacySSL?: boolean; // connect to the legacy SSL port, requires at least the host to be specified + credentials?: any; // Dictionary (optional) - TLS or SSL key and certificate credentials + actAs?: string; // if admin user act on behalf of another user (just user) + disallowTLS?: boolean; // prevent upgrading the connection to a secure one via TLS + preferred?: string; // Preferred SASL mechanism to use + bosh?: Bosh; +} + +interface Bosh { + url?: string + prebind?: (error, data) => void; +} diff --git a/node-xmpp-client/node-xmpp-client-tests.ts b/node-xmpp-client/node-xmpp-client-tests.ts new file mode 100644 index 0000000000..6ff2803197 --- /dev/null +++ b/node-xmpp-client/node-xmpp-client-tests.ts @@ -0,0 +1,21 @@ +import {Client} from './index'; + +let client = new Client({ + jid: 'user@example.com', + password: 'password' +}); + +client.on('online', function () { + console.log('online') +}); + +client.on('stanza', function (stanza) { + console.log('Incoming stanza: ', stanza.toString()) +}); + +let stanza = new Client.Stanza('chat', {}) + .c('show').t('chat').up() + .c('status').t('message'); +this.client.send(stanza); + +client.end(); diff --git a/node-xmpp-client/tsconfig.json b/node-xmpp-client/tsconfig.json new file mode 100644 index 0000000000..54d5c2a02f --- /dev/null +++ b/node-xmpp-client/tsconfig.json @@ -0,0 +1,13 @@ +{ + "files": [ + "index.d.ts", + "node-xmpp-client-tests.ts" + ], + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "sourceMap": true + }, + "exclude": [ + ] +} From 911723cfa7f9bc07d2585d98c113d0e31a582ee3 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Wed, 15 Feb 2017 18:59:07 +0100 Subject: [PATCH 2/5] Minor adjustments and added tslist.json. --- node-xmpp-client/index.d.ts | 12 ++++-------- node-xmpp-client/node-xmpp-client-tests.ts | 6 ++++-- node-xmpp-client/tsconfig.json | 14 ++++++++------ node-xmpp-client/tslint.json | 3 +++ 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 node-xmpp-client/tslint.json diff --git a/node-xmpp-client/index.d.ts b/node-xmpp-client/index.d.ts index 894c3dead8..3c70f44f50 100644 --- a/node-xmpp-client/index.d.ts +++ b/node-xmpp-client/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Node Xmpp Client 3.1.3 +// Type definitions for node-xmpp-client 3.1 // Project: https://github.com/node-xmpp/node-xmpp/tree/master/packages/node-xmpp-client/ // Definitions by: PJakcson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -9,9 +9,6 @@ export declare class Client { constructor(options: XmppOptions); - /** - * Connect to Xmpp-Server - */ connect(): void; disconnect(): void; @@ -19,11 +16,10 @@ export declare class Client { on(event: string, c: (err: any, r: any) => any): void; send(stanza: any): void; - - end(): void; } interface Stanza extends Element { + // tslint:disable-next-line new(name: string, attr: any): Stanza; from: string; to: string; @@ -68,6 +64,6 @@ interface XmppOptions { } interface Bosh { - url?: string - prebind?: (error, data) => void; + url?: string; + prebind?: (error: any, data: any) => void; } diff --git a/node-xmpp-client/node-xmpp-client-tests.ts b/node-xmpp-client/node-xmpp-client-tests.ts index 6ff2803197..1e4c215462 100644 --- a/node-xmpp-client/node-xmpp-client-tests.ts +++ b/node-xmpp-client/node-xmpp-client-tests.ts @@ -5,6 +5,8 @@ let client = new Client({ password: 'password' }); +client.connect(); + client.on('online', function () { console.log('online') }); @@ -16,6 +18,6 @@ client.on('stanza', function (stanza) { let stanza = new Client.Stanza('chat', {}) .c('show').t('chat').up() .c('status').t('message'); -this.client.send(stanza); +client.send(stanza); -client.end(); +client.disconnect(); diff --git a/node-xmpp-client/tsconfig.json b/node-xmpp-client/tsconfig.json index 54d5c2a02f..fface20c51 100644 --- a/node-xmpp-client/tsconfig.json +++ b/node-xmpp-client/tsconfig.json @@ -1,13 +1,15 @@ { - "files": [ - "index.d.ts", - "node-xmpp-client-tests.ts" - ], "compilerOptions": { "module": "commonjs", "target": "es5", - "sourceMap": true + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "noEmit": true, + "forceConsistentCasingInFileNames": true }, - "exclude": [ + "files": [ + "index.d.ts", + "node-xmpp-client-tests.ts" ] } diff --git a/node-xmpp-client/tslint.json b/node-xmpp-client/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/node-xmpp-client/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} From a531496e5c95fd8f23886da8f2bd263341902166 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Wed, 15 Feb 2017 19:02:01 +0100 Subject: [PATCH 3/5] Minor comment. --- node-xmpp-client/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node-xmpp-client/index.d.ts b/node-xmpp-client/index.d.ts index 3c70f44f50..97e7cdfa73 100644 --- a/node-xmpp-client/index.d.ts +++ b/node-xmpp-client/index.d.ts @@ -19,6 +19,8 @@ export declare class Client { } interface Stanza extends Element { + // This has to be used for the static class initializer new Client.Stanza(..). If there is a better way feel free to + // contribute. // tslint:disable-next-line new(name: string, attr: any): Stanza; from: string; From e90288f791fcf43bdf80f3ba5e37032bd45d31a7 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Wed, 15 Feb 2017 19:03:24 +0100 Subject: [PATCH 4/5] Added lib in tsconfig. --- node-xmpp-client/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node-xmpp-client/tsconfig.json b/node-xmpp-client/tsconfig.json index fface20c51..03d7dfa4db 100644 --- a/node-xmpp-client/tsconfig.json +++ b/node-xmpp-client/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { "module": "commonjs", - "target": "es5", + "lib": [ + "es6" + ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, From 29e48f54a7a806fa6b3ce7f739555b377363df35 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Wed, 15 Feb 2017 19:13:25 +0100 Subject: [PATCH 5/5] Switch to es6 part II. --- node-xmpp-client/index.d.ts | 2 +- node-xmpp-client/node-xmpp-client-tests.ts | 3 +-- node-xmpp-client/tsconfig.json | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/node-xmpp-client/index.d.ts b/node-xmpp-client/index.d.ts index 97e7cdfa73..874df37de7 100644 --- a/node-xmpp-client/index.d.ts +++ b/node-xmpp-client/index.d.ts @@ -13,7 +13,7 @@ export declare class Client { disconnect(): void; - on(event: string, c: (err: any, r: any) => any): void; + on(event: string, c: (e: any, d: any) => any): void; send(stanza: any): void; } diff --git a/node-xmpp-client/node-xmpp-client-tests.ts b/node-xmpp-client/node-xmpp-client-tests.ts index 1e4c215462..52a54a0453 100644 --- a/node-xmpp-client/node-xmpp-client-tests.ts +++ b/node-xmpp-client/node-xmpp-client-tests.ts @@ -8,11 +8,10 @@ let client = new Client({ client.connect(); client.on('online', function () { - console.log('online') }); client.on('stanza', function (stanza) { - console.log('Incoming stanza: ', stanza.toString()) + let _ = stanza; }); let stanza = new Client.Stanza('chat', {}) diff --git a/node-xmpp-client/tsconfig.json b/node-xmpp-client/tsconfig.json index 03d7dfa4db..c76db9a985 100644 --- a/node-xmpp-client/tsconfig.json +++ b/node-xmpp-client/tsconfig.json @@ -7,6 +7,11 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true },