Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/graphql / dist / graphql-modules / pm2 / transform.js
Size: Mime:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fixture_1 = require("./fixture");
exports.fromProcessDescriptionListToResponse = (list) => {
    if (list.length === 0) {
        console.warn('[@skava/graphql]{pm2} had empty list of processes');
        return fixture_1.fixture;
    }
    const [description] = list;
    const pm2env = {
        cwd: description.pm2_env.pm_cwd,
        errorLogPath: description.pm2_env.pm_err_log_path,
        logPath: description.pm2_env.pm_out_log_path,
        restartTime: description.pm2_env.restart_time,
        status: description.pm2_env.status,
        executionPath: description.pm2_env.pm_exec_path,
    };
    return {
        processId: description.pid,
        processManagerProcessId: description.pm_id,
        env: pm2env,
        monitor: description.monit,
    };
};
/** @todo typings */
const parse_1 = __importDefault(require("date-fns/parse"));
const is_before_1 = __importDefault(require("date-fns/is_before"));
const is_after_1 = __importDefault(require("date-fns/is_after"));
const distance_in_words_to_now_1 = __importDefault(require("date-fns/distance_in_words_to_now"));
const exotic_1 = require("exotic");
exports.fromLogListToFormatted = (list) => {
    return list.map(exports.fromLogToFormatted);
};
exports.fromLogToFormatted = (item) => {
    const timestamp = item.timestamp ? distance_in_words_to_now_1.default(item.timestamp) : 'missing timestamp!';
    return {
        timestampFull: item.timestamp,
        timestamp,
        correlationId: item.correlationId,
        message: item.message,
    };
};
exports.fromLogArgsToCoerced = (args) => {
    const before = exotic_1.isNonEmptyString(args.before) ? parse_1.default(args.before) : '';
    const after = exotic_1.isNonEmptyString(args.after) ? parse_1.default(args.after) : '';
    const matches = exotic_1.isString(args.matches) && args.matches.includes('/')
        ? new RegExp(args.matches, 'gmi')
        : args.matches || '';
    return { before, after, matches };
};
exports.isRawArgs = (args) => !!args.password;
exports.filterLogListForArgs = (list, rawArgs) => {
    const args = exports.isRawArgs(rawArgs) ? exports.fromLogArgsToCoerced(rawArgs) : rawArgs;
    return list.filter(item => {
        const date = parse_1.default(item.timestamp);
        // 1st before 2nd
        if (args.before && !is_before_1.default(date, args.before)) {
            // console.debug('[@skava/graphql]{logs.transform} removing `before`')
            return false;
        }
        // 1st after 2nd
        if (args.after && !is_after_1.default(date, args.after)) {
            // console.debug('[@skava/graphql]{logs.transform} removing `after`')
            return false;
        }
        // @todo truthy fix
        if (args.matches) {
            // console.debug('[@skava/graphql]{logs.transform} removing `matches`')
            if (exotic_1.isString(args.matches)) {
                return item.message && item.message.includes(args.matches);
            }
            else {
                return args.matches.test(item.message);
            }
        }
        return true;
    });
};
//# sourceMappingURL=transform.js.map