cda-schematron-validator 1.1.12 → 2.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -9
- package/README.md +222 -243
- package/bin/cda-validate.js +36 -0
- package/docs/api.md +134 -0
- package/docs/architecture.md +102 -0
- package/docs/coverage.md +124 -0
- package/docs/deployment.md +126 -0
- package/docs/history.md +245 -0
- package/docs/legacy-api.md +70 -0
- package/docs/terminology.md +75 -0
- package/lib/checkIfFileOrPath.js +27 -28
- package/lib/checkRule.js +97 -98
- package/lib/createClient.js +35 -0
- package/lib/getAssertionObject.js +23 -23
- package/lib/getErrorsAndWarnings.js +41 -41
- package/lib/getFailedAssertions.js +24 -25
- package/lib/getIgnored.js +27 -27
- package/lib/getResults.js +22 -22
- package/lib/getReturnObject.js +20 -20
- package/lib/getSchematronMap.js +34 -31
- package/lib/getSelectXmlChunk.js +27 -27
- package/lib/includeExternalDocument.js +113 -107
- package/lib/initializeProcess.js +34 -40
- package/lib/parseSchematron.js +122 -122
- package/lib/processFailedAssertions.js +17 -17
- package/lib/processRules.js +20 -20
- package/lib/processRulesAsync.js +18 -30
- package/lib/testAssertion.js +74 -74
- package/package.json +67 -59
- package/validateAsync.js +103 -117
- package/validateSync.js +51 -55
- package/validator.d.ts +89 -0
- package/validator.js +17 -16
- package/.eslintrc.js +0 -30
- package/.github/workflows/codeql-analysis.yml +0 -70
- package/.husky/pre-commit +0 -5
- package/.jshintrc +0 -96
- package/.vscode/launch.json +0 -37
- package/Gruntfile.js +0 -28
- package/SECURITY.md +0 -21
- package/test/CDAR2_IG_CCDA_CLINNOTES_R1_DSTU2.1_2015AUG_Vol2_2019JUNwith_errata.sch +0 -71
- package/test/VitalSigns.xml +0 -856
- package/test/async.test.js +0 -124
- package/test/asyncFileList.test.js +0 -61
- package/test/test.sch +0 -47
- package/test/test.xml +0 -80
- package/test/tests.js +0 -140
- package/test/vitalSigns.test.js +0 -34
- package/test/voc.xml +0 -44
package/lib/checkRule.js
CHANGED
|
@@ -1,98 +1,97 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* @
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {array}
|
|
38
|
-
* @param {
|
|
39
|
-
* @
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
assertionObject
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
assertionObject
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @param {
|
|
76
|
-
* @param {
|
|
77
|
-
* @
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
1
|
+
const getSelectXmlChunk = require('./getSelectXmlChunk');
|
|
2
|
+
const includeExternalDocument = require('./includeExternalDocument');
|
|
3
|
+
const testAssertion = require('./testAssertion');
|
|
4
|
+
const getAssertionObject = require('./getAssertionObject');
|
|
5
|
+
// Take the checkRule function out of validate function, and pass on the variable needed as parameters and options
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @method checkRule Validate assertions and extension against the provided context of the xml with the given options
|
|
9
|
+
* @param {string} context Used to query the xml using xpath
|
|
10
|
+
* @param {array} assertionsAndExtensions Each assertionsAndExtensions object is processed further based on the information in the object
|
|
11
|
+
* @param {object} options Options passed to the validator and any other variables passed between the methods
|
|
12
|
+
* @returns {array} Failed assertion objects are returned
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function checkRule(context, assertionsAndExtensions, options) {
|
|
16
|
+
// Context cache
|
|
17
|
+
const failedAssertions = [];
|
|
18
|
+
// Determine the sections within context, load selected section from cache if possible
|
|
19
|
+
const selectedXml = getSelectXmlChunk(context, options);
|
|
20
|
+
for (let i = 0; i < assertionsAndExtensions.length; i++) {
|
|
21
|
+
const assertionAndExtensionObject = assertionsAndExtensions[i];
|
|
22
|
+
if (assertionAndExtensionObject.type === 'assertion') {
|
|
23
|
+
processAssertions(assertionAndExtensionObject, selectedXml, failedAssertions, options);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const failedSubAssertions = processExtensions(assertionAndExtensionObject, context, options);
|
|
27
|
+
failedAssertions.push(...failedSubAssertions);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return failedAssertions;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @method processAssertions When the assertionAndExtensionObject type is assertion process it
|
|
35
|
+
* @param {object} assertionAndExtensionObject Assertion object with information to test against the selectedXml using testAssertion
|
|
36
|
+
* @param {array} selectedXml array of selected xml based on context
|
|
37
|
+
* @param {array} failedAssertions array to hold failedAssertions
|
|
38
|
+
* @param {object} options Options passed to the validator and any other variables passed between the methods
|
|
39
|
+
* @returns {array} Failed assertion objects are returned
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
function processAssertions(assertionAndExtensionObject, selectedXml, failedAssertions, options) {
|
|
43
|
+
// const failedAssertions = [];
|
|
44
|
+
let { level, test, id, description } = assertionAndExtensionObject;
|
|
45
|
+
// Extract values from external document and modify test if a document call is made
|
|
46
|
+
const originalTest = test;
|
|
47
|
+
let simplifiedTest = null;
|
|
48
|
+
try {
|
|
49
|
+
test = includeExternalDocument(test, options.resourceDir);
|
|
50
|
+
if (originalTest !== test) {
|
|
51
|
+
simplifiedTest = test;
|
|
52
|
+
}
|
|
53
|
+
if (level === 'error' || options?.includeWarnings) {
|
|
54
|
+
const testAssertionResponse = testAssertion(test, selectedXml, options.xpathSelect, options.xmlDoc, options.resourceDir, options.xmlSnippetMaxLength);
|
|
55
|
+
if ((Array.isArray(testAssertionResponse) && testAssertionResponse.length) || testAssertionResponse?.ignored) {
|
|
56
|
+
const assertionObject = getAssertionObject(level, id, originalTest, simplifiedTest, description);
|
|
57
|
+
assertionObject.results = testAssertionResponse;
|
|
58
|
+
failedAssertions.push(assertionObject);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const assertionObject = getAssertionObject(level, id, originalTest, simplifiedTest, description);
|
|
64
|
+
assertionObject.results = { ignored: true, errorMessage: err.message };
|
|
65
|
+
failedAssertions.push(assertionObject);
|
|
66
|
+
}
|
|
67
|
+
return failedAssertions;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @method processExtension When the assertionAndExtensionObject type is 'not an assertion' (extension) process it
|
|
72
|
+
* Cannot have this as a separate file with a circular reference to checkRule export in a separate file. That will cause
|
|
73
|
+
* the code to fail. So, these methods (checkRule and processExtension) should be in the same file.
|
|
74
|
+
* @param {object} assertionAndExtensionObject Extension object with a rule is processed with checkRule
|
|
75
|
+
* @param {string} context Used to query the xml using xpath
|
|
76
|
+
* @param {object} options Options passed to the validator and any other variables passed between the methods
|
|
77
|
+
* @returns {array} Failed assertion objects are returned
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
function processExtensions(assertionAndExtensionObject, context, options) {
|
|
81
|
+
const extensionRule = assertionAndExtensionObject.rule;
|
|
82
|
+
let failedSubAssertions = [];
|
|
83
|
+
if (extensionRule) {
|
|
84
|
+
const newRuleObject = options.schematronMap.ruleAssertionMap[extensionRule];
|
|
85
|
+
const subAssertionsAndExtensions = newRuleObject ? newRuleObject.assertionsAndExtensions : null;
|
|
86
|
+
if (subAssertionsAndExtensions) {
|
|
87
|
+
failedSubAssertions = checkRule(context, subAssertionsAndExtensions, options);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return failedSubAssertions;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
checkRule,
|
|
95
|
+
processAssertions,
|
|
96
|
+
processExtensions
|
|
97
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** Modern HTTP client; the existing in-process Schematron APIs remain available. */
|
|
4
|
+
module.exports = function createClient({ baseUrl = 'http://127.0.0.1:17643', token, timeoutMs = 110000 } = {}) {
|
|
5
|
+
const base = new URL(baseUrl);
|
|
6
|
+
if (!['http:', 'https:'].includes(base.protocol) || base.username || base.password) {
|
|
7
|
+
throw new TypeError('Use an HTTP(S) service URL without embedded credentials');
|
|
8
|
+
}
|
|
9
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new TypeError('timeoutMs must be positive');
|
|
10
|
+
async function request(path, body) {
|
|
11
|
+
const response = await fetch(new URL(path, base), {
|
|
12
|
+
method: body ? 'POST' : 'GET',
|
|
13
|
+
headers: Object.assign({ Accept: 'application/json' }, body ? { 'Content-Type': 'application/json' } : {}, token ? { Authorization: 'Bearer ' + token } : {}),
|
|
14
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
15
|
+
redirect: 'error',
|
|
16
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
17
|
+
});
|
|
18
|
+
const report = await response.json();
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const error = new Error(report.error || 'Validation service returned HTTP ' + response.status);
|
|
21
|
+
error.status = response.status;
|
|
22
|
+
error.report = report;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return report;
|
|
26
|
+
}
|
|
27
|
+
return Object.freeze({
|
|
28
|
+
validate(xml, { profile = 'ccda-5.0', includeWarnings = true } = {}) {
|
|
29
|
+
if (typeof xml !== 'string' || !xml.trim()) throw new TypeError('xml must be non-empty XML text');
|
|
30
|
+
return request('/v1/validate', { xml, profile, includeWarnings });
|
|
31
|
+
},
|
|
32
|
+
profiles: () => request('/v1/profiles'),
|
|
33
|
+
version: () => request('/v1/version')
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @method getAssertionObject A simple wrapper to output assertionObject with the right properties as it is used by
|
|
3
|
-
* multiple mthods
|
|
4
|
-
* @param {string} level 'error' or 'warning'
|
|
5
|
-
* @param {string} id rule id
|
|
6
|
-
* @param {string} originalTest test information
|
|
7
|
-
* @param {string} simplifiedTest if the originalTest has an addition from an external file
|
|
8
|
-
* @param {string} description description of the error or warning
|
|
9
|
-
* @returns {object} returns object with the properties type, assertionId, test, simplifiedTest, description
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function getAssertionObject(level, id, originalTest, simplifiedTest, description) {
|
|
13
|
-
const assertionObject = {
|
|
14
|
-
type: level,
|
|
15
|
-
assertionId: id,
|
|
16
|
-
test: originalTest,
|
|
17
|
-
simplifiedTest: simplifiedTest,
|
|
18
|
-
description: description
|
|
19
|
-
};
|
|
20
|
-
return assertionObject;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = getAssertionObject;
|
|
1
|
+
/**
|
|
2
|
+
* @method getAssertionObject A simple wrapper to output assertionObject with the right properties as it is used by
|
|
3
|
+
* multiple mthods
|
|
4
|
+
* @param {string} level 'error' or 'warning'
|
|
5
|
+
* @param {string} id rule id
|
|
6
|
+
* @param {string} originalTest test information
|
|
7
|
+
* @param {string} simplifiedTest if the originalTest has an addition from an external file
|
|
8
|
+
* @param {string} description description of the error or warning
|
|
9
|
+
* @returns {object} returns object with the properties type, assertionId, test, simplifiedTest, description
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function getAssertionObject(level, id, originalTest, simplifiedTest, description) {
|
|
13
|
+
const assertionObject = {
|
|
14
|
+
type: level,
|
|
15
|
+
assertionId: id,
|
|
16
|
+
test: originalTest,
|
|
17
|
+
simplifiedTest: simplifiedTest,
|
|
18
|
+
description: description
|
|
19
|
+
};
|
|
20
|
+
return assertionObject;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = getAssertionObject;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @method getErrorsAndWarnings Given the information update errors and warnings array in resultInfo
|
|
3
|
-
* @param {object} assertionObject Provides the assertion and the results of the test
|
|
4
|
-
* @param {object} assertionInfo Information about the assertion
|
|
5
|
-
* @param {object} resultInfo Arrays to store error and warning info
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
function getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo) {
|
|
9
|
-
const { type, assertionId, test, simplifiedTest, description, results } = assertionObject;
|
|
10
|
-
const { patternId, ruleId, context } = assertionInfo;
|
|
11
|
-
const { errors, warnings } = resultInfo;
|
|
12
|
-
for (let index = 0; index < results.length; index++) {
|
|
13
|
-
const resultObject = results[index];
|
|
14
|
-
const { result, line, path, xml } = resultObject;
|
|
15
|
-
// If the xpath did not return a result (result=false), then there should be
|
|
16
|
-
// and error or warning
|
|
17
|
-
if (!result) {
|
|
18
|
-
const obj = {
|
|
19
|
-
type,
|
|
20
|
-
test,
|
|
21
|
-
simplifiedTest,
|
|
22
|
-
description,
|
|
23
|
-
line,
|
|
24
|
-
path,
|
|
25
|
-
patternId,
|
|
26
|
-
ruleId,
|
|
27
|
-
assertionId,
|
|
28
|
-
context,
|
|
29
|
-
xml
|
|
30
|
-
};
|
|
31
|
-
if (type === 'error') {
|
|
32
|
-
errors.push(obj);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
warnings.push(obj);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = getErrorsAndWarnings;
|
|
1
|
+
/**
|
|
2
|
+
* @method getErrorsAndWarnings Given the information update errors and warnings array in resultInfo
|
|
3
|
+
* @param {object} assertionObject Provides the assertion and the results of the test
|
|
4
|
+
* @param {object} assertionInfo Information about the assertion
|
|
5
|
+
* @param {object} resultInfo Arrays to store error and warning info
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo) {
|
|
9
|
+
const { type, assertionId, test, simplifiedTest, description, results } = assertionObject;
|
|
10
|
+
const { patternId, ruleId, context } = assertionInfo;
|
|
11
|
+
const { errors, warnings } = resultInfo;
|
|
12
|
+
for (let index = 0; index < results.length; index++) {
|
|
13
|
+
const resultObject = results[index];
|
|
14
|
+
const { result, line, path, xml } = resultObject;
|
|
15
|
+
// If the xpath did not return a result (result=false), then there should be
|
|
16
|
+
// and error or warning
|
|
17
|
+
if (!result) {
|
|
18
|
+
const obj = {
|
|
19
|
+
type,
|
|
20
|
+
test,
|
|
21
|
+
simplifiedTest,
|
|
22
|
+
description,
|
|
23
|
+
line,
|
|
24
|
+
path,
|
|
25
|
+
patternId,
|
|
26
|
+
ruleId,
|
|
27
|
+
assertionId,
|
|
28
|
+
context,
|
|
29
|
+
xml
|
|
30
|
+
};
|
|
31
|
+
if (type === 'error') {
|
|
32
|
+
errors.push(obj);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
warnings.push(obj);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = getErrorsAndWarnings;
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {object}
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = getFailedAssertions;
|
|
1
|
+
const { checkRule } = require('./checkRule');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @method getFailedAssertions Get assertions and extension from the rule object and check the rule against the context
|
|
5
|
+
* @param {string} ruleId Rule identifier
|
|
6
|
+
* @param {object} assertionInfo Object to store assertion info
|
|
7
|
+
* @param {object} options Options passed to the validator and any other variables passed between the methods
|
|
8
|
+
* @returns {array} array of failedAssertionObjects
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function getFailedAssertions(ruleId, assertionInfo, options) {
|
|
12
|
+
let failedAssertions;
|
|
13
|
+
assertionInfo.ruleId = ruleId;
|
|
14
|
+
const ruleObject = options.schematronMap.ruleAssertionMap[ruleId];
|
|
15
|
+
if (!ruleObject?.abstract) {
|
|
16
|
+
const context = ruleObject?.context;
|
|
17
|
+
assertionInfo.context = context;
|
|
18
|
+
const assertionsAndExtensions = ruleObject?.assertionsAndExtensions || [];
|
|
19
|
+
failedAssertions = checkRule(context, assertionsAndExtensions, options);
|
|
20
|
+
}
|
|
21
|
+
return failedAssertions;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = getFailedAssertions;
|
package/lib/getIgnored.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @method getIgnored If there ws an erroneous rule, it results in the rule being ignored.
|
|
3
|
-
* This method will add the ignored assertion info to the ignored array.
|
|
4
|
-
* @param {object} assertionObject Carries the ignored assertion info
|
|
5
|
-
* @param {object} assertionInfo carries the assertion info from pattern, rule and context
|
|
6
|
-
* @param {object} resultInfo carries the ignored array
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
function getIgnored(assertionObject, assertionInfo, resultInfo) {
|
|
10
|
-
const { type, assertionId, test, simplifiedTest, description, errorMessage } = assertionObject;
|
|
11
|
-
const { patternId, ruleId, context } = assertionInfo;
|
|
12
|
-
const { ignored } = resultInfo;
|
|
13
|
-
const obj = {
|
|
14
|
-
errorMessage,
|
|
15
|
-
type,
|
|
16
|
-
test,
|
|
17
|
-
simplifiedTest,
|
|
18
|
-
description,
|
|
19
|
-
patternId,
|
|
20
|
-
ruleId,
|
|
21
|
-
assertionId,
|
|
22
|
-
context
|
|
23
|
-
};
|
|
24
|
-
ignored.push(obj);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = getIgnored;
|
|
1
|
+
/**
|
|
2
|
+
* @method getIgnored If there ws an erroneous rule, it results in the rule being ignored.
|
|
3
|
+
* This method will add the ignored assertion info to the ignored array.
|
|
4
|
+
* @param {object} assertionObject Carries the ignored assertion info
|
|
5
|
+
* @param {object} assertionInfo carries the assertion info from pattern, rule and context
|
|
6
|
+
* @param {object} resultInfo carries the ignored array
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function getIgnored(assertionObject, assertionInfo, resultInfo) {
|
|
10
|
+
const { type, assertionId, test, simplifiedTest, description, errorMessage } = assertionObject;
|
|
11
|
+
const { patternId, ruleId, context } = assertionInfo;
|
|
12
|
+
const { ignored } = resultInfo;
|
|
13
|
+
const obj = {
|
|
14
|
+
errorMessage,
|
|
15
|
+
type,
|
|
16
|
+
test,
|
|
17
|
+
simplifiedTest,
|
|
18
|
+
description,
|
|
19
|
+
patternId,
|
|
20
|
+
ruleId,
|
|
21
|
+
assertionId,
|
|
22
|
+
context
|
|
23
|
+
};
|
|
24
|
+
ignored.push(obj);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = getIgnored;
|
package/lib/getResults.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const getErrorsAndWarnings = require('./getErrorsAndWarnings');
|
|
2
|
-
const getIgnored = require('./getIgnored');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @method getResults Get the results from the assertionObject and store the information in
|
|
6
|
-
* errors, warnings and ignored arrays
|
|
7
|
-
* @param {object} assertionObject Object with the assertion check results
|
|
8
|
-
* @param {object} assertionInfo Object with the assertion information
|
|
9
|
-
* @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function getResults(assertionObject, assertionInfo, resultInfo) {
|
|
13
|
-
const { results } = assertionObject;
|
|
14
|
-
if (Array.isArray(results)) {
|
|
15
|
-
getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo);
|
|
16
|
-
}
|
|
17
|
-
else if (results.ignored) {
|
|
18
|
-
getIgnored(assertionObject, assertionInfo, resultInfo);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = getResults;
|
|
1
|
+
const getErrorsAndWarnings = require('./getErrorsAndWarnings');
|
|
2
|
+
const getIgnored = require('./getIgnored');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @method getResults Get the results from the assertionObject and store the information in
|
|
6
|
+
* errors, warnings and ignored arrays
|
|
7
|
+
* @param {object} assertionObject Object with the assertion check results
|
|
8
|
+
* @param {object} assertionInfo Object with the assertion information
|
|
9
|
+
* @param {object} resultInfo Object that hosts the errors, warnings and ignored arrays to store the results
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function getResults(assertionObject, assertionInfo, resultInfo) {
|
|
13
|
+
const { results } = assertionObject;
|
|
14
|
+
if (Array.isArray(results)) {
|
|
15
|
+
getErrorsAndWarnings(assertionObject, assertionInfo, resultInfo);
|
|
16
|
+
}
|
|
17
|
+
else if (results.ignored) {
|
|
18
|
+
getIgnored(assertionObject, assertionInfo, resultInfo);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = getResults;
|
package/lib/getReturnObject.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @method getReturnObject Simple method to avoid redundancy of result object representation
|
|
3
|
-
* @param {object} resultInfo carrying the arrays errors, warnings and ignored
|
|
4
|
-
* @returns result object with information about overall errors, warnings and ignored
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function getReturnObject(resultInfo) {
|
|
8
|
-
const { errors, warnings, ignored } = resultInfo;
|
|
9
|
-
const result = {
|
|
10
|
-
errorCount: errors.length,
|
|
11
|
-
warningCount: warnings.length,
|
|
12
|
-
ignoredCount: ignored.length,
|
|
13
|
-
errors: errors,
|
|
14
|
-
warnings: warnings,
|
|
15
|
-
ignored: ignored
|
|
16
|
-
};
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = getReturnObject;
|
|
1
|
+
/**
|
|
2
|
+
* @method getReturnObject Simple method to avoid redundancy of result object representation
|
|
3
|
+
* @param {object} resultInfo carrying the arrays errors, warnings and ignored
|
|
4
|
+
* @returns result object with information about overall errors, warnings and ignored
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function getReturnObject(resultInfo) {
|
|
8
|
+
const { errors, warnings, ignored } = resultInfo;
|
|
9
|
+
const result = {
|
|
10
|
+
errorCount: errors.length,
|
|
11
|
+
warningCount: warnings.length,
|
|
12
|
+
ignoredCount: ignored.length,
|
|
13
|
+
errors: errors,
|
|
14
|
+
warnings: warnings,
|
|
15
|
+
ignored: ignored
|
|
16
|
+
};
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = getReturnObject;
|
package/lib/getSchematronMap.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
const Dom = require('@xmldom/xmldom').DOMParser;
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @
|
|
7
|
-
* @param {
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
.update(
|
|
19
|
-
.digest('hex');
|
|
20
|
-
if (options.parsedMap[hash]) {
|
|
21
|
-
return options.parsedMap[hash];
|
|
22
|
-
}
|
|
23
|
-
// If not in cache
|
|
24
|
-
// Load schematron doc
|
|
25
|
-
const schematronDoc = new Dom().parseFromString(schematron);
|
|
26
|
-
// Parse schematron
|
|
27
|
-
options.parsedMap
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
const Dom = require('@xmldom/xmldom').DOMParser;
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const parseSchematron = require('./parseSchematron');
|
|
4
|
+
/**
|
|
5
|
+
* @method getSchematronMap A method to get the schematron map from the provided schematron or utilize the data from cache or options object
|
|
6
|
+
* @param {string} schematron String data of schematron
|
|
7
|
+
* @param {object} options Options passed to the validator and any other variables passed between the methods
|
|
8
|
+
* @returns {object} parsed schemtaron map object
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function getSchematronMap(schematron, options = {}) {
|
|
12
|
+
if (options?.parsedSchematronMap) {
|
|
13
|
+
return options?.parsedSchematronMap;
|
|
14
|
+
}
|
|
15
|
+
const hash = crypto
|
|
16
|
+
.createHash('sha256')
|
|
17
|
+
.update(schematron)
|
|
18
|
+
.update(String(Boolean(options.includeWarnings)))
|
|
19
|
+
.digest('hex');
|
|
20
|
+
if (options.parsedMap[hash]) {
|
|
21
|
+
return options.parsedMap[hash];
|
|
22
|
+
}
|
|
23
|
+
// If not in cache
|
|
24
|
+
// Load schematron doc
|
|
25
|
+
const schematronDoc = new Dom().parseFromString(schematron);
|
|
26
|
+
// Parse schematron
|
|
27
|
+
if (Object.keys(options.parsedMap).length >= 32) {
|
|
28
|
+
delete options.parsedMap[Object.keys(options.parsedMap)[0]];
|
|
29
|
+
}
|
|
30
|
+
options.parsedMap[hash] = parseSchematron(schematronDoc, options);
|
|
31
|
+
return options.parsedMap[hash];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = getSchematronMap;
|