cross-project-diagnostics
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -12,3 +12,3 @@ "use strict"; | ||
})(Level = exports.Level || (exports.Level = {})); | ||
exports.getLevelByLabel = function (levelStr) { | ||
exports.getLevelByLabel = (levelStr) => { | ||
switch (levelStr) { | ||
@@ -24,3 +24,3 @@ case 'off': return Level.OFF; | ||
}; | ||
exports.getLabelByLevel = function (level) { | ||
exports.getLabelByLevel = (level) => { | ||
switch (level) { | ||
@@ -27,0 +27,0 @@ case Level.OFF: return 'off'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var definitions_1 = require("./definitions"); | ||
exports.getLevelAvailability = function (currentLevel, expectedLevel) { | ||
var levelPriorities = [definitions_1.Level.OFF, definitions_1.Level.FATAL, definitions_1.Level.ERROR, definitions_1.Level.WARNING, definitions_1.Level.DEBUG, definitions_1.Level.ALL]; | ||
var totalPriority = definitions_1.Level.OFF; | ||
for (var _i = 0, levelPriorities_1 = levelPriorities; _i < levelPriorities_1.length; _i++) { | ||
var level = levelPriorities_1[_i]; | ||
const definitions_1 = require("./definitions"); | ||
exports.getLevelAvailability = (currentLevel, expectedLevel) => { | ||
const levelPriorities = [definitions_1.Level.OFF, definitions_1.Level.FATAL, definitions_1.Level.ERROR, definitions_1.Level.WARNING, definitions_1.Level.DEBUG, definitions_1.Level.ALL]; | ||
let totalPriority = definitions_1.Level.OFF; | ||
for (const level of levelPriorities) { | ||
totalPriority |= level; | ||
@@ -17,4 +15,4 @@ if (level === currentLevel) { | ||
}; | ||
var LiftingDiagnosticManager = (function () { | ||
function LiftingDiagnosticManager(diagnosticDescriptor) { | ||
class LiftingDiagnosticManager { | ||
constructor(diagnosticDescriptor) { | ||
this.diagnosticDescriptor = diagnosticDescriptor; | ||
@@ -26,37 +24,37 @@ this.parents = []; | ||
} | ||
LiftingDiagnosticManager.prototype.addOutputTo = function (parent) { | ||
addOutputTo(parent) { | ||
this.parents.push(parent); | ||
}; | ||
LiftingDiagnosticManager.prototype.getFatalListener = function () { | ||
} | ||
getFatalListener() { | ||
return this.onFatal; | ||
}; | ||
LiftingDiagnosticManager.prototype.setFatalListener = function (onFatal) { | ||
} | ||
setFatalListener(onFatal) { | ||
this.onFatal = onFatal; | ||
}; | ||
LiftingDiagnosticManager.prototype.fatal = function (funName, message, attachmentPar) { | ||
} | ||
fatal(funName, message, attachmentPar) { | ||
if (exports.getLevelAvailability(this.diagnosticDescriptor.level, definitions_1.Level.FATAL)) { | ||
var attachment = attachmentPar instanceof Error ? attachmentPar.stack : attachmentPar; | ||
const attachment = attachmentPar instanceof Error ? attachmentPar.stack : attachmentPar; | ||
if (this.onFatal) { | ||
this.onFatal(attachment); | ||
} | ||
this.addRecord(this.prepareRecord({ funName: funName, message: message, attachment: attachment }, definitions_1.Level.FATAL)); | ||
this.addRecord(this.prepareRecord({ funName, message, attachment }, definitions_1.Level.FATAL)); | ||
} | ||
}; | ||
LiftingDiagnosticManager.prototype.error = function (funName, message, attachmentPar) { | ||
} | ||
error(funName, message, attachmentPar) { | ||
if (exports.getLevelAvailability(this.diagnosticDescriptor.level, definitions_1.Level.ERROR)) { | ||
var attachment = attachmentPar instanceof Error ? attachmentPar.stack : attachmentPar; | ||
this.addRecord(this.prepareRecord({ funName: funName, message: message, attachment: attachment }, definitions_1.Level.ERROR)); | ||
const attachment = attachmentPar instanceof Error ? attachmentPar.stack : attachmentPar; | ||
this.addRecord(this.prepareRecord({ funName, message, attachment }, definitions_1.Level.ERROR)); | ||
} | ||
}; | ||
LiftingDiagnosticManager.prototype.warning = function (funName, message, attachment) { | ||
} | ||
warning(funName, message, attachment) { | ||
if (exports.getLevelAvailability(this.diagnosticDescriptor.level, definitions_1.Level.WARNING)) { | ||
this.addRecord(this.prepareRecord({ funName: funName, message: message, attachment: attachment }, definitions_1.Level.WARNING)); | ||
this.addRecord(this.prepareRecord({ funName, message, attachment }, definitions_1.Level.WARNING)); | ||
} | ||
}; | ||
LiftingDiagnosticManager.prototype.debug = function (funName, message, attachment) { | ||
} | ||
debug(funName, message, attachment) { | ||
if (exports.getLevelAvailability(this.diagnosticDescriptor.level, definitions_1.Level.DEBUG)) { | ||
this.addRecord(this.prepareRecord({ funName: funName, message: message, attachment: attachment }, definitions_1.Level.DEBUG)); | ||
this.addRecord(this.prepareRecord({ funName, message, attachment }, definitions_1.Level.DEBUG)); | ||
} | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareDiagnosticFor = function (funName) { | ||
} | ||
prepareDiagnosticFor(funName) { | ||
return { | ||
@@ -68,39 +66,34 @@ fatal: this.prepareFatalFor(funName), | ||
}; | ||
}; | ||
LiftingDiagnosticManager.prototype.addRecord = function (record) { | ||
} | ||
addRecord(record) { | ||
if (this.parents.length <= 0) { | ||
throw Error("parents are missing for " + this.diagnosticDescriptor.module + "@" + this.diagnosticDescriptor.version + " on " + this.diagnosticDescriptor.requestId); | ||
throw Error(`parents are missing for ${this.diagnosticDescriptor.module}@${this.diagnosticDescriptor.version} on ${this.diagnosticDescriptor.requestId}`); | ||
} | ||
for (var _i = 0, _a = this.parents; _i < _a.length; _i++) { | ||
var parent_1 = _a[_i]; | ||
parent_1.addRecord(record); | ||
for (const parent of this.parents) { | ||
parent.addRecord(record); | ||
} | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareFatalFor = function (funName) { | ||
var _this = this; | ||
return function (message, attachment) { | ||
_this.fatal(funName, message, attachment); | ||
} | ||
prepareFatalFor(funName) { | ||
return (message, attachment) => { | ||
this.fatal(funName, message, attachment); | ||
}; | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareErrorFor = function (funName) { | ||
var _this = this; | ||
return function (message, attachment) { | ||
_this.error(funName, message, attachment); | ||
} | ||
prepareErrorFor(funName) { | ||
return (message, attachment) => { | ||
this.error(funName, message, attachment); | ||
}; | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareWarningFor = function (funName) { | ||
var _this = this; | ||
return function (message, attachment) { | ||
_this.warning(funName, message, attachment); | ||
} | ||
prepareWarningFor(funName) { | ||
return (message, attachment) => { | ||
this.warning(funName, message, attachment); | ||
}; | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareDebugFor = function (funName) { | ||
var _this = this; | ||
return function (message, attachment) { | ||
_this.debug(funName, message, attachment); | ||
} | ||
prepareDebugFor(funName) { | ||
return (message, attachment) => { | ||
this.debug(funName, message, attachment); | ||
}; | ||
}; | ||
LiftingDiagnosticManager.prototype.prepareRecord = function (data, level) { | ||
var funName = data.funName, message = data.message, attachment = data.attachment; | ||
var result = { | ||
} | ||
prepareRecord(data, level) { | ||
const { funName, message, attachment } = data; | ||
const result = { | ||
time: (new Date()).toISOString(), | ||
@@ -110,3 +103,3 @@ module: this.diagnosticDescriptor.module, | ||
requestId: this.diagnosticDescriptor.requestId, | ||
funName: funName, message: message, level: definitions_1.getLabelByLevel(level) | ||
funName, message, level: definitions_1.getLabelByLevel(level) | ||
}; | ||
@@ -117,24 +110,20 @@ if (attachment) { | ||
return result; | ||
}; | ||
return LiftingDiagnosticManager; | ||
}()); | ||
} | ||
} | ||
exports.LiftingDiagnosticManager = LiftingDiagnosticManager; | ||
var EndpointDiagnosticManager = (function (_super) { | ||
tslib_1.__extends(EndpointDiagnosticManager, _super); | ||
function EndpointDiagnosticManager() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.content = []; | ||
return _this; | ||
class EndpointDiagnosticManager extends LiftingDiagnosticManager { | ||
constructor() { | ||
super(...arguments); | ||
this.content = []; | ||
} | ||
EndpointDiagnosticManager.prototype.addRecord = function (record) { | ||
addRecord(record) { | ||
this.content.push(record); | ||
}; | ||
EndpointDiagnosticManager.prototype.putDiagnosticContentInto = function (response) { | ||
} | ||
putDiagnosticContentInto(response) { | ||
response._diagnostic = this.content; | ||
}; | ||
EndpointDiagnosticManager.prototype.extractDiagnosticContentFrom = function (response) { | ||
var _a; | ||
var jsonResponse = JSON.parse(response); | ||
} | ||
extractDiagnosticContentFrom(response) { | ||
const jsonResponse = JSON.parse(response); | ||
if (jsonResponse._diagnostic) { | ||
(_a = this.content).push.apply(_a, jsonResponse._diagnostic); | ||
this.content.push(...jsonResponse._diagnostic); | ||
} | ||
@@ -144,12 +133,11 @@ else { | ||
} | ||
}; | ||
return EndpointDiagnosticManager; | ||
}(LiftingDiagnosticManager)); | ||
} | ||
} | ||
exports.EndpointDiagnosticManager = EndpointDiagnosticManager; | ||
function createDiagnosticManagerOn(module, version) { | ||
return { | ||
forRequest: function (requestId) { | ||
var diagnosticDescriptor = { module: module, version: version, requestId: requestId, level: null }; | ||
forRequest: (requestId) => { | ||
const diagnosticDescriptor = { module, version, requestId, level: null }; | ||
return { | ||
withSeverityLevel: function (level) { | ||
withSeverityLevel: (level) => { | ||
diagnosticDescriptor.level = level; | ||
@@ -160,9 +148,9 @@ return new EndpointDiagnosticManager(diagnosticDescriptor); | ||
}, | ||
basedOn: function (parent) { | ||
var diagnosticDescriptor = { | ||
module: module, version: version, | ||
basedOn: (parent) => { | ||
const diagnosticDescriptor = { | ||
module, version, | ||
requestId: parent.diagnosticDescriptor.requestId, | ||
level: parent.diagnosticDescriptor.level | ||
}; | ||
var diag = new LiftingDiagnosticManager(diagnosticDescriptor); | ||
const diag = new LiftingDiagnosticManager(diagnosticDescriptor); | ||
diag.addOutputTo(parent); | ||
@@ -169,0 +157,0 @@ if (parent.getFatalListener()) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./definitions"), exports); | ||
tslib_1.__exportStar(require("./diagnostic-manager"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "cross-project-diagnostics", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Gapminder Cross-project Diagnostics functionality", | ||
@@ -5,0 +5,0 @@ "author": "Vyacheslav Chub<vyacheslav.chub@valor-software.com>", |
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"target": "es5", | ||
"target": "es2017", | ||
"module": "commonjs", | ||
@@ -6,0 +6,0 @@ "noImplicitAny": false, |
60248
473