@wmfs/tymly-statelint
Advanced tools
Comparing version 1.6.2 to 1.7.0
@@ -0,1 +1,8 @@ | ||
# [1.7.0](https://github.com/wmfs/tymly-statelint/compare/v1.6.2...v1.7.0) (2019-03-19) | ||
### ✨ Features | ||
* Extend resource validation to check functions as well as modules. ([2cf2f2a](https://github.com/wmfs/tymly-statelint/commit/2cf2f2a)) | ||
## [1.6.2](https://github.com/wmfs/tymly-statelint/compare/v1.6.1...v1.6.2) (2019-02-28) | ||
@@ -2,0 +9,0 @@ |
@@ -6,5 +6,5 @@ const StateLint = require('@wmfs/statelint').StateLint | ||
class TymlyStateLint extends StateLint { | ||
constructor (stateResources, logger) { | ||
constructor (stateResources, functions, logger) { | ||
super(extensionPath) | ||
this.taskNodeChecker = CheckTaskNodes(stateResources, logger) | ||
this.taskNodeChecker = CheckTaskNodes(stateResources, functions, logger) | ||
} // constructor | ||
@@ -19,2 +19,2 @@ | ||
module.exports = (stateResources, logger) => new TymlyStateLint(stateResources, logger) | ||
module.exports = (stateResources, functions, logger) => new TymlyStateLint(stateResources, functions, logger) |
@@ -6,3 +6,3 @@ const path = require('path') | ||
const moduleRegex = /^module:(.+)$/ | ||
const moduleRegex = /^(module|function):(.+)$/ | ||
@@ -15,4 +15,5 @@ const schemaTypes = { | ||
class CheckTaskNodes { | ||
constructor (stateResources, logger = console) { | ||
constructor (stateResources, functions, logger = console) { | ||
this.resources = stateResources | ||
this.functions = functions | ||
this.validators = { } | ||
@@ -56,3 +57,4 @@ this.logger = logger | ||
this.checkResource(name, state, resource[1]) | ||
const [ , resourceType, resourceName ] = resource | ||
if (resourceType === 'module') { this.checkResource(name, state, resourceName) } else if (resourceType === 'function') { this.checkFunction(name, resourceName) } | ||
} // checkTask | ||
@@ -88,2 +90,10 @@ | ||
} // findValidator | ||
checkFunction (name, functionName) { | ||
if (!this.functions) return | ||
if (!this.functions[functionName]) { | ||
return this.problems.push(`State Machine.States.${name}.Resource references a function '${functionName}' which is not loaded.`) | ||
} | ||
} | ||
} // CheckTaskNodes | ||
@@ -116,2 +126,2 @@ | ||
module.exports = (stateResources, logger) => new CheckTaskNodes(stateResources, logger) | ||
module.exports = (stateResources, functions, logger) => new CheckTaskNodes(stateResources, functions, logger) |
{ | ||
"name": "@wmfs/tymly-statelint", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "Validator for Amazon States Language with Tymly Extensions JSON.", | ||
@@ -5,0 +5,0 @@ "author": "West Midlands Fire Service", |
@@ -20,2 +20,5 @@ /* eslint-env mocha */ | ||
} | ||
const testFunctions = { | ||
fn: true | ||
} | ||
@@ -69,2 +72,17 @@ describe('TaskNode', () => { | ||
verify( | ||
'Resource is a Tymly function', | ||
{ | ||
StartAt: 'A', | ||
States: { | ||
A: { | ||
Type: 'Task', | ||
Resource: 'function:fn', | ||
End: true | ||
} | ||
} | ||
}, | ||
0 | ||
) | ||
verify( | ||
'Resource URN references a Tymly module, but that module is not loaded', | ||
@@ -83,2 +101,17 @@ { | ||
) | ||
verify( | ||
'Resource is a Tymly function, but the function does not exist', | ||
{ | ||
StartAt: 'A', | ||
States: { | ||
A: { | ||
Type: 'Task', | ||
Resource: 'function:unknownfn', | ||
End: true | ||
} | ||
} | ||
}, | ||
1 | ||
) | ||
}) | ||
@@ -209,3 +242,3 @@ | ||
it(title, () => { | ||
const taskNodeChecker = CheckTaskNode(testStateResources, nullLogger) | ||
const taskNodeChecker = CheckTaskNode(testStateResources, testFunctions, nullLogger) | ||
const problems = taskNodeChecker.check(json) | ||
@@ -212,0 +245,0 @@ problems.forEach(p => console.log(`P: ${p}`)) |
@@ -58,3 +58,3 @@ /* eslint-env mocha */ | ||
const logger = new TestLogger() | ||
tymlyStateLint(null, logger) | ||
tymlyStateLint(null, null, logger) | ||
@@ -66,3 +66,3 @@ expect(logger.logs).to.eql(['State Resources not available. Will not validate Resource or ResourceConfig']) | ||
const logger = new TestLogger() | ||
const linter = tymlyStateLint(stateResources, logger) | ||
const linter = tymlyStateLint(stateResources, null, logger) | ||
linter.validate(require(path.join(fixturesDir, 'timestamp.json'))) | ||
@@ -69,0 +69,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32026
651