Skip to content

Commit

Permalink
fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Dec 10, 2023
1 parent f063195 commit 72d5202
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/cpu-usage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare type CpuUsageResponse = {
avg: number;
usages: number[];
};

declare function _exports(sampleTime?: number): Promise<CpuUsageResponse>;
export = _exports;
12 changes: 12 additions & 0 deletions src/health.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os = require("os");
import type { NodeHealthStatus } from "./service-broker";

export function getHealthStatus(): NodeHealthStatus;

export function getCpuInfo(): NodeHealthStatus["cpu"];
export function getMemoryInfo(): NodeHealthStatus["mem"];
export function getOsInfo(): NodeHealthStatus["os"];
export function getProcessInfo(): NodeHealthStatus["process"];
export function getClientInfo(): NodeHealthStatus["client"];
export function getNetworkInterfacesInfo(): NodeHealthStatus["net"];
export function getDateTimeInfo(): NodeHealthStatus["time"];
2 changes: 1 addition & 1 deletion src/health.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* moleculer
* Copyright (c) 2019 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

Expand Down
4 changes: 4 additions & 0 deletions src/internals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { ServiceSchema, ServiceSettingSchema } from "./service";

declare function _exports(): ServiceSchema<ServiceSettingSchema>;
export = _exports;
9 changes: 9 additions & 0 deletions src/lock.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare class Lock {
locked: Map<string, any[]>;

acquire(key: string, ttl: number): Promise<any>;
isLocked(key: string): boolean;
release(key: string): Promise<void>;
}

export = Lock;
9 changes: 8 additions & 1 deletion src/lock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/*
* moleculer
* Copyright (c) 2019 MoleculerJS (https://github.com/moleculerjs/moleculer)
* Copyright (c) 2023 MoleculerJS (https://github.com/moleculerjs/moleculer)
* MIT Licensed
*/

"use strict";

/**
* @typedef {import("./lock")} LockClass
*/

/**
* @implements {LockClass}
*/
class Lock {
constructor() {
this.locked = new Map();
Expand Down
11 changes: 11 additions & 0 deletions src/metrics/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Register common OS, process & Moleculer metrics.
*/
export function registerCommonMetrics(): void;

/**
* Update common metric values.
*
* @returns {Promise}
*/
export function updateCommonMetrics(): Promise<void>;
21 changes: 21 additions & 0 deletions src/metrics/rates.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type BaseMetric = require("./types/base");

declare class MetricRate {
metric: BaseMetric;
item: Record<string, any>;
min: number;

constructor(metric: BaseMetric, item: Record<string, any>, min: number);

rate: number;
lastValue: number;
lastTickTime: number;
value: number;
timer: NodeJS.Timeout;

update(value: number): void;
tick(): void;
reset(): void;
}

export = MetricRate;
7 changes: 7 additions & 0 deletions src/metrics/rates.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ function getAlpha(min) {
}
*/

/**
* @typedef {import("./rates")} MetricRateClass
*/

/**
* @implements {MetricRateClass}
*/
class MetricRate {
constructor(metric, item, min) {
this.metric = metric;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strict": false,
"checkJs": true,
"declaration": true,
"skipLibCheck": false,
"skipLibCheck": true,
"declarationDir": "generated-types",
"outDir": "dist",
"noEmit": true,
Expand Down

0 comments on commit 72d5202

Please sign in to comment.