@vroskus/library-health 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "requireConfigFile": false,
6
+ "project": ["tsconfig.json"]
7
+ },
8
+ "extends": [
9
+ "airbnb-base",
10
+ "airbnb-typescript",
11
+ "plugin:import/recommended",
12
+ "plugin:@typescript-eslint/eslint-recommended",
13
+ "plugin:@typescript-eslint/recommended",
14
+ "plugin:sort/recommended"
15
+ ],
16
+ "plugins": [
17
+ "@typescript-eslint",
18
+ "import",
19
+ "import-newlines",
20
+ "react",
21
+ "sort"
22
+ ],
23
+ "rules": {
24
+ "complexity": ["error", 5],
25
+ "@typescript-eslint/ban-ts-comment": [1],
26
+ "@typescript-eslint/no-unused-vars": [2],
27
+ "curly": ["error", "all"],
28
+ "import/no-cycle": [0],
29
+ "no-await-in-loop": 0,
30
+ "no-console": "error",
31
+ "no-duplicate-imports": [0],
32
+ "no-loss-of-precision": [0],
33
+ "no-restricted-syntax": 0,
34
+ "no-unreachable-loop": [0],
35
+ "no-useless-backreference": [0],
36
+ "no-unused-private-class-members": [2],
37
+ "padding-line-between-statements": ["error", {
38
+ "blankLine": "always",
39
+ "prev": ["const", "let"],
40
+ "next": "*"
41
+ }, {
42
+ "blankLine": "any",
43
+ "prev": ["const", "let"],
44
+ "next": ["const", "let"]
45
+ }, {
46
+ "blankLine": "always",
47
+ "prev": ["if", "function", "for"],
48
+ "next": "*"
49
+ }, {
50
+ "blankLine": "always",
51
+ "prev": "*",
52
+ "next": "return"
53
+ }],
54
+ "object-curly-newline": ["error", {
55
+ "ObjectExpression": "always",
56
+ "ObjectPattern": "always",
57
+ "ImportDeclaration": "always",
58
+ "ExportDeclaration": "always"
59
+ }],
60
+ "function-call-argument-newline": ["error", "always"],
61
+ "object-property-newline": ["error", {
62
+ "allowMultiplePropertiesPerLine": false
63
+ }],
64
+ "import-newlines/enforce": ["error", {
65
+ "items": 1,
66
+ "forceSingleLine": false
67
+ }],
68
+ "sort/imports": [0],
69
+ "sort/exports": [0]
70
+ },
71
+ "env": {
72
+ "browser": true,
73
+ "node": true,
74
+ "jest": true,
75
+ "es6": true
76
+ }
77
+ }
@@ -0,0 +1,4 @@
1
+ import type { Request as $Request, Response as $Response } from 'express';
2
+ type $HealthRoute = (req: $Request, res: $Response) => Promise<void>;
3
+ export declare const healthRoute: $HealthRoute;
4
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,4CAAoB;AACpB,kEAAoC;AA6BpC,MAAM,eAAe,GAAqB,GAAS,EAAE;IACnD,MAAM,IAAI,GAAG,MAAM,uBAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,uBAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACxC,MAAM,GAAG,GAAG,MAAM,uBAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE;QAC3B,EAAE,EAAE,YAAE,CAAC,MAAM,EAAE;KAChB,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,MAAM;KACP,CAAC;AACJ,CAAC,CAAA,CAAC;AAIK,MAAM,WAAW,GAAiB,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;IAC1D,MAAM,MAAM,GAAG,MAAM,eAAe,EAAE,CAAC;IAEvC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnB,CAAC,CAAA,CAAC;AAJW,QAAA,WAAW,eAItB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vroskus/library-health",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Health",
5
5
  "author": "Vilius Roškus <vilius@regattas.eu>",
6
6
  "license": "MIT",
@@ -9,9 +9,6 @@
9
9
  "url": "git+https://github.com/vroskus/library-health.git"
10
10
  },
11
11
  "main": "dist/index.js",
12
- "files": [
13
- "dist/index.js"
14
- ],
15
12
  "scripts": {
16
13
  "postinstall": "npm run build",
17
14
  "build": "tsc",
@@ -24,18 +21,19 @@
24
21
  "node-os-utils": "1.3.7"
25
22
  },
26
23
  "devDependencies": {
24
+ "@types/express": "4.17.17",
27
25
  "@types/jest": "29.5.0",
28
26
  "@types/node": "18.15.11",
29
- "@typescript-eslint/eslint-plugin": "5.53.0",
30
- "@typescript-eslint/parser": "5.53.0",
31
- "eslint": "8.34.0",
27
+ "@typescript-eslint/eslint-plugin": "5.58.0",
28
+ "@typescript-eslint/parser": "5.58.0",
29
+ "eslint": "8.38.0",
32
30
  "eslint-config-airbnb-base": "15.0.0",
33
31
  "eslint-config-airbnb-typescript": "17.0.0",
34
32
  "eslint-plugin-import": "2.27.5",
35
33
  "eslint-plugin-import-newlines": "1.3.1",
36
34
  "eslint-plugin-react": "7.32.2",
37
- "eslint-plugin-sort": "2.4.0",
35
+ "eslint-plugin-sort": "2.7.1",
38
36
  "npm-check": "6.0.1",
39
37
  "typescript": "4.9.5"
40
38
  }
41
- }
39
+ }
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ // Global Types
3
+ import type {
4
+ Request as $Request,
5
+ Response as $Response,
6
+ } from 'express';
7
+
8
+ // Helpers
9
+ import os from 'os';
10
+ import osUtils from 'node-os-utils'; // Types
11
+
12
+ type $LoadValue = Array<number>;
13
+ type $DiskValue = {
14
+ freeGb: string;
15
+ freePercentage: string;
16
+ totalGb: string;
17
+ usedGb: string;
18
+ usedPercentage: string;
19
+ };
20
+ type $MemValue = {
21
+ freeMemMb: number;
22
+ freeMemPercentage: number;
23
+ totalMemMb: number;
24
+ usedMemMb: number;
25
+ };
26
+ type $UptimeValue = {
27
+ container: number;
28
+ os: number;
29
+ };
30
+ type $SystemValues = {
31
+ disk: $DiskValue;
32
+ load: $LoadValue;
33
+ mem: $MemValue;
34
+ uptime: $UptimeValue;
35
+ };
36
+
37
+ type $GetSystemValues = () => Promise<$SystemValues>;
38
+
39
+ const getSystemValues: $GetSystemValues = async () => {
40
+ const load = await osUtils.cpu.loadavg();
41
+ const disk = await osUtils.drive.info();
42
+ const mem = await osUtils.mem.info();
43
+ const uptime = {
44
+ container: process.uptime(),
45
+ os: os.uptime(),
46
+ };
47
+
48
+ return {
49
+ disk,
50
+ load,
51
+ mem,
52
+ uptime,
53
+ };
54
+ };
55
+
56
+ type $HealthRoute = (req: $Request, res: $Response) => Promise<void>;
57
+
58
+ export const healthRoute: $HealthRoute = async (req, res) => {
59
+ const output = await getSystemValues();
60
+
61
+ res.json(output);
62
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "types": ["node", "jest"],
5
+ "module": "commonjs",
6
+ "esModuleInterop": true,
7
+ "declaration": true,
8
+ "noImplicitAny": false,
9
+ "removeComments": true,
10
+ "noLib": false,
11
+ "emitDecoratorMetadata": true,
12
+ "experimentalDecorators": true,
13
+ "target": "es6",
14
+ "sourceMap": true,
15
+ "lib": [
16
+ "es6"
17
+ ]
18
+ },
19
+ "exclude": [
20
+ "node_modules",
21
+ "./dist/**/*"
22
+ ],
23
+ "include": [
24
+ "./src"
25
+ ]
26
+ }