chore(jsdoc):Linting fixes (#3703)

* fixed the lockfile having a different version

* jsdoc
pull/3499/head
Frank Elsinga 1 year ago committed by GitHub
parent d243cd84bf
commit d6302198f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

4
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "uptime-kuma", "name": "uptime-kuma",
"version": "1.23.0", "version": "1.23.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "uptime-kuma", "name": "uptime-kuma",
"version": "1.23.0", "version": "1.23.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@grpc/grpc-js": "~1.7.3", "@grpc/grpc-js": "~1.7.3",

@ -134,7 +134,10 @@ class Database {
} }
/** /**
* * Read the database config
* @throws {Error} If the config is invalid
* @typedef {string|undefined} envString
* @returns {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString}} Database config
*/ */
static readDBConfig() { static readDBConfig() {
let dbConfig; let dbConfig;
@ -153,7 +156,9 @@ class Database {
} }
/** /**
* @param dbConfig * @typedef {string|undefined} envString
* @param {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString}} dbConfig the database configuration that should be written
* @returns {void}
*/ */
static writeDBConfig(dbConfig) { static writeDBConfig(dbConfig) {
fs.writeFileSync(path.join(Database.dataDir, "db-config.json"), JSON.stringify(dbConfig, null, 4)); fs.writeFileSync(path.join(Database.dataDir, "db-config.json"), JSON.stringify(dbConfig, null, 4));
@ -161,10 +166,8 @@ class Database {
/** /**
* Connect to the database * Connect to the database
* @param {boolean} testMode Should the connection be * @param {boolean} testMode Should the connection be started in test mode?
* started in test mode? * @param {boolean} autoloadModels Should models be automatically loaded?
* @param {boolean} autoloadModels Should models be
* automatically loaded?
* @param {boolean} noLog Should logs not be output? * @param {boolean} noLog Should logs not be output?
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
@ -292,8 +295,9 @@ class Database {
} }
/** /**
* @param testMode @param {boolean} testMode Should the connection be started in test mode?
* @param noLog @param {boolean} noLog Should logs not be output?
@returns {Promise<void>}
*/ */
static async initSQLite(testMode, noLog) { static async initSQLite(testMode, noLog) {
await R.exec("PRAGMA foreign_keys = ON"); await R.exec("PRAGMA foreign_keys = ON");
@ -321,7 +325,8 @@ class Database {
} }
/** /**
* * Initialize MariaDB
* @returns {Promise<void>}
*/ */
static async initMariaDB() { static async initMariaDB() {
log.debug("db", "Checking if MariaDB database exists..."); log.debug("db", "Checking if MariaDB database exists...");
@ -368,6 +373,7 @@ class Database {
/** /**
* Patch the database for SQLite * Patch the database for SQLite
* @returns {Promise<void>}
* @deprecated * @deprecated
*/ */
static async patchSqlite() { static async patchSqlite() {
@ -650,7 +656,7 @@ class Database {
} }
/** /**
* * @returns {string} Get the SQL for the current time plus a number of hours
*/ */
static sqlHourOffset() { static sqlHourOffset() {
if (Database.dbConfig.type === "sqlite") { if (Database.dbConfig.type === "sqlite") {

@ -18,13 +18,17 @@ class EmbeddedMariaDB {
socketPath = this.runDir + "/mysqld.sock"; socketPath = this.runDir + "/mysqld.sock";
/**
* @type {ChildProcessWithoutNullStreams}
* @private
*/
childProcess = null; childProcess = null;
running = false; running = false;
started = false; started = false;
/** /**
* @returns {EmbeddedMariaDB} * @returns {EmbeddedMariaDB} The singleton instance
*/ */
static getInstance() { static getInstance() {
if (!EmbeddedMariaDB.instance) { if (!EmbeddedMariaDB.instance) {
@ -34,14 +38,15 @@ class EmbeddedMariaDB {
} }
/** /**
* * @returns {boolean} If the singleton instance is created
*/ */
static hasInstance() { static hasInstance() {
return !!EmbeddedMariaDB.instance; return !!EmbeddedMariaDB.instance;
} }
/** /**
* * Start the embedded MariaDB
* @returns {Promise<void>|void} A promise that resolves when the MariaDB is started or void if it is already started
*/ */
start() { start() {
if (this.childProcess) { if (this.childProcess) {
@ -103,7 +108,8 @@ class EmbeddedMariaDB {
} }
/** /**
* * Stop all the child processes
* @returns {void}
*/ */
stop() { stop() {
if (this.childProcess) { if (this.childProcess) {
@ -113,7 +119,8 @@ class EmbeddedMariaDB {
} }
/** /**
* * Install MariaDB if it is not installed and make sure the `runDir` directory exists
* @returns {void}
*/ */
initDB() { initDB() {
if (!fs.existsSync(this.mariadbDataDir)) { if (!fs.existsSync(this.mariadbDataDir)) {
@ -146,7 +153,8 @@ class EmbeddedMariaDB {
} }
/** /**
* * Initialise the "kuma" database in mariadb if it does not exist
* @returns {Promise<void>}
*/ */
async initDBAfterStarted() { async initDBAfterStarted() {
const connection = mysql.createConnection({ const connection = mysql.createConnection({

@ -291,7 +291,8 @@ class Monitor extends BeanModel {
} }
/** /**
* * Get if game dig should only use the port which was provided
* @returns {boolean} gamedig should only use the provided port
*/ */
getGameDigGivenPortOnly() { getGameDigGivenPortOnly() {
return Boolean(this.gamedigGivenPortOnly); return Boolean(this.gamedigGivenPortOnly);

@ -8,24 +8,32 @@ const { allowDevAllOrigin } = require("./util-server");
const mysql = require("mysql2/promise"); const mysql = require("mysql2/promise");
/** /**
* A standalone express app that is used to setup database * A standalone express app that is used to setup a database
* It is used when db-config.json and kuma.db are not found or invalid * It is used when db-config.json and kuma.db are not found or invalid
* Once it is configured, it will shutdown and start the main server * Once it is configured, it will shut down and start the main server
*/ */
class SetupDatabase { class SetupDatabase {
/** /**
* Show Setup Page * Show Setup Page
* @type {boolean} * @type {boolean}
*/ */
needSetup = true; needSetup = true;
/**
* If the server has finished the setup
* @type {boolean}
* @private
*/
runningSetup = false; runningSetup = false;
/**
* @inheritDoc
* @type {UptimeKumaServer}
* @private
*/
server; server;
/** /**
* @param args * @param {object} args The arguments passed from the command line
* @param server * @param {UptimeKumaServer} server the main server instance
*/ */
constructor(args, server) { constructor(args, server) {
this.server = server; this.server = server;
@ -76,21 +84,25 @@ class SetupDatabase {
/** /**
* Show Setup Page * Show Setup Page
* @returns {boolean} true if the setup page should be shown
*/ */
isNeedSetup() { isNeedSetup() {
return this.needSetup; return this.needSetup;
} }
/** /**
* * Check if the embedded MariaDB is enabled
* @returns {boolean} true if the embedded MariaDB is enabled
*/ */
isEnabledEmbeddedMariaDB() { isEnabledEmbeddedMariaDB() {
return process.env.UPTIME_KUMA_ENABLE_EMBEDDED_MARIADB === "1"; return process.env.UPTIME_KUMA_ENABLE_EMBEDDED_MARIADB === "1";
} }
/** /**
* @param hostname * Start the setup-database server
* @param port * @param {string} hostname where the server is listening
* @param {number} port where the server is listening
* @returns {Promise<void>}
*/ */
start(hostname, port) { start(hostname, port) {
return new Promise((resolve) => { return new Promise((resolve) => {

@ -8,6 +8,10 @@ const { R } = require("redbean-node");
* Calculates the uptime of a monitor. * Calculates the uptime of a monitor.
*/ */
class UptimeCalculator { class UptimeCalculator {
/**
* @private
* @type {{string:UptimeCalculator}}
*/
static list = {}; static list = {};
@ -17,11 +21,16 @@ class UptimeCalculator {
*/ */
static currentDate = null; static currentDate = null;
/**
* monitorID the id of the monitor
* @type {number}
*/
monitorID; monitorID;
/** /**
* Recent 24-hour uptime, each item is a 1-minute interval * Recent 24-hour uptime, each item is a 1-minute interval
* Key: {number} DivisionKey * Key: {number} DivisionKey
* @type {LimitQueue<number,string>}
*/ */
minutelyUptimeDataList = new LimitQueue(24 * 60); minutelyUptimeDataList = new LimitQueue(24 * 60);
@ -38,8 +47,10 @@ class UptimeCalculator {
lastMinutelyStatBean = null; lastMinutelyStatBean = null;
/** /**
* @param monitorID * Get the uptime calculator for a monitor
* @returns {Promise<UptimeCalculator>} * Initializes and returns the monitor if it does not exist
* @param {number} monitorID the id of the monitor
* @returns {Promise<UptimeCalculator>} UptimeCalculator
*/ */
static async getUptimeCalculator(monitorID) { static async getUptimeCalculator(monitorID) {
if (!UptimeCalculator.list[monitorID]) { if (!UptimeCalculator.list[monitorID]) {
@ -50,7 +61,9 @@ class UptimeCalculator {
} }
/** /**
* @param monitorID * Remove a monitor from the list
* @param {number} monitorID the id of the monitor
* @returns {Promise<void>}
*/ */
static async remove(monitorID) { static async remove(monitorID) {
delete UptimeCalculator.list[monitorID]; delete UptimeCalculator.list[monitorID];
@ -74,7 +87,9 @@ class UptimeCalculator {
} }
/** /**
* @param {number} monitorID * Initialize the uptime calculator for a monitor
* @param {number} monitorID the id of the monitor
* @returns {Promise<void>}
*/ */
async init(monitorID) { async init(monitorID) {
this.monitorID = monitorID; this.monitorID = monitorID;
@ -300,8 +315,8 @@ class UptimeCalculator {
/** /**
* Flat status to UP or DOWN * Flat status to UP or DOWN
* @param {number} status * @param {number} status the status which schould be turned into a flat status
* @returns {number} * @returns {UP|DOWN|PENDING} The flat status
* @throws {Error} Invalid status * @throws {Error} Invalid status
*/ */
flatStatus(status) { flatStatus(status) {
@ -317,8 +332,10 @@ class UptimeCalculator {
} }
/** /**
* @param {number} num * @param {number} num the number of data points which are expected to be returned
* @param {string} type "day" | "minute" * @param {"day" | "minute"} type the type of data which is expected to be returned
* @returns {UptimeDataResult} UptimeDataResult
* @throws {Error} The maximum number of minutes greater than 1440
*/ */
getData(num, type = "day") { getData(num, type = "day") {
let key; let key;

@ -1,20 +1,22 @@
/** /**
* An object that can be used as an array with a key * An object that can be used as an array with a key
* Like PHP's array * Like PHP's array
* @template K
* @template V
*/ */
class ArrayWithKey { class ArrayWithKey {
__stack = [];
/** /**
* * All keys that are stored in the current object
* @type {K[]}
* @private
*/ */
constructor() { __stack = [];
}
/** /**
* @param key * Push an element to the end of the array
* @param value * @param {K} key The key of the element
* @param {V} value The value of the element
* @returns {void}
*/ */
push(key, value) { push(key, value) {
this[key] = value; this[key] = value;
@ -22,7 +24,8 @@ class ArrayWithKey {
} }
/** /**
* * Get the last element and remove it from the array
* @returns {V|undefined} The first value, or undefined if there is no element to pop
*/ */
pop() { pop() {
let key = this.__stack.pop(); let key = this.__stack.pop();
@ -32,7 +35,8 @@ class ArrayWithKey {
} }
/** /**
* * Get the last key
* @returns {K|null} The last key, or null if the array is empty
*/ */
getLastKey() { getLastKey() {
if (this.__stack.length === 0) { if (this.__stack.length === 0) {
@ -42,7 +46,8 @@ class ArrayWithKey {
} }
/** /**
* * Get the first element
* @returns {{key:K,value:V}|null} The first element, or null if the array is empty
*/ */
shift() { shift() {
let key = this.__stack.shift(); let key = this.__stack.shift();
@ -55,15 +60,16 @@ class ArrayWithKey {
} }
/** /**
* * Get the length of the array
* @returns {number} Amount of elements stored
*/ */
length() { length() {
return this.__stack.length; return this.__stack.length;
} }
/** /**
* Get the last element * Get the last value
* @returns {*|null} The last element, or null if the array is empty * @returns {V|null} The last element without removing it, or null if the array is empty
*/ */
last() { last() {
let key = this.getLastKey(); let key = this.getLastKey();

@ -6,11 +6,22 @@ const { ArrayWithKey } = require("./array-with-key");
*/ */
class LimitQueue extends ArrayWithKey { class LimitQueue extends ArrayWithKey {
/**
* The limit of the queue after which the first element will be removed
* @private
* @type {number}
*/
__limit; __limit;
/**
* The callback function when the queue exceeds the limit
* @private
* @callback onExceedCallback
* @param {{key:K,value:V}|nul} item
*/
__onExceed = null; __onExceed = null;
/** /**
* @param {number} limit * @param {number} limit The limit of the queue after which the first element will be removed
*/ */
constructor(limit) { constructor(limit) {
super(); super();

@ -166,6 +166,7 @@ export default {
/** /**
* Loads toast timeout settings from storage to component data. * Loads toast timeout settings from storage to component data.
* @returns {void}
*/ */
loadToastTimeoutSettings() { loadToastTimeoutSettings() {
const successTimeout = localStorage.toastSuccessTimeout; const successTimeout = localStorage.toastSuccessTimeout;

@ -197,6 +197,7 @@ export default {
methods: { methods: {
/** /**
* Clear all toast notifications. * Clear all toast notifications.
* @returns {void}
*/ */
clearToasts() { clearToasts() {
toast.clear(); toast.clear();

@ -353,18 +353,18 @@ test("Test get1YearUptime (1 check per day)", async (t) => {
/** /**
* Code from here: https://stackoverflow.com/a/64550489/1097815 * Code from here: https://stackoverflow.com/a/64550489/1097815
* @returns {{rss: string, heapTotal: string, heapUsed: string, external: string}} Current memory usage
*/ */
function memoryUsage() { function memoryUsage() {
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`; const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
const memoryData = process.memoryUsage(); const memoryData = process.memoryUsage();
const memoryUsage = { return {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`, rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`, heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`, heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`, external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
}; };
return memoryUsage;
} }
test("Worst case", async (t) => { test("Worst case", async (t) => {

Loading…
Cancel
Save