asl-validator
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "asl-validator", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Amazon States Language validator", | ||
@@ -34,3 +34,4 @@ "main": "./src/validator.js", | ||
"ajv": "^5.3.0", | ||
"commander": "^2.11.0" | ||
"commander": "^2.11.0", | ||
"jsonpath": "^1.0.0" | ||
}, | ||
@@ -37,0 +38,0 @@ "devDependencies": { |
@@ -9,3 +9,3 @@ # asl-validator | ||
A simple [**Amazon States Language**](https://states-language.net/spec.html) validator based on JSON schemas. | ||
A simple [**Amazon States Language**](https://states-language.net/spec.html) validator based on JSON schemas. It also validates JSON paths syntax in `InputPath`, `OutputPath` and `ResultPath`. | ||
@@ -12,0 +12,0 @@ When writing your state machine (for AWS step functions), you can't locally validate you state machine definition without creating it. `asl-validator` makes it possible. |
@@ -17,5 +17,7 @@ const fs = require('fs'); | ||
expect(isValid).toBeTruthy(); | ||
expect(errors).toBeNull(); | ||
expect(Array.isArray(errors)).toBeTruthy(); | ||
expect(errors.length).toEqual(0); | ||
} else if (match[1] === 'invalid') { | ||
expect(isValid).toBeFalsy(); | ||
expect(Array.isArray(errors)).toBeTruthy(); | ||
expect(errors.length).toBeGreaterThan(0); | ||
@@ -22,0 +24,0 @@ } |
const Ajv = require('ajv'); | ||
const jp = require('jsonpath'); | ||
@@ -27,6 +28,24 @@ const choice = require('./schemas/choice'); | ||
}); | ||
const isValid = ajv.validate('http://asl-validator.cloud/state-machine#', definition); | ||
return { isValid, errors: ajv.errors }; | ||
// Validating JSON paths | ||
const jsonPathErrors = jp.query(definition, '$..[\'InputPath\',\'OutputPath\',\'ResultPath\']') | ||
.map((path) => { | ||
try { | ||
jp.parse(path); | ||
return null; | ||
} catch (e) { | ||
return e; | ||
} | ||
}) | ||
.filter(parsed => parsed); // remove null values to keep only errors | ||
// Validating JSON schemas | ||
const isJsonSchemaValid = ajv.validate('http://asl-validator.cloud/state-machine#', definition); | ||
return { | ||
isValid: isJsonSchemaValid && !jsonPathErrors.length, | ||
errors: jsonPathErrors.concat(ajv.errors || []), | ||
}; | ||
} | ||
module.exports = validator; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40024
3
29
1000
+ Addedjsonpath@^1.0.0
+ Addeddeep-is@0.1.4(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@1.2.24.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedjsonpath@1.1.1(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedstatic-eval@2.0.2(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedunderscore@1.12.1(transitive)
+ Addedword-wrap@1.2.5(transitive)