From 7ac1deb81d03ea5b865e5f83965b6a0d0300f79c Mon Sep 17 00:00:00 2001 From: omrilotan Date: Tue, 12 Mar 2024 18:22:28 +0000 Subject: [PATCH] Add types definition --- index.d.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ee388eb --- /dev/null +++ b/index.d.ts @@ -0,0 +1,60 @@ +declare class SDC { + constructor({ + host, + port, + protocol, + protocol_version, + MTU, + timeout, + tags, + scheme, + prefix, + sanitise, + errorHandler, + enforceRate + }: { + // StatsD host [127.0.0.1] + host?: string, + // StatsD port [8125] + port?: string|number, + // Internet Protocol (UDP/TCP) [UDP] + protocol?: string, + // Internet Protocol version (ipv4/ipv6) [ipv4] + protocol_version?: string + // Maximum Transmission Unit [576] + MTU?: number, + // Maximum cutoff time (ms) until flush current metric bulk [1000] + timeout?: number, + // Default tags to be sent with every metric [] + tags?, + // Format stats metric as: `'datadog'`, `'graphite'`, custom format function [datadog] + scheme?: string|( + ({ + type, key, value, rate, tags + }: { + type: string, + key: string, + value: number, + rate: number, + tags: string[] + }) => string), + // Prefix all stats with this value [] + prefix?: string, + // Sanitise stat keys [Default sanitisation: Allow characters, numbers, underscores and dots. Replace everything else with underscore. Lowercase everything] + sanitise?: (string: string) => string, + // Handle message sending errors (see section 'Throwing errors') [] + errorHandler?: Function, + // Should I enforce rate (mark as false is rate was already enforced) [true] + enforceRate?: boolean, + }); + count(key: string, value: number, rate?: number, tags?: string[]): void; + time(key: string, value: number, rate?: number, tags?: string[]): void; + gauge(key: string, value: number, rate?: number, tags?: string[]): void; + set(key: string, value: number, rate?: number, tags?: string[]): void; + generic(type: string, key: string, value: number, rate?: number, tags?: string[]): void; + histogram(key: string, value: number, rate?: number, tags?: string[]): void; + get size(): number; + destroy(): void; +} + +export default SDC; diff --git a/package.json b/package.json index c87c26b..74c1dd1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fiverr/statsd-client", - "version": "1.1.0", + "version": "1.1.1", "description": "📈 A feature packed, highly customisable StatsD client", "keywords": [ "StatsD", @@ -24,6 +24,7 @@ }, "homepage": "https://fiverr.github.io/node-statsd-client", "main": "index.js", + "types": "index.d.ts", "scripts": { "predocs": "which docsify || npm i --no-save docsify-cli", "docs": "docsify serve docs -p 6375",