@mitre/hdf-diff 3.0.0 → 3.0.1
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/dist/validate.d.ts +2 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +7 -96
- package/dist/validate.js.map +1 -1
- package/package.json +2 -3
package/dist/validate.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface ValidationResult {
|
|
|
10
10
|
/**
|
|
11
11
|
* Validate a document against the hdf-comparison schema.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Delegates to @mitre/hdf-validators which loads schemas from embedded
|
|
14
|
+
* bundled JSON (no filesystem access, no hardcoded version URLs).
|
|
15
15
|
*
|
|
16
16
|
* @param doc - The document to validate (typically the output of `diffHdf()`)
|
|
17
17
|
* @returns Validation result with `valid` boolean and optional `errors` array
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,KAAK,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAWjE"}
|
package/dist/validate.js
CHANGED
|
@@ -1,108 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import addFormats from 'ajv-formats';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { resolve, dirname } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
/** Schema ID for the hdf-comparison schema */
|
|
8
|
-
const COMPARISON_SCHEMA_ID = 'https://mitre.github.io/hdf-libs/schemas/hdf-comparison/v1.0.0';
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the path to the hdf-schema package's schemas directory.
|
|
11
|
-
*
|
|
12
|
-
* In the monorepo layout, hdf-schema is a sibling package at `../hdf-schema`.
|
|
13
|
-
* The schemas are in `src/schemas/` within that package.
|
|
14
|
-
*/
|
|
15
|
-
function schemasDir() {
|
|
16
|
-
// From src/validate.ts (or dist/validate.js), go up to hdf-diff root, then to sibling
|
|
17
|
-
return resolve(__dirname, '..', '..', 'hdf-schema', 'src', 'schemas');
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Load a JSON schema file from the hdf-schema package.
|
|
21
|
-
*/
|
|
22
|
-
function loadSchema(relativePath) {
|
|
23
|
-
const fullPath = resolve(schemasDir(), relativePath);
|
|
24
|
-
return JSON.parse(readFileSync(fullPath, 'utf-8'));
|
|
25
|
-
}
|
|
26
|
-
/** Cached compiled validator function */
|
|
27
|
-
let cachedValidator = null;
|
|
28
|
-
/**
|
|
29
|
-
* Build and cache an Ajv 2020-12 validator for the hdf-comparison schema.
|
|
30
|
-
*
|
|
31
|
-
* Loads schemas in dependency order:
|
|
32
|
-
* 1. All primitive schemas (common, platform, target, runner, statistics, result, extensions, comparison)
|
|
33
|
-
* 2. hdf-results schema (defines Evaluated_Requirement, referenced by comparison)
|
|
34
|
-
* 3. hdf-comparison schema (the top-level schema we validate against)
|
|
35
|
-
*
|
|
36
|
-
* The validator is compiled once and cached for all subsequent calls.
|
|
37
|
-
*/
|
|
38
|
-
function getValidator() {
|
|
39
|
-
if (cachedValidator)
|
|
40
|
-
return cachedValidator;
|
|
41
|
-
const ajv = new Ajv2020({
|
|
42
|
-
strict: false,
|
|
43
|
-
allErrors: true,
|
|
44
|
-
validateFormats: true,
|
|
45
|
-
});
|
|
46
|
-
addFormats(ajv);
|
|
47
|
-
// Load all primitive schemas first (order matters for $ref resolution)
|
|
48
|
-
const primitiveFiles = [
|
|
49
|
-
'primitives/common.schema.json',
|
|
50
|
-
'primitives/platform.schema.json',
|
|
51
|
-
'primitives/target.schema.json',
|
|
52
|
-
'primitives/runner.schema.json',
|
|
53
|
-
'primitives/statistics.schema.json',
|
|
54
|
-
'primitives/result.schema.json',
|
|
55
|
-
'primitives/amendments.schema.json',
|
|
56
|
-
'primitives/extensions.schema.json',
|
|
57
|
-
'primitives/parameter.schema.json',
|
|
58
|
-
'primitives/component.schema.json',
|
|
59
|
-
'primitives/data-flow.schema.json',
|
|
60
|
-
'primitives/system.schema.json',
|
|
61
|
-
'primitives/comparison.schema.json',
|
|
62
|
-
];
|
|
63
|
-
for (const file of primitiveFiles) {
|
|
64
|
-
ajv.addSchema(loadSchema(file));
|
|
65
|
-
}
|
|
66
|
-
// Load hdf-results (defines Evaluated_Requirement referenced by comparison)
|
|
67
|
-
ajv.addSchema(loadSchema('hdf-results.schema.json'));
|
|
68
|
-
// Load and compile hdf-comparison (the top-level schema we validate against)
|
|
69
|
-
ajv.addSchema(loadSchema('hdf-comparison.schema.json'));
|
|
70
|
-
// getSchema compiles on first access; the schema was just added so this always succeeds
|
|
71
|
-
cachedValidator = ajv.getSchema(COMPARISON_SCHEMA_ID);
|
|
72
|
-
return cachedValidator;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Format Ajv validation errors into human-readable strings.
|
|
76
|
-
*/
|
|
77
|
-
function formatErrors(validate) {
|
|
78
|
-
/* c8 ignore next -- Ajv always populates errors array when validation fails */
|
|
79
|
-
return (validate.errors ?? []).map((err) => {
|
|
80
|
-
const path = err.instancePath || '/';
|
|
81
|
-
/* c8 ignore next -- Ajv always populates err.message */
|
|
82
|
-
const msg = err.message ?? 'unknown error';
|
|
83
|
-
// Ajv always populates err.params on validation errors.
|
|
84
|
-
// The else branch exists for defensive typing since params is typed as optional.
|
|
85
|
-
/* c8 ignore start */
|
|
86
|
-
return err.params
|
|
87
|
-
? `${path}: ${msg} (${JSON.stringify(err.params)})`
|
|
88
|
-
: `${path}: ${msg}`;
|
|
89
|
-
/* c8 ignore stop */
|
|
90
|
-
});
|
|
91
|
-
}
|
|
1
|
+
import { validateComparison as validatorsValidateComparison } from '@mitre/hdf-validators';
|
|
92
2
|
/**
|
|
93
3
|
* Validate a document against the hdf-comparison schema.
|
|
94
4
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
5
|
+
* Delegates to @mitre/hdf-validators which loads schemas from embedded
|
|
6
|
+
* bundled JSON (no filesystem access, no hardcoded version URLs).
|
|
97
7
|
*
|
|
98
8
|
* @param doc - The document to validate (typically the output of `diffHdf()`)
|
|
99
9
|
* @returns Validation result with `valid` boolean and optional `errors` array
|
|
100
10
|
*/
|
|
101
11
|
export function validateComparison(doc) {
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
12
|
+
const result = validatorsValidateComparison(doc);
|
|
13
|
+
if (result.valid) {
|
|
104
14
|
return { valid: true };
|
|
105
15
|
}
|
|
106
|
-
|
|
16
|
+
const errors = result.errors.map(e => e.field === '(root)' ? e.message : `${e.field}: ${e.message}`);
|
|
17
|
+
return { valid: false, errors };
|
|
107
18
|
}
|
|
108
19
|
//# sourceMappingURL=validate.js.map
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAY3F;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,MAAM,MAAM,GAAG,4BAA4B,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACnC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,OAAO,EAAE,CAC9D,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/hdf-diff",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Structured comparison of HDF evaluation results — tracks what changed, why, and by how much",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"author": "MITRE Corporation",
|
|
38
38
|
"license": "Apache-2.0",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"ajv-formats": "^3.0.0"
|
|
40
|
+
"@mitre/hdf-validators": "workspace:*"
|
|
42
41
|
},
|
|
43
42
|
"engines": {
|
|
44
43
|
"node": ">=20.0.0"
|