Add declarations for module graphite-udp (#14927)

* Adding graphite-udp typings

* Cleaning up linting errors

* Removing the namespacing that is not needed

* Adding missing constructor typing, capitilizing the interface

* Callback is optional
This commit is contained in:
Eric Byers 2017-03-10 00:51:45 -06:00 committed by Mohamed Hegazy
parent 0796946a66
commit 585e114310
4 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,43 @@
import graphite = require('graphite-udp');
// Test creation of client directly.
let client = new graphite.Client();
client.put('test', 1);
client.add('test', 1);
client.close();
// Create client with helper
let client2 = graphite.createClient();
client2.put('test2', 1);
client2.add('test2', 1);
client2.close();
// Test creation with options.
graphite.createClient({
host: '127.0.0.1',
port: 2003,
type: 'udp4',
maxPacketSize: 4096,
prefix: 'prefix',
suffix: 'suffix',
interval: 60 * 1000,
verbose: true,
callback: (error: Error, metrics: any): void => {
}
});
// Test creation options with class directly.
new graphite.Client({
host: '127.0.0.1',
port: 2003,
type: 'udp4',
maxPacketSize: 4096,
prefix: 'prefix',
suffix: 'suffix',
interval: 60 * 1000,
verbose: true,
callback: (error: Error, metrics: any): void => {
}
});

97
graphite-udp/index.d.ts vendored Normal file
View File

@ -0,0 +1,97 @@
// Type definitions for graphite-udp 1.2
// Project: https://github.com/fermads/graphite-udp
// Definitions by: Eric Byers <https://github.com/EricByers/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface ClientOptions {
/**
* graphite server host or ip
* Defaults to 127.0.0.1
*/
host?: string;
/**
* graphite server udp port
* Defaults to 2003
*/
port?: number;
/**
* udp type (udp4 or udp6)
* Defaults to udp4
*/
type?: 'udp4' | 'udp6';
/**
* split into smaller UDP packets
* Defaults to 4096
*/
maxPacketSize?: number;
/**
* Prefix for each metric name
* Defaults to ''
*/
prefix?: string;
/**
* Suffix for each metrtic name
* Defaults to ''
*/
suffix?: string;
/**
* Interval to group metrics by in milliseconds
* Defaults to 5000 (5s)
*/
interval?: number;
/**
* log messages to console
* Defaults to false
*/
verbose?: boolean;
/**
* called when metrics are sent
* Defaults to null
*
* @param {error} Error
* @param {metrics}
* @return void
*/
callback?: (error: Error, metrics: any) => void;
}
export class Client {
constructor(clientOptions?: ClientOptions);
/**
* During the interval time option, if 2 or more metrics with the same name are sent, metrics will be added (summed)
*
* @param {name}
* @param {value} number
* @return void
*/
add(name: string, value: number): void;
/**
* During the interval time option, if 2 or more metrics with the same name are sent, the last one will be used
*
* @param {name} metric name (my.test.metric)
* @param {value} number
* @return void
*/
put(name: string, value: number): void;
/**
* Close the underlying UDP client socket
*
* @return void
*/
close(): void;
}
export function createClient(clientOptions?: ClientOptions): Client;

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"graphite-udp-tests.ts"
]
}

1
graphite-udp/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "../tslint.json" }