From 949922e0959ccea0cad7a6fa787b63b7d4e67d3f Mon Sep 17 00:00:00 2001 From: Romain CONNESSON Date: Thu, 14 Nov 2019 02:20:13 +0100 Subject: [PATCH] Add types for syslog-client (#40354) --- types/syslog-client/index.d.ts | 76 ++++++++++++++++++++++ types/syslog-client/syslog-client-tests.ts | 11 ++++ types/syslog-client/tsconfig.json | 23 +++++++ types/syslog-client/tslint.json | 1 + 4 files changed, 111 insertions(+) create mode 100644 types/syslog-client/index.d.ts create mode 100644 types/syslog-client/syslog-client-tests.ts create mode 100644 types/syslog-client/tsconfig.json create mode 100644 types/syslog-client/tslint.json diff --git a/types/syslog-client/index.d.ts b/types/syslog-client/index.d.ts new file mode 100644 index 0000000000..0f06e3632a --- /dev/null +++ b/types/syslog-client/index.d.ts @@ -0,0 +1,76 @@ +// Type definitions for node-syslog-client 1.1 +// Project: https://github.com/paulgrove/node-syslog-client +// Definitions by: Romain CONNESSON +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { EventEmitter } from 'events'; + +export enum Transport { + Tcp = 1, + Udp = 2 +} + +export enum Facility { + Kernel = 0, + User = 1, + System = 3, + Audit = 13, + Alert = 14, + Local0 = 16, + Local1 = 17, + Local2 = 18, + Local3 = 19, + Local4 = 20, + Local5 = 21, + Local6 = 22, + Local7 = 23 +} + +export enum Severity { + Emergency = 0, + Alert = 1, + Critical = 2, + Error = 3, + Warning = 4, + Notice = 5, + Informational = 6, + Debug = 7 +} + +export interface ClientOptions { + syslogHostname?: string; + port?: number; + tcpTimeout?: number; + facility?: Facility; + severity?: Severity; + rfc3164?: boolean; + appName?: string; + dateFormatter?: (() => string); + transport?: Transport; + timestamp?: Date; + msgid?: string; +} + +export interface MessageOptions { + syslogHostname?: string; + facility?: Facility; + severity?: Severity; + rfc3164?: boolean; + appName?: string; + timestamp?: Date; + msgid?: string; +} + +export class Client extends EventEmitter { + constructor(target?: string, options?: ClientOptions); + buildFormattedMessage(message: string, options: MessageOptions): Buffer; + close(): Client; + log(message: string, options?: MessageOptions, cb?: ((error: Error | null) => void)): Client; + getTransport(cb: ((error: Error | null, transport: Transport) => void)): void; + onClose(): Client; + onError(error: Error): Client; +} + +export function createClient(target: string, options: ClientOptions): Client; diff --git a/types/syslog-client/syslog-client-tests.ts b/types/syslog-client/syslog-client-tests.ts new file mode 100644 index 0000000000..12143a6027 --- /dev/null +++ b/types/syslog-client/syslog-client-tests.ts @@ -0,0 +1,11 @@ +import * as syslog from 'syslog-client'; + +const syslog_client = syslog.createClient("127.0.0.1", { + port: 514, + transport: syslog.Transport.Tcp, + rfc3164: false, + appName: "testapp" +}); +syslog_client.log("Test message", { severity: syslog.Severity.Warning }, (error: Error | null) => { + syslog_client.close(); +}); diff --git a/types/syslog-client/tsconfig.json b/types/syslog-client/tsconfig.json new file mode 100644 index 0000000000..6d6e85d407 --- /dev/null +++ b/types/syslog-client/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "syslog-client-tests.ts" + ] +} diff --git a/types/syslog-client/tslint.json b/types/syslog-client/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/syslog-client/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }