{"size": 1351, "ext": "js", "max_stars_repo_path": "src/modules/common/keepAlive.js", "max_stars_repo_name": "ylorph/configurator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modules/common/keepAlive.js", "max_issues_repo_name": "ylorph/configurator", "max_issues_repo_issues_event_min_datetime": "2021-11-25T10:35:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T12:20:49.000Z", "max_forks_repo_path": "src/modules/common/keepAlive.js", "max_forks_repo_name": "ylorph/configurator", "max_forks_repo_forks_event_min_datetime": "2021-12-05T14:24:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-27T09:47:29.000Z"}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": 2, "avg_line_length": 29.3695652174, "max_line_length": 141, "alphanum_fraction": 0.6387860844}
import {validateKeepAlive} from "../lib/validate";

function formatKeepAlive(name, value) {
    return value !== undefined ? `&${name}=${value}` : "";
}

function getKeepAliveValueHelp(isEnabled, name, value) {
    return isEnabled
        && value !== undefined && value !== -1 && value < 10000
            ? `We recommend setting ${name} greater or equal to 10 000 ms.`
            : "";
}

export default class KeepAlive {
    constructor() {
        this.keepAliveInterval   = undefined;
        this.keepAliveTimeout    = undefined;

        this.isEnabled           = true;
        this.minKeepAlive        = -1;
        this.maxKeepAlive        = Number.MAX_SAFE_INTEGER;
    }

    validate(value, callback) {
        return validateKeepAlive(value, callback);
    }

    minKeepAliveTimeoutValueHelp() {
        return getKeepAliveValueHelp(this.isEnabled, "keepAliveTimeout", this.keepAliveTimeout);
    }

    minKeepAliveIntervalValueHelp() {
        return getKeepAliveValueHelp(this.isEnabled, "keepAliveInterval", this.keepAliveInterval);
    }

    getConnectionStringValue() {
        if(!this.isEnabled) {
            return "&keepAliveInterval=-1&keepAliveTimeout=-1";
        }

        return `${formatKeepAlive("keepAliveTimeout", this.keepAliveTimeout)}${formatKeepAlive("keepAliveInterval", this.keepAliveInterval)}`
    }


}
