forked from shopyourway/metrics-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ysa23/feat/typescript-declarations
Feature: TypeScript declarations
- Loading branch information
Showing
21 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ jobs: | |
- run: npm install | ||
- run: npm run lint | ||
- run: npm test | ||
- run: npm run tsc:build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./metrics"; | ||
export * from "./reporters"; | ||
export * from "./types"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
const { ConsoleReporter } = require('./reporters/console-reporter'); | ||
const { DataDogReporter } = require('./reporters/datadog-reporter'); | ||
const { GraphiteReporter } = require('./reporters/graphite-reporter'); | ||
const { InMemoryReporter } = require('./reporters/in-memory-reporter'); | ||
const { StringReporter } = require('./reporters/string-reporter'); | ||
const reporters = require('./reporters'); | ||
const { Metrics } = require('./metrics'); | ||
|
||
module.exports = { | ||
Metrics, | ||
ConsoleReporter, | ||
DataDogReporter, | ||
GraphiteReporter, | ||
InMemoryReporter, | ||
StringReporter, | ||
...reporters, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Space} from "./space"; | ||
import {Tags} from "./types/tags"; | ||
import {IReporter} from "./types/reporter"; | ||
|
||
declare interface MetricsOptions { | ||
reporters: IReporter[]; | ||
tags: Tags; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
export declare class Metrics { | ||
constructor(options: MetricsOptions); | ||
|
||
space(key: string, tags?: Tags): Space; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {ErrorCallback} from "../types/error-callback"; | ||
|
||
declare interface SocketOptions { | ||
port: number; | ||
host: string; | ||
maxBufferSize?: number; | ||
flushInterval?: number; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
declare interface SendProps { | ||
message: any; | ||
} | ||
|
||
export declare class Socket { | ||
constructor(options: SocketOptions); | ||
|
||
send(props: SendProps) : void; | ||
close() : void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Tags} from "../types/tags"; | ||
import {ErrorCallback} from "../types/error-callback"; | ||
|
||
declare interface SendProps { | ||
key: string; | ||
value: number; | ||
type: string; | ||
tags?: Tags; | ||
} | ||
|
||
declare interface StatsdSocketOptions { | ||
port?: number; | ||
host: string; | ||
batch?: boolean; | ||
maxBufferSize?: number; | ||
flushInterval?: number; | ||
prefix?: string; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
export declare class StatsdSocket { | ||
constructor(options: StatsdSocketOptions); | ||
|
||
send(props: SendProps) : void; | ||
close() : void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Tags} from "../types/tags"; | ||
import {IReporter} from "../types/reporter"; | ||
|
||
export declare class ConsoleReporter implements IReporter { | ||
constructor(); | ||
|
||
report(key: string, value: number, tags?: Tags); | ||
value(key: string, value: number, tags?: Tags); | ||
increment(key: string, value?: number, tags?: Tags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {IReporter} from "../types/reporter"; | ||
import {Tags} from "../types/tags"; | ||
|
||
declare interface DataDogReporterOptions { | ||
host: string; | ||
port?: number; | ||
prefix?: string; | ||
batch?: boolean; | ||
maxBufferSize?: number; | ||
flushInterval?: number; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
export declare class DataDogReporter implements IReporter { | ||
constructor(options: DataDogReporterOptions); | ||
|
||
report(key: string, value: number, tags?: Tags); | ||
value(key: string, value: number, tags?: Tags); | ||
increment(key: string, value?: number, tags?: Tags); | ||
|
||
close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {IReporter} from "../types/reporter"; | ||
import {Tags} from "../types/tags"; | ||
|
||
declare interface GraphiteReporterOptions { | ||
host: string; | ||
port?: number; | ||
prefix?: string; | ||
batch?: boolean; | ||
maxBufferSize?: number; | ||
flushInterval?: number; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
export declare class GraphiteReporter implements IReporter { | ||
constructor(options: GraphiteReporterOptions); | ||
|
||
report(key: string, value: number, tags?: Tags); | ||
value(key: string, value: number, tags?: Tags); | ||
increment(key: string, value?: number, tags?: Tags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {IReporter} from "../types/reporter"; | ||
import {Tags} from "../types/tags"; | ||
|
||
declare interface InMemoryReporterOptions { | ||
buffer: any[]; | ||
} | ||
|
||
export declare class InMemoryReporter implements IReporter { | ||
constructor(options: InMemoryReporterOptions); | ||
|
||
increment(key: string, value?: number, tags?: Tags); | ||
report(key: string, value: number, tags?: Tags); | ||
value(key: string, value: number, tags?: Tags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./console-reporter"; | ||
export * from "./datadog-reporter"; | ||
export * from "./graphite-reporter"; | ||
export * from "./in-memory-reporter"; | ||
export * from "./string-reporter"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { ConsoleReporter } = require('./console-reporter'); | ||
const { DataDogReporter } = require('./datadog-reporter'); | ||
const { GraphiteReporter } = require('./graphite-reporter'); | ||
const { InMemoryReporter } = require('./in-memory-reporter'); | ||
const { StringReporter } = require('./string-reporter'); | ||
|
||
module.exports = { | ||
ConsoleReporter, | ||
DataDogReporter, | ||
GraphiteReporter, | ||
InMemoryReporter, | ||
StringReporter, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {IReporter} from "../types/reporter"; | ||
import {Tags} from "../types/tags"; | ||
|
||
declare interface StringReporterOptions { | ||
action: (metric: string) => void; | ||
} | ||
|
||
export declare class StringReporter implements IReporter { | ||
constructor(options: StringReporterOptions); | ||
|
||
increment(key: string, value?: number, tags?: Tags); | ||
report(key: string, value: number, tags?: Tags); | ||
value(key: string, value: number, tags?: Tags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Tags} from "./types/tags"; | ||
import {IReporter} from "./types/reporter"; | ||
import {ErrorCallback} from "./types/error-callback"; | ||
|
||
declare interface SpaceOptions { | ||
key: string; | ||
tags: Tags; | ||
reporters: IReporter[]; | ||
errback?: ErrorCallback; | ||
} | ||
|
||
export declare class Space { | ||
constructor(options: SpaceOptions); | ||
|
||
value(val: number) : void; | ||
increment(val?: number): void; | ||
meter: <T>(func: () => T) => T; | ||
|
||
space: (nextKey: string, nextTags?: Tags) => Space; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare type ErrorCallback = (err: Error) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./reporter"; | ||
export * from "./tags"; | ||
export * from './error-callback'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Tags} from "./tags"; | ||
|
||
export declare interface IReporter { | ||
report(key: string, value: number, tags?: Tags); | ||
|
||
value(key: string, value: number, tags?: Tags); | ||
|
||
increment(key: string, value?: number, tags?: Tags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare type Tags = { [key: string]: string | number | boolean }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2021", | ||
}, | ||
"include": [ | ||
"./src/**/*.d.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
] | ||
} |