feat: Created a mini nodeJS server with NewMan for testing without PostMan GUI.

This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
Simon Priet
2021-09-08 14:01:19 +02:00
parent 5fbd7c88fa
commit e69a613a37
5610 changed files with 740417 additions and 3 deletions

157
node_modules/intel/lib/config.js generated vendored Normal file
View File

@@ -0,0 +1,157 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const path = require('path');
const util = require('util');
const intel = require('./');
const Formatter = require('./formatter');
const Filter = require('./filter');
const INTEL_PREFIX = 'intel/';
function req(str, root) {
if (str.indexOf(INTEL_PREFIX) === 0) {
str = str.replace(INTEL_PREFIX, './');
} else if (str.indexOf('./') === 0 || str.indexOf('../') === 0) {
str = path.join(root || process.cwd(), str);
}
return require(str);
}
function isObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}
function evalFunction(source) {
/*jshint evil:true*/
var fn = Function('return (' + String(source).trim() + ');')();
if (!(fn instanceof Function)) {
throw new Error('function parameter did not parse as a function');
}
return fn;
}
function configureFormatter(formatter, options) {
if (formatter.formatFn) {
var customFormatter = new Formatter();
if (formatter.formatFn instanceof Function) {
customFormatter.format = formatter.formatFn;
} else {
customFormatter.format = evalFunction(formatter.formatFn);
}
return customFormatter;
}
var FormatterClass = formatter['class'] || Formatter;
if (typeof FormatterClass === 'string') {
FormatterClass = req(FormatterClass, options.root);
}
return new FormatterClass(formatter);
}
function configureFilter(filterOptions, options) {
var FilterClass = filterOptions['class'] || Filter;
if (typeof FilterClass === 'string') {
FilterClass = req(FilterClass, options.root);
}
if (isObject(filterOptions)) {
var fOpts = filterOptions;
var re = fOpts.regexp || fOpts.regex || fOpts.re;
var fn = fOpts.function || fOpts.fn;
if (re) {
filterOptions = new RegExp(re, fOpts.flags);
} else if (fn) {
filterOptions = evalFunction(fn);
}
}
return new FilterClass(filterOptions);
}
function configureHandler(handler, options) {
var HandlerClass = handler['class'];
if (typeof HandlerClass === 'string') {
HandlerClass = req(HandlerClass, options.root);
}
delete handler['class'];
if (handler.formatter) {
handler.formatter = options.formatters[handler.formatter];
}
var hndlr = new HandlerClass(handler);
if (handler.filters) {
handler.filters.forEach(function eachHandler(fname) {
hndlr.addFilter(options.filters[fname]);
});
}
return hndlr;
}
function getHandler(name, options) {
var handler = options.handlers && options.handlers[name];
if (!handler) {
var errStr = util.format('Handler "%s" is not defined in config', name);
throw new Error(errStr);
}
if (typeof handler.handle !== 'function') {
handler = options.handlers[name] = configureHandler(handler, options);
}
return handler;
}
function configureLogger(name, loggerOptions, options) {
var logger = intel.getLogger(name);
if (loggerOptions.level != null) {
logger.setLevel(loggerOptions.level);
}
if (loggerOptions.handlers) {
loggerOptions.handlers.forEach(function eachHandler(hName) {
logger.addHandler(getHandler(hName, options));
});
}
if (loggerOptions.filters) {
loggerOptions.filters.forEach(function eachHandler(fname) {
logger.addFilter(options.filters[fname]);
});
}
if (loggerOptions.propagate != null) {
logger.propagate = loggerOptions.propagate;
}
if (loggerOptions.handleExceptions) {
logger.handleExceptions(loggerOptions.exitOnError);
}
}
module.exports = function config(options) {
// lets do formatters and filters first, since they dont depend on anything
// then handlers, since they can depend on formatters
// and then loggers, since they can depend on handlers
var formatters = options.formatters || {};
for (var f in formatters) {
formatters[f] = configureFormatter(formatters[f], options);
}
var filters = options.filters || {};
for (var fi in filters) {
filters[fi] = configureFilter(filters[fi], options);
}
if (options.handlers) {
intel.basicConfig({ null: true});
}
var loggers = options.loggers || {};
for (var l in loggers) {
configureLogger(l, loggers[l], options);
}
if (options.console) {
var consoleOpts = isObject(options.console) ? options.console : {};
consoleOpts.__trace = config;
intel.console(consoleOpts);
}
};

307
node_modules/intel/lib/console.js generated vendored Normal file
View File

@@ -0,0 +1,307 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const path = require('path');
const util = require('util');
const chalk = require('chalk');
const dbug = require('dbug');
const stack = require('stack-trace');
const utc = require('utcstring');
const intel = require('./');
const ALIASES = [
'trace',
'debug',
'info',
'warn',
'error'
];
function copyProperties(source, target, props) {
props.forEach(function(prop) {
target[prop] = source[prop];
});
}
var ORIGINAL_METHODS = {};
const METHOD_NAMES = [
'trace',
'debug',
'dir',
'error',
'info',
'log',
'warn'
];
var ORIGINAL_STDERR;
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
var root;
var ignore;
var parentLogger;
var basename;
function getLoggerName(debugName) {
var trace = stack.get();
// walk up the stack until we find a function that isn't from this
// module. that's the calling module.
// ALSO: 'console.js' could be on the stack if console.trace() or
// something similar was called, cause we don't modify those, since
// they internally call console.log(), which is us!
var filename;
var debug = [];
if (debugName) {
debug = [
// debug@0.x
path.join('node_modules', 'debug', 'lib', 'debug.js'),
// debug@1.x
path.join('node_modules', 'debug', 'node.js'),
path.join('node_modules', 'debug', 'debug.js'),
// dbug@0.x
path.join('node_modules', 'dbug', 'lib', 'dbug.js'),
path.join('node_modules', 'dbug', 'index.js')
];
}
function skip(name) {
if (name === __filename || name === 'console.js') {
return true;
}
return debug.some(function(d) {
return endsWith(name, d);
});
}
for (var i = 0, len = trace.length; i < len; i++) {
filename = path.normalize(trace[i].getFileName());
if (!skip(filename)) {
break;
}
}
var topName = basename || path.basename(root);
topName = topName.replace(path.extname(topName), '');
var moduleName = path.join(topName, path.relative(root, filename));
moduleName = moduleName.replace(path.extname(moduleName), '');
moduleName = moduleName.replace(/[\\\/]/g, '.');
// lib is the defacto place to store js files, but removing lib looks
// better: connect.lib.session -> connect.session
moduleName = moduleName.replace(/\.lib\./g, '.');
// index.js filename shouldn't be used, since it's really the folder
// up. better: gryphon.index -> gryphon
moduleName = moduleName.replace(/\.index/g, '');
if (debugName) {
// clean up duplicated parts of the name
// ex: node_modules.intel.logger.intel.logger =>
// node_modules.intel.logger
if (!endsWith(moduleName, debugName)) {
moduleName += '.' + debugName;
}
}
if (parentLogger) {
moduleName = parentLogger + '.' + moduleName;
}
return moduleName;
}
function setRoot(r) {
root = r;
}
function setIgnore(i) {
if (typeof i === 'string') {
i = [i];
}
ignore = i;
}
const DEBUG_COLORED_RE = new RegExp([
'^',
' ', // starts with 2 spaces. yea really
'\\u001b\\[\\d{1,2};1m', // colored debug has colors
'(.+)', // logger name
'\\u001b\\[\\d?0m', // color end
'(.+)', // message
'\n?', // debug 2.0 addes a newline
'$'
].join(''));
const DBUG_LEVELS = ['debug', 'info', 'warn', 'error'];
function getLoggerLevel(name) {
var i = DBUG_LEVELS.length;
while (i--) {
var level = DBUG_LEVELS[i];
if (endsWith(name, '.' + level)) {
return level;
}
}
return 'debug';
}
function dbugName(name) {
if (!name) {
return;
}
if (name.indexOf('.') === -1) {
return name;
}
var level = getLoggerLevel(name.toLowerCase());
level = new RegExp('\\.' + level + '$', 'i');
return name.replace(level, '');
}
function parseDebug(args) {
// O_O
// Dear reader: I'm so sorry.
var str = String(args[0]);
// is it colored debug() ?
var match = str.match(DEBUG_COLORED_RE);
if (match) {
var logger = chalk.stripColor(match[1]).trim();
var msg = chalk.stripColor(match[2]).trim();
args[0] = msg; // overwrite the message portion
return logger.replace(/:/g, '.');
} else if (utc.has(str)) {
str = str.replace(utc.get(str), '').trim();
var logger = str.split(' ').shift();
var msg = str.replace(logger, '').trim();
args[0] = msg;
return logger.replace(/:/g, '.');
}
}
// cached loggers that hook into dbug.__log
// this way, we don't format a level message, and then parse it with
// regex, just to format a new message in intel
// ALSO: we only get a stacktrace once, and then save the name, so
// PERFORMANCE WIN!
var dbugLoggers = {};
function dbugHook(name, level, args) {
var logger = dbugLoggers[name];
if (!logger) {
logger = dbugLoggers[name] =
intel.getLogger(getLoggerName(name.replace(/:/g, '.')));
}
logger[level].apply(logger, args);
}
var isDebugging = false;
var __log = dbug.__log;
function setDebug(debug) {
if (debug === true) {
process.env.DEBUG = dbug.env = '*';
} else if (debug === false) {
process.env.DEBUG = dbug.env = '';
} else if (debug) {
if (process.env.DEBUG) {
process.env.DEBUG += ',' + debug;
dbug.env = process.env.DEBUG;
} else {
process.env.DEBUG = dbug.env = '' + debug;
}
}
isDebugging = !!debug;
dbug.__log = dbugHook;
}
function setLoggerBaseName(bn){
basename = bn;
}
function deliver(method, args) {
var debugged = isDebugging && parseDebug(args);
var name = getLoggerName(dbugName(debugged));
var i = ignore.length;
var logger = intel.getLogger(name);
name = logger._name;
while (i--) {
if (name.indexOf(ignore[i]) === 0) {
if (method === 'stderr') {
ORIGINAL_STDERR.call(process.stderr, args[0]);
} else {
ORIGINAL_METHODS[method].apply(console, args);
}
return;
}
}
if (debugged) {
method = getLoggerLevel(debugged);
}
var level = ALIASES.indexOf(method) !== -1 ? method : 'debug';
logger[level].apply(logger, args);
}
function overrideConsole(options) {
options = options || {};
setRoot(options.root || path.join(
stack.get(options.__trace || overrideConsole)[0].getFileName(),
'..'
));
setIgnore(options.ignore || []);
parentLogger = options.logger;
setDebug(options.debug);
setLoggerBaseName(options.basename);
if (!ORIGINAL_METHODS.log) {
copyProperties(console, ORIGINAL_METHODS, METHOD_NAMES);
}
if (!ORIGINAL_STDERR) {
ORIGINAL_STDERR = process.stderr.write;
}
ALIASES.forEach(function(method) {
console[method] = function alias(){
deliver(method, arguments);
};
});
console.log = function log() {
deliver('log', arguments);
};
console.dir = function dir(obj) {
deliver('dir', [util.inspect(obj)]);
};
process.stderr.write = function write(str) {
deliver('stderr', [str]);
return true;
};
}
function restoreConsole() {
for (var name in ORIGINAL_METHODS) {
if (ORIGINAL_METHODS.hasOwnProperty(name) && ORIGINAL_METHODS[name]) {
console[name] = ORIGINAL_METHODS[name];
}
}
copyProperties({}, ORIGINAL_METHODS, METHOD_NAMES);
dbug.__log = __log;
if (ORIGINAL_STDERR) {
process.stderr.write = ORIGINAL_STDERR;
ORIGINAL_STDERR = undefined;
}
}
module.exports = exports = overrideConsole;
exports.restore = restoreConsole;

44
node_modules/intel/lib/filter.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
function nameFilter(record) {
var filter = this._filter;
if (filter === record.name) {
return true;
} else if (record.name.indexOf(filter) === -1) {
return false;
} else {
return record.name[filter.length] === '.';
}
}
function regexpFilter(record) {
return this._filter.test(record.message);
}
function Filter(filter) {
// valid filters: regexp, string, function
var type = typeof filter;
if (type === 'function') {
this.filter = filter;
} else if (type === 'string') {
this._filter = filter;
this.filter = nameFilter;
} else if (util.isRegExp(filter)) {
this._filter = filter;
this.filter = regexpFilter;
}
}
Filter.prototype = {
filter: function() {
throw new Error('Filter type was not defined.');
}
};
module.exports = Filter;

50
node_modules/intel/lib/filterer.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function filter(record) {
var i = this._filters.length;
while (i--) {
if (!this._filters[i].filter(record)) {
return false;
}
}
return true;
}
function noop() { return true; }
function Filterer() {
this._filters = [];
this.filter = noop;
}
Filterer.prototype = {
__toggleFilter: function toggleFilter() {
this.filter = this.filter === noop ? filter : noop;
},
addFilter: function addFilter(_filter) {
if (this._filters.length === 0) {
this.__toggleFilter();
}
this._filters.push(_filter);
return this;
},
removeFilter: function removeFilter(_filter) {
var index = this._filters.indexOf(_filter);
if (index !== -1) {
this._filters.splice(index, 1);
}
if (this._filters.length === 0) {
this.__toggleFilter();
}
return this;
}
};
module.exports = Filterer;

125
node_modules/intel/lib/formatter.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const chalk = require('chalk');
const strftime = require('strftime');
const printf = require('./utils/printf');
const json = require('./utils/json');
chalk.enabled = true;
const COLORS = {
'TRACE': chalk.bold.bgBlue,
'VERBOSE': chalk.bold.magenta,
'DEBUG': chalk.bold.cyan,
'INFO': chalk.bold.green,
'WARN': chalk.bold.yellow,
'ERROR': chalk.bold.red,
'CRITICAL': chalk.bold.bgRed
};
const BOLD = chalk.bold;
const TO_JSON = '%O';
const MESSAGE_ONLY = '%(message)s';
const BASIC_FORMAT = '%(name)s.%(levelname)s: %(message)s';
function messageOnly(record) {
return record.message;
}
function basicFormat(record) {
return record.name + '.' + record.levelname + ': ' + record.message;
}
function sprintf(record) {
return printf(this._format, record);
}
function formatDate(record) {
record.date = strftime(this._datefmt, new Date(record.timestamp));
}
function noop() {
}
function optimize() {
switch (this._format) {
// faster shortcuts
case MESSAGE_ONLY:
this.__format = messageOnly;
break;
case BASIC_FORMAT:
this.__format = basicFormat;
break;
case TO_JSON:
this.__format = json;
break;
// bring on the regexp
default:
this.__format = sprintf;
}
this.__time = this._usesTime ? formatDate : noop;
}
function Formatter(options) {
options = options || {};
if (typeof options === 'string') {
options = { format: options };
}
this._format = options.format || this._format;
this._datefmt = options.datefmt || this._datefmt;
this._strip = options.strip || this._strip;
this._colorize = this._strip ? false : options.colorize || this._colorize;
this._usesTime = this._format.indexOf('%(date)s') !== -1;
optimize.call(this);
}
Formatter.prototype = {
_format: MESSAGE_ONLY,
_datefmt: '%Y-%m-%d %H:%M:%S',
_colorize: false,
_strip: false,
_usesTime: false,
format: function format(record) {
this.__time(record);
var levelname = record.levelname;
var name = record.name;
if (this._colorize) {
var colorize = COLORS[levelname];
if (colorize) {
record.levelname = colorize(levelname);
}
// else levelname doesnt have a color
record.name = BOLD(name);
}
var formatted = this.__format(record);
if (record.stack && this._format !== TO_JSON) {
formatted += record.stack;
}
record.levelname = levelname;
record.name = name;
record.date = undefined;
if (this._strip) {
formatted = chalk.stripColor(formatted);
}
return formatted;
}
};
module.exports = Formatter;

33
node_modules/intel/lib/handlers/console.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
const Handler = require('./handler');
const StreamHandler = require('./stream');
const LEVELS = require('../levels');
function ConsoleHandler(options) {
options = options || {};
options.stream = process.stdout;
this._out = new StreamHandler(options);
options.stream = process.stderr;
this._err = new StreamHandler(options);
Handler.call(this, options);
}
util.inherits(ConsoleHandler, Handler);
ConsoleHandler.prototype.emit = function consoleEmit(record) {
var handler = (record.level >= LEVELS.WARN) ? this._err : this._out;
handler.emit(record);
};
ConsoleHandler.prototype.setFormatter = function setFormatter(formatter) {
Handler.prototype.setFormatter.call(this, formatter);
this._out.setFormatter(formatter);
this._err.setFormatter(formatter);
};
module.exports = ConsoleHandler;

25
node_modules/intel/lib/handlers/file.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const fs = require('fs');
const util = require('util');
const StreamHandler = require('./stream');
function FileHandler(options) {
if (typeof options === 'string') {
options = { file: options };
}
this._file = options.file;
options.stream = this._open();
StreamHandler.call(this, options);
}
util.inherits(FileHandler, StreamHandler);
FileHandler.prototype._open = function open() {
return fs.createWriteStream(this._file, { flags: 'a' });
};
module.exports = FileHandler;

79
node_modules/intel/lib/handlers/handler.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Formatter = require('../formatter');
const Filterer = require('../filterer');
const klass = require('../utils/klass');
const LEVELS = require('../levels');
const _defaultFormatter = new Formatter();
function emit(record) {
return this._emit(record);
}
function handleFilter(record) {
if (this.filter(record)) {
this.__emit(record);
}
}
function Handler(options) {
if (typeof options !== 'object') {
options = { level: options };
}
var level = options.level;
this.setLevel((level !== undefined) ? LEVELS.getLevel(level) : LEVELS.NOTSET);
this.setFormatter(options.formatter || _defaultFormatter);
this.handle = this.__emit;
Filterer.call(this, options);
}
klass(Handler).inherit(Filterer).mixin({
level: null,
_formatter: null,
__toggleFilter: function handlerToggleFilter() {
Filterer.prototype.__toggleFilter.call(this);
this.handle = this.handle === this.__emit ? handleFilter : this.__emit;
},
// sub-classes should override emit, not handle
_emit: function emit(/*record*/) {
throw new Error('Handler.emit must be implemented by sub-classes');
},
__emit: emit,
format: function format(record) {
return this._formatter.format(record);
},
setFormatter: function setFormatter(formatter) {
this._formatter = formatter;
return this;
},
setLevel: function setLevel(level) {
this.level = LEVELS.getLevel(level);
return this;
}
});
Object.defineProperty(Handler.prototype, 'emit', {
get: function() {
return this._emit;
},
set: function(val) {
if (typeof val !== 'function') {
throw new TypeError('emit must be a function');
}
this._emit = val;
}
});
module.exports = Handler;

20
node_modules/intel/lib/handlers/index.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const fs = require('fs');
fs.readdirSync(__dirname).forEach(function(file) {
if (file === 'index.js' || file === 'handler.js') {
return;
}
var handler = file.replace('.js', '');
var capital = handler[0].toUpperCase() + handler.substring(1);
Object.defineProperty(exports, capital, {
get: function() {
return require('./' + handler);
}
});
});

16
node_modules/intel/lib/handlers/null.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
const Handler = require('./handler');
function NullHandler() {
Handler.apply(this, arguments);
}
util.inherits(NullHandler, Handler);
NullHandler.prototype.emit = function nullEmit(){};
module.exports = NullHandler;

24
node_modules/intel/lib/handlers/stream.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
const Handler = require('./handler');
function StreamHandler(options) {
options = options || {};
if (!options.stream) {
options = { stream: options };
}
Handler.call(this, options);
this._stream = options.stream;
}
util.inherits(StreamHandler, Handler);
StreamHandler.prototype.emit = function streamEmit(record) {
this._stream.write(this.format(record) + '\n');
};
module.exports = StreamHandler;

77
node_modules/intel/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const dbug = require('dbug')('intel');
const Logger = require('./logger');
const Handler = require('./handlers/handler');
const handlers = require('./handlers');
const Formatter = require('./formatter');
const root = new Logger();
root.propagate = false;
root.setLevel(Logger.TRACE);
var oldHandle = root.handle;
root.handle = function handle() {
if (this._handlers.length === 0) {
root.basicConfig();
}
return oldHandle.apply(this, arguments);
};
const DEFAULT_FORMAT = '%(name)s.%(levelname)s: %(message)s';
root.basicConfig = function basicConfig(options) {
if (root._handlers.length) {
return;
}
dbug('basicConfig', options);
// available options:
// level, format, filename, stream
options = options || {};
var hdlr;
if (options.file) {
hdlr = new handlers.File({ file: options.file });
} else if (options.stream) {
hdlr = new handlers.Stream({ stream: options.stream });
} else if (options.null) {
hdlr = new handlers.Null();
} else {
hdlr = new handlers.Console();
}
hdlr.setFormatter(new Formatter(options.format || DEFAULT_FORMAT));
root.addHandler(hdlr);
if (options.level) {
root.setLevel(options.level);
}
root.handle = oldHandle;
};
root.Logger = Logger;
root.Handler = Handler;
root.handlers = handlers;
root.Formatter = Formatter;
root.Filter = require('./filter');
root.getLogger = function getLogger(name) {
return new Logger(name);
};
// lazy load it, since console depends on this module
Object.defineProperty(root, 'config', {
get: function() {
return require('./config');
}
});
Object.defineProperty(root, 'console', {
get: function() {
return require('./console');
}
});
module.exports = root;

47
node_modules/intel/lib/levels.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const LEVELS = module.exports = {};
[
'NOTSET',
'TRACE',
'VERBOSE',
'DEBUG',
'INFO',
'WARN',
'ERROR',
'CRITICAL'
].forEach(function(name, index) {
LEVELS[name] = index * 10;
});
const NUMBERS = {};
for (var levelname in LEVELS) {
NUMBERS[LEVELS[levelname]] = levelname;
}
// additional levels, but not canonical names
LEVELS.WARNING = LEVELS.WARN;
LEVELS.ALL = LEVELS.NOTSET;
LEVELS.NONE = Infinity;
LEVELS.getLevelName = function getLevelName(number) {
return NUMBERS[number];
};
LEVELS.getLevel = function getLevel(val) {
// 5 => 5
// '5' => 5
// 'five' => undefined
// 'debug' => 20
// 'DEBUG' = > 20
var level = Number(val);
if (isNaN(level)) {
level = LEVELS[String(val).toUpperCase()];
}
return level;
};

308
node_modules/intel/lib/logger.js generated vendored Normal file
View File

@@ -0,0 +1,308 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const assert = require('assert');
const dbug = require('dbug')('intel:logger');
const klass = require('./utils/klass');
const LEVELS = require('./levels');
const Filterer = require('./filterer');
const Record = require('./record');
const Trace = Record._Trace;
var __loggers = {};
var __levelCache = {};
const ROOT = 'root';
const DIVIDER = '.';
const OTHER_DIVIDERS = /[\/\\]/g;
function emptyStr() { return ''; }
function traceStr() { return 'Trace'; }
function getEffectiveParent(name) {
if (name === ROOT) {
return;
}
var parent;
while (name.indexOf(DIVIDER) !== -1 && !parent) {
name = name.substring(0, name.lastIndexOf(DIVIDER));
parent = __loggers[name];
}
return parent || __loggers[ROOT];
}
function getChildren(name) {
var children = [];
for (var k in __loggers) {
if ((name === ROOT || k.indexOf(name) === 0) &&
k !== name &&
getEffectiveParent(k) === __loggers[name]) {
children.push(__loggers[k]);
}
}
return children;
}
function logNoop() {}
function disableLevels(logger) {
for (var name in LEVELS) {
if (typeof LEVELS[name] === 'number') {
var level = LEVELS[name];
name = name.toLowerCase();
if (logger[name]) {
if (logger.isEnabledFor(level)) {
// delete any noops
delete logger[name];
} else {
Object.defineProperty(logger, name, {
configurable: true,
value: logNoop
});
}
}
}
}
var children = getChildren(logger._name);
children.forEach(function(child) {
disableLevels(child);
});
}
function logAtLevel(level) {
return function(msg /*, args...*/) {
switch (arguments.length) {
//faster cases
case 0:
case 1:
return this._log(level, msg);
case 2:
return this._log(level, msg, arguments[1]);
default:
//turtles
var args = new Array(arguments.length + 1);
args[0] = level;
for (var i = 1; i < args.length; i++) {
args[i] = arguments[i - 1];
}
return this._log.apply(this, args);
}
};
}
function Logger(name) {
if (!name) {
name = ROOT;
}
name = name.replace(OTHER_DIVIDERS, DIVIDER);
if (name in __loggers) {
return __loggers[name];
}
__loggers[name] = this;
this._name = name;
disableLevels(this);
Filterer.call(this);
this._handlers = [];
dbug('Logger (%s) created', name);
}
klass(Logger).inherit(Filterer).mixin({
//_handlers: [],
_name: null,
_level: null,
_handlesExceptions: false,
_exitOnError: true,
propagate: true,
setLevel: function setLevel(val) {
var level = LEVELS.getLevel(val);
assert(level != null, 'Cannot set level with provided value: ' + val);
this._level = level;
// clean __levelsCache
__levelCache = {};
disableLevels(this);
return this;
},
getEffectiveLevel: function getEffectiveLevel() {
if (this._level != null) {
return this._level;
} else if (this._name in __levelCache) {
return __levelCache[this._name];
} else {
var parent = getEffectiveParent(this._name);
return __levelCache[this._name] = parent ?
parent.getEffectiveLevel() :
LEVELS.NOTSET;
}
},
isEnabledFor: function isEnabledFor(level) {
return level >= this.getEffectiveLevel();
},
addHandler: function addHandler(handler) {
this._handlers.push(handler);
return this;
},
removeHandler: function removeHandler(handler) {
var index = this._handlers.indexOf(handler);
if (index !== -1) {
this._handlers.splice(index, 1);
}
return this;
},
removeAllHandlers: function removeAllHandlers() {
this._handlers = [];
},
handleExceptions: function handleExceptions(exitOnError/* = true */) {
this._exitOnError = exitOnError === false ? false : true;
if (!this._uncaughtException) {
this._uncaughtException = this.catchException.bind(this);
this._process.on('uncaughtException', this._uncaughtException);
}
},
unhandleExceptions: function unhandleExceptions() {
this._process.removeListener('uncaughtException', this._uncaughtException);
delete this._uncaughtException;
},
catchException: function catchException(err) {
var exits = this._exitOnError;
err[Record._UNCAUGHT_SYMBOL] = true;
this.critical(err);
if (exits) {
this._exit();
}
},
_exit: function _exit() {
this._process.exit(1);
},
makeRecord: function makeRecord(name, level, msg) {
return new Record(name, level, msg);
},
handle: function handle(record) {
if (this.filter(record)) {
var i = this._handlers.length;
while (i--) {
if (record.level >= this._handlers[i].level) {
this._handlers[i].handle(record);
}
}
// if this.propagate, tell our parent
if (this.propagate) {
var par = getEffectiveParent(this._name);
if (par) {
par.handle(record);
}
}
} else {
dbug('%s filtered message [%s]', this._name, record.message);
}
},
_log: function _log(_level, msg /*, args...*/) {
var level = LEVELS.getLevel(_level);
var args;
if (arguments.length < 3) {
args = [msg];
} else {
args = new Array(arguments.length - 1);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 1];
}
}
var record = this.makeRecord(this._name, level, args);
this.handle(record);
},
log: function log(_level /* msg, messageArs... */) {
var level = LEVELS.getLevel(_level);
// if level >= this.getEffectiveLevel(), tell our handlers
if (this.isEnabledFor(level)) {
this._log.apply(this, arguments);
}
},
trace: function trace(_msg) {
var obj = new Trace(trace);
var slice = 0;
var message = _msg;
if (typeof message === 'string') {
// [TRACE, msg, obj, ...arguments]
slice = 1;
message = '%s' + message;
obj.toString = emptyStr;
} else {
message = '%s';
obj.toString = traceStr;
}
var args = new Array(3 + arguments.length - slice);
args[0] = LEVELS.TRACE;
args[1] = message;
args[2] = obj;
for (var i = 3; i < args.length; i++) {
args[i] = arguments[i - 3 + slice];
}
return this._log.apply(this, args);
},
verbose: logAtLevel(LEVELS.VERBOSE),
debug: logAtLevel(LEVELS.DEBUG),
info: logAtLevel(LEVELS.INFO),
warn: logAtLevel(LEVELS.WARNING),
error: logAtLevel(LEVELS.ERROR),
critical: logAtLevel(LEVELS.CRITICAL),
// aliases
warning: function warning() {
return this.warn.apply(this, arguments);
},
/*jshint -W106*/ // ignore camelCase warning for this fun functions
o_O: function o_O() {
return this.warn.apply(this, arguments);
},
O_O: function O_O() {
return this.error.apply(this, arguments);
},
_process: process
});
for (var k in LEVELS) {
if (typeof LEVELS[k] === 'number') {
Logger[k] = Logger.prototype[k] = LEVELS[k];
}
}
module.exports = Logger;

121
node_modules/intel/lib/record.js generated vendored Normal file
View File

@@ -0,0 +1,121 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
const stacktrace = require('stack-trace');
const _Symbol = require('symbol');
const LEVELS = require('./levels');
const printf = require('./utils/printf');
const UNCAUGHT_SYMBOL = _Symbol();
const LOG_VERSION = 1; // increment when log format changes
const HOSTNAME = require('os').hostname();
const MESSAGE_CACHE = _Symbol();
const PID = process.pid;
// stack formatter helper
function stack(e) {
return {
toString: function() {
// first line is err.message, which we already show, so start from
// second line
return e.stack.substr(e.stack.indexOf('\n'));
},
toJSON: function() {
return stacktrace.parse(e);
}
};
}
function Trace(fn) {
Error.captureStackTrace(this, fn);
}
Trace.prototype.toJSON = function() {
return '[object Trace]';
};
function Record(name, level, args) {
this.name = name;
this.level = level;
this.levelname = LEVELS.getLevelName(level);
this.args = args;
this.pid = PID;
this.host = HOSTNAME;
this.v = LOG_VERSION;
this.timestamp = Date.now();
var trace;
var isErr = false;
var i = args.length;
while (i--) {
var a = args[i];
if (a && ((isErr = util.isError(a)) || a instanceof Trace)) {
trace = a;
break;
}
}
this.exception = isErr || undefined;
this.uncaughtException = isErr ? trace[UNCAUGHT_SYMBOL] : undefined;
this.stack = trace && trace.stack ? stack(trace) : undefined;
}
Record.prototype.name = undefined;
Record.prototype.level = undefined;
Record.prototype.levelname = undefined;
Record.prototype.args = undefined;
Record.prototype.pid = undefined;
Record.prototype.host = undefined;
Record.prototype.v = undefined;
Record.prototype.timestamp = undefined;
Record.prototype.exception = undefined;
Record.prototype.uncaughtException = undefined;
Record.prototype.stack = undefined;
Record.prototype[MESSAGE_CACHE] = undefined;
Object.defineProperty(Record.prototype, 'message', {
enumerable: true,
get: function() {
var message = this[MESSAGE_CACHE];
if (!message) {
var args = this.args;
message = args[0];
var isString = typeof message === 'string';
if (!isString || args.length > 1) {
if (!isString) {
args = new Array(this.args.length + 1);
args[0] = '%?';
var i = args.length - 1;
while (i--) {
args[i + 1] = this.args[i];
}
}
message = printf.apply(null, args);
}
this[MESSAGE_CACHE] = message;
}
return message;
}
});
Record.prototype.toJSON = function toJSON() {
var json = {};
var keys = Object.keys(this);
var i = keys.length;
while (i--) {
var key = keys[i];
if (key === 'timestamp') {
json.timestamp = new Date(this.timestamp);
} else {
json[key] = this[key];
}
}
return json;
};
Record._Trace = Trace;
Record._UNCAUGHT_SYMBOL = UNCAUGHT_SYMBOL;
module.exports = Record;

10
node_modules/intel/lib/utils/fn.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
module.exports = function fn(args) {
/*jshint evil: true*/
console.log(args, [].slice.call(arguments, 1).join('\n'));
return new Function(args, [].slice.call(arguments, 1).join('\n'));
};

32
node_modules/intel/lib/utils/json.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// util to protect us from circular references when stringifying
'use strict';
function stringify(obj, indent) {
var seen = [];
return JSON.stringify(obj, function filter(key, val) {
if (!val || typeof val !== 'object') {
return val;
} else if (seen.indexOf(val) !== -1) {
return '[Circular]';
}
seen.push(val);
return val;
}, indent || 0);
}
function nativeJson(obj, indent) {
return indent ? JSON.stringify(obj, null, indent) : JSON.stringify(obj);
}
module.exports = function json(obj, indent) {
try {
return nativeJson(obj, indent);
} catch (e) {
return stringify(obj, indent);
}
};

27
node_modules/intel/lib/utils/klass.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const util = require('util');
function klass(ctor) {
if (!(this instanceof klass)) {
return new klass(ctor);
}
this._ctor = ctor;
}
klass.prototype = {
inherit: function inherit(par) {
util.inherits(this._ctor, par);
return this;
},
mixin: function mixin(other) {
for (var k in other) {
this._ctor.prototype[k] = other[k];
}
return this;
}
};
module.exports = klass;

126
node_modules/intel/lib/utils/printf.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const json = require('./json');
const RE = /%(-?\d+)?(\.-?\d+)?(:\d+)?(%|(\([^\)]+\))?([sdOj\?]))/g;
const toString = Object.prototype.toString;
function type(x) {
return toString.call(x).slice(8, -1).toLowerCase();
}
function pad(str, value) {
var isRight = false;
if(value < 0) {
isRight = true;
value = -value;
}
if(str.length < value) {
var padding = new Array(value - str.length + 1).join(' ');
return isRight ? str + padding : padding + str;
} else{
return str;
}
}
function truncate(str, value) {
if(value > 0) {// truncate from begining
return str.slice(-value);
} else {// truncate from end
return str.slice(0, -value);
}
}
function defaultFmt(x) {
switch (type(x)) {
case 'arguments':
case 'object':
return json(x);
default:
return String(x);
}
}
function printfNextValue(format, nextValFn) {
var str = String(format).replace(RE,
function(match, padding, trunc, indent, kind, name, type) {
if (kind === '%') {
return '%';
}
var val = nextValFn(name);
var fmt = '';
switch (type) {
case 's':
fmt = String(val);
break;
case 'd':
fmt = String(Number(val));
break;
case 'O':
case 'j':
fmt = json(val, indent && parseInt(indent.slice(1), 10));
break;
case '?':
fmt = defaultFmt(val);
break;
}
if (trunc !== undefined) {
fmt = truncate(fmt, trunc.slice(1));
}
if (padding !== undefined) {
fmt = pad(fmt, padding);
}
return fmt;
});
return str;
}
function printfObj(format, obj) {
return printfNextValue(format, function(name) {
name = name && name.slice(1, -1);
return obj[name];
});
}
function printfArgs(format, args) {
var i = 0;
var len = args.length;
var str = printfNextValue(format, function() {
return args[i++];
});
if (len > 0) {
for (var x = args[i]; i < len; x = args[++i]) {
str += ' ' + defaultFmt(x);
}
}
return str;
}
// Usage:
// printf('I am %d %s old', 4, 'years');
// printf('%(name)s: %:2(message)j', { name: 'foo', message: { foo: 'bar' }});
const OBJECT_FMT = /%([:\-]?\d+)?\([^\)]+\)[sdjO\?]/;
module.exports = function printf(format, obj/*, ..args*/) {
if (!OBJECT_FMT.test(format)) {
var args = new Array(arguments.length - 1);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 1];
}
return printfArgs(format, args);
} else {
return printfObj(format, obj);
}
};