mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
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:
parent
0796946a66
commit
585e114310
43
graphite-udp/graphite-udp-tests.ts
Normal file
43
graphite-udp/graphite-udp-tests.ts
Normal 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
97
graphite-udp/index.d.ts
vendored
Normal 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;
|
||||
22
graphite-udp/tsconfig.json
Normal file
22
graphite-udp/tsconfig.json
Normal 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
1
graphite-udp/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user