diff --git a/types/mosca/index.d.ts b/types/mosca/index.d.ts new file mode 100644 index 0000000000..4478a6e692 --- /dev/null +++ b/types/mosca/index.d.ts @@ -0,0 +1,89 @@ +// Type definitions for mosca 1.0 +// Project: https://github.com/mcollina/mosca +// Definitions by: Joao Gabriel Gouveia +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class Server { + opts: any; + modernOpts: any; + dedupId: any; + clients: any; + closed: boolean; + + constructor(opts: any, callback?: () => void); + + on(when: string, callback: (() => void) | ((client: Client) => void) | ((packet: Packet, client: Client) => void)): void; + once(when: string, callback: () => void): void; + toString(): string; + subscribe(topic: string, callback: () => void, done: () => void): void; + publish(message: Message, callback: (obj: any, packet: Packet) => void): void; + authenticate(client: Client, username: string, password: string, + callback: (obj: any, authenticated: boolean) => void): void; + published(packet: Packet, client: Client, callback: (obj: any) => void): void; + authorizePublish(client: Client, topic: string, payload: string, + callback: (obj: any, authorized: boolean) => void): void; + authorizeSubscribe(client: Client, topic: string, callback: (obj: any, authorized: boolean) => void): void; + authorizeForward(client: Client, packet: Packet, callback: (obj: any, authorized: boolean) => void): void; + storePacket(packet: Packet, callback: () => void): void; + deleteOfflinePacket(client: Client, messageId: number, callback: () => void): void; + forwardRetained(pattern: string, client: Client, callback: () => void): void; + restoreClientSubscriptions(client: Client, callback: () => void): void; + forwardOfflinePackets(client: Client, callback: () => void): void; + updateOfflinePacket(client: Client, originMessageId: number, packet: Packet, + callback: (obj: any, packet: Packet) => void): void; + persistClient(client: Client, callback: () => void): void; + close(callback: () => void): void; + attachHttpServer(server: any, path?: any): void; +} + +export class Client { + id: any; + connection: any; + server: any; + logger: any; + subscriptions: any; + nextId: number; + inflight: any; + inflightCounter: number; + _lastDedupId: number; + _closed: boolean; + _closing: boolean; + + constructor(connection: any, server: Server); + + close(callback: () => void, reason: string): void; +} + +export class Stats { + maxConnectedClients: number; + connectedClients: number; + lastIntervalConnectedClients: number; + publishedMessages: number; + lastIntervalPublishedMessages: number; + started: Date; + load: any; + + wire(server: Server): void; +} + +export class Authorizer { + users: any; + + addUser(username: string, password: string, authorizePublish: string, + authorizeSubscribe: string, callback: (func: any) => void): void; +} + +export interface Packet { + topic: string; + payload: any; + messageId: any; + qos: any; + retain: any; +} + +export interface Message { + topic: string; + payload: any; + qos: number; + retain: boolean; +} diff --git a/types/mosca/mosca-tests.ts b/types/mosca/mosca-tests.ts new file mode 100644 index 0000000000..e03b664b1b --- /dev/null +++ b/types/mosca/mosca-tests.ts @@ -0,0 +1,16 @@ +import { Server, Client, Packet } from 'mosca'; + +const settings = { + port: 1883, + host: '0.0.0.0' +}; + +const server = new Server(settings); + +server.on('ready', () => {}); + +server.on('clientConnected', (client: Client) => {}); + +server.on('clientDisconnected', (client: Client) => {}); + +server.on('published', (packet: Packet, client: Client) => {}); diff --git a/types/mosca/tsconfig.json b/types/mosca/tsconfig.json new file mode 100644 index 0000000000..58b3dcaaf8 --- /dev/null +++ b/types/mosca/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mosca-tests.ts" + ] +} diff --git a/types/mosca/tslint.json b/types/mosca/tslint.json new file mode 100644 index 0000000000..6746359dda --- /dev/null +++ b/types/mosca/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}