UNPKG

devebot

Version:

Nodejs Microservice Framework

38 lines (37 loc) 1.1 kB
"use strict"; const chores = require("../utils/chores"); const blockRef = chores.getBlockRef(__filename); function SchemaValidator(params = {}) { const loggingFactory = params.loggingFactory.branch(blockRef); const L = loggingFactory.getLogger(); const T = loggingFactory.getTracer(); const _ref_ = { validator: null }; L && L.has("silly") && L.log("silly", T && T.toMessage({ tags: [blockRef, "constructor-begin"], text: " + constructor start ..." })); this.validate = function (object, schema) { _ref_.validator = _ref_.validator || chores.getValidator(); const result = _ref_.validator.validate(object, schema); if (typeof result.ok === "boolean") { result.valid = result.ok; } return result; }; L && L.has("silly") && L.log("silly", T && T.toMessage({ tags: [blockRef, "constructor-end"], text: " - constructor has finished" })); } SchemaValidator.argumentSchema = { "$id": "schemaValidator", "type": "object", "properties": { "loggingFactory": { "type": "object" } } }; module.exports = SchemaValidator;