From dba4b88578baa4c64621f485f903c8e9559fa456 Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Mon, 14 Jan 2019 18:27:49 +0800 Subject: [PATCH 1/5] Update index.d.ts --- types/pidusage/index.d.ts | 85 +++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/types/pidusage/index.d.ts b/types/pidusage/index.d.ts index b16dada0ef..79ca2ae88d 100644 --- a/types/pidusage/index.d.ts +++ b/types/pidusage/index.d.ts @@ -5,46 +5,61 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -declare function pidusage(pid: number | string, callback: (err: Error | null, stats: Stat) => void): void; -declare function pidusage(pids: Array, callback: (err: Error | null, stats: { [key: string]: Stat }) => void): void; -declare function pidusage(pid: number | string): Promise; -declare function pidusage(pids: Array): Promise<{ [key: string]: Stat }>; +interface IStat { + /** + * percentage (from 0 to 100*vcore) + */ + cpu: number; -export default pidusage; + /** + * bytes + */ + memory: number; -export interface Stat { - /** - * percentage (from 0 to 100*vcore) - */ - cpu: number; + /** + * PPID + */ + ppid: number; - /** - * bytes - */ - memory: number; + /** + * PID + */ + pid: number; - /** - * PPID - */ - ppid: number; + /** + * ms user + system time + */ + ctime: number; - /** - * PID - */ - pid: number; + /** + * ms since the start of the process + */ + elapsed: number; - /** - * ms user + system time - */ - ctime: number; + /** + * ms since epoch + */ + timestamp: number; +} - /** - * ms since the start of the process - */ - elapsed: number; +declare function pidusage(pid: number | string, callback: (err: Error | null, stats: IStat) => void): void; +declare function pidusage(pid: number | string, options: { [key: string]: any }, callback: (err: Error | null, stats: IStat) => void): void; +declare function pidusage(pids: Array, callback: (err: Error | null, stats: { [key: string]: IStat }) => void): void; +declare function pidusage(pids: Array, options: { [key: string]: any }, callback: (err: Error | null, stats: { [key: string]: IStat }) => void): void; +declare function pidusage(pid: number | string): Promise; +declare function pidusage(pid: number | string, options: { [key: string]: any }): Promise; +declare function pidusage(pids: Array): Promise<{ [key: string]: IStat }>; +declare function pidusage(pids: Array, options: { [key: string]: any }): Promise<{ [key: string]: IStat }>; - /** - * ms since epoch - */ - timestamp: number; - } +declare namespace pidusage { + export type Status = IStat; + + /** + * If needed this function can be used to clear the event loop. + * Indeed, we're registering an interval to free up the in-memory metrics. + * By calling this, it will clear this interval and all delete all in-memory data + */ + export const clear: () => void; +} + +export = pidusage; From d26f6be7e7e7e71ee0cedee8612be249a0b53cb0 Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Mon, 14 Jan 2019 18:32:26 +0800 Subject: [PATCH 2/5] Update pidusage-tests.ts --- types/pidusage/pidusage-tests.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/types/pidusage/pidusage-tests.ts b/types/pidusage/pidusage-tests.ts index 614569dfa3..8c3d99e194 100644 --- a/types/pidusage/pidusage-tests.ts +++ b/types/pidusage/pidusage-tests.ts @@ -1,4 +1,4 @@ -import pidusage, { Stat } from 'pidusage'; +import * as pidusage from 'pidusage'; let cpu: number; let memory: number; @@ -8,7 +8,7 @@ let ctime: number; let elapsed: number; let timestamp: number; -pidusage(1, (err: Error | null, stats: Stat) => { +pidusage(1, (err: Error | null, stats: pidusage.Status) => { cpu = stats.cpu; memory = stats.memory; ppid = stats.ppid; @@ -18,7 +18,7 @@ pidusage(1, (err: Error | null, stats: Stat) => { timestamp = stats.timestamp; }); -pidusage('two', (err: Error | null, stats: Stat) => { +pidusage('two', {}, (err: Error | null, stats: pidusage.Status) => { cpu = stats.cpu; memory = stats.memory; ppid = stats.ppid; @@ -28,11 +28,18 @@ pidusage('two', (err: Error | null, stats: Stat) => { timestamp = stats.timestamp; }); -pidusage([1, 'two'], (err: Error | null, stats: { [key: string]: Stat }) => { - const one: Stat = stats[1]; - const two: Stat = stats.two; +pidusage([1, 'two'], (err: Error | null, stats: { [key: string]: pidusage.Status }) => { + const one: pidusage.Status = stats[1]; + const two: pidusage.Status = stats.two; }); -const stats_1: Promise = pidusage(1); -const stats_two: Promise = pidusage('two'); -const stats_obj: Promise<{ [key: string]: Stat }> = pidusage([1, 'two']); +pidusage([1, 'two'], {}, (err: Error | null, stats: { [key: string]: pidusage.Status }) => { + const one: pidusage.Status = stats[1]; + const two: pidusage.Status = stats.two; +}); + +const stats_1: Promise = pidusage(1); +const stats_two: Promise = pidusage('two', {}); + +const stats_obj: Promise<{ [key: string]: pidusage.Status }> = pidusage([1, 'two']); +const stats_obj_config: Promise<{ [key: string]: pidusage.Status }> = pidusage([1, 'two'], {}); From b691c656f8c2079981934869b0ad433ba03b48ac Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Mon, 14 Jan 2019 18:51:24 +0800 Subject: [PATCH 3/5] Update index.d.ts --- types/pidusage/index.d.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/types/pidusage/index.d.ts b/types/pidusage/index.d.ts index 79ca2ae88d..976611f9b3 100644 --- a/types/pidusage/index.d.ts +++ b/types/pidusage/index.d.ts @@ -5,7 +5,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -interface IStat { +interface Stat { /** * percentage (from 0 to 100*vcore) */ @@ -42,24 +42,22 @@ interface IStat { timestamp: number; } -declare function pidusage(pid: number | string, callback: (err: Error | null, stats: IStat) => void): void; -declare function pidusage(pid: number | string, options: { [key: string]: any }, callback: (err: Error | null, stats: IStat) => void): void; -declare function pidusage(pids: Array, callback: (err: Error | null, stats: { [key: string]: IStat }) => void): void; -declare function pidusage(pids: Array, options: { [key: string]: any }, callback: (err: Error | null, stats: { [key: string]: IStat }) => void): void; -declare function pidusage(pid: number | string): Promise; -declare function pidusage(pid: number | string, options: { [key: string]: any }): Promise; -declare function pidusage(pids: Array): Promise<{ [key: string]: IStat }>; -declare function pidusage(pids: Array, options: { [key: string]: any }): Promise<{ [key: string]: IStat }>; +declare function pidusage(pid: number | string, callback: (err: Error | null, stats: Stat) => void): void; +declare function pidusage(pid: number | string, options: { [key: string]: any }, callback: (err: Error | null, stats: Stat) => void): void; +declare function pidusage(pids: Array, callback: (err: Error | null, stats: { [key: string]: Stat }) => void): void; +declare function pidusage(pids: Array, options: { [key: string]: any }, callback: (err: Error | null, stats: { [key: string]: Stat }) => void): void; +declare function pidusage(pid: number | string, options?: { [key: string]: any }): Promise; +declare function pidusage(pids: Array, options?: { [key: string]: any }): Promise<{ [key: string]: Stat }>; declare namespace pidusage { - export type Status = IStat; + type Status = Stat; /** * If needed this function can be used to clear the event loop. * Indeed, we're registering an interval to free up the in-memory metrics. * By calling this, it will clear this interval and all delete all in-memory data */ - export const clear: () => void; + export function clear(): void; } export = pidusage; From 25ad5fe08a74f8105820f74209cd6bad2419cf3d Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Mon, 14 Jan 2019 18:57:00 +0800 Subject: [PATCH 4/5] Update index.d.ts --- types/pidusage/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/pidusage/index.d.ts b/types/pidusage/index.d.ts index 976611f9b3..3efec6ce09 100644 --- a/types/pidusage/index.d.ts +++ b/types/pidusage/index.d.ts @@ -53,11 +53,11 @@ declare namespace pidusage { type Status = Stat; /** - * If needed this function can be used to clear the event loop. - * Indeed, we're registering an interval to free up the in-memory metrics. + * If needed this function can be used to clear the event loop. + * Indeed, we're registering an interval to free up the in-memory metrics. * By calling this, it will clear this interval and all delete all in-memory data */ - export function clear(): void; + function clear(): void; } export = pidusage; From 871ed4521f35be1d8688eed84e1a4ee15cbea094 Mon Sep 17 00:00:00 2001 From: wujingtao <601595686@qq.com> Date: Tue, 15 Jan 2019 11:31:45 +0800 Subject: [PATCH 5/5] revision the module import statement --- types/pidusage/pidusage-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/pidusage/pidusage-tests.ts b/types/pidusage/pidusage-tests.ts index 8c3d99e194..faa2b30c0c 100644 --- a/types/pidusage/pidusage-tests.ts +++ b/types/pidusage/pidusage-tests.ts @@ -1,4 +1,4 @@ -import * as pidusage from 'pidusage'; +import pidusage = require('pidusage'); let cpu: number; let memory: number;