Total Complexity | 3 |
Complexity/F | 1.5 |
Lines of Code | 39 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | var Schema = require('../Schema') |
||
2 | var Normalizer = Schema.Normalizer |
||
3 | var Validator = Schema.Validator |
||
4 | var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j |
||
5 | var Printer = require('./Printer').Printer |
||
6 | var InvalidInputError = require('../Error').InvalidInputError |
||
7 | |||
8 | /** |
||
9 | * This class provide so-called barricade functionality - it validates |
||
10 | * and converts user input and, if input is invalid, prevents following |
||
11 | * actions by raising an exception. |
||
12 | * |
||
13 | * @param {TBarricadeOptions} [options] |
||
14 | * |
||
15 | * @class |
||
16 | */ |
||
17 | function Barricade (options) { |
||
18 | options = options || {} |
||
19 | var logger = Slf4j.factory(options.logger, 'ama-team.vsf.barricade') |
||
20 | var printer = options.printer || new Printer(options.logger) |
||
21 | |||
22 | /** |
||
23 | * @param {TScenarioInput} input |
||
24 | * @return {TScenario} |
||
25 | */ |
||
26 | this.scenario = function (input) { |
||
27 | var violations = Validator.scenario(input) |
||
28 | logger.info('Running scenario validation') |
||
29 | printer.violations(violations) |
||
30 | if (violations.severity === Validator.Severity.Fatal) { |
||
31 | throw new InvalidInputError('Scenario validation has failed') |
||
32 | } |
||
33 | return Normalizer.scenario(input) |
||
34 | } |
||
35 | } |
||
36 | |||
37 | module.exports = { |
||
38 | Barricade: Barricade |
||
39 | } |
||
40 |