@mitre/hdf-diff 2.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.
@@ -10,8 +10,8 @@ export interface ValidationResult {
10
10
  /**
11
11
  * Validate a document against the hdf-comparison schema.
12
12
  *
13
- * Loads and compiles all required schemas from the sibling hdf-schema package.
14
- * The compiled validator is cached for performance on subsequent calls.
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
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,KAAK,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAkGD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAQjE"}
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 Ajv2020 from 'ajv/dist/2020.js';
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
- * Loads and compiles all required schemas from the sibling hdf-schema package.
96
- * The compiled validator is cached for performance on subsequent calls.
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 validate = getValidator();
103
- if (validate(doc)) {
12
+ const result = validatorsValidateComparison(doc);
13
+ if (result.valid) {
104
14
  return { valid: true };
105
15
  }
106
- return { valid: false, errors: formatErrors(validate) };
16
+ const errors = result.errors.map(e => e.field === '(root)' ? e.message : `${e.field}: ${e.message}`);
17
+ return { valid: false, errors };
107
18
  }
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Q,GAAG,YAAY,EAAE,CAAC;IAEhC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1D,CAAC"}
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": "2.0.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"
@@ -17,6 +17,18 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
+ "scripts": {
21
+ "build": "pnpm clean && tsc",
22
+ "clean": "rimraf dist",
23
+ "test": "pnpm run test:ts",
24
+ "test:ts": "vitest run",
25
+ "test:go": "echo 'No Go tests yet in hdf-diff'",
26
+ "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "type-check": "tsc --noEmit",
29
+ "lint": "eslint src test",
30
+ "lint:fix": "eslint src test --fix"
31
+ },
20
32
  "repository": {
21
33
  "type": "git",
22
34
  "url": "https://github.com/mitre/hdf-libs.git",
@@ -25,8 +37,7 @@
25
37
  "author": "MITRE Corporation",
26
38
  "license": "Apache-2.0",
27
39
  "dependencies": {
28
- "ajv": "^8.17.0",
29
- "ajv-formats": "^3.0.0"
40
+ "@mitre/hdf-validators": "workspace:*"
30
41
  },
31
42
  "engines": {
32
43
  "node": ">=20.0.0"
@@ -38,17 +49,5 @@
38
49
  "comparison",
39
50
  "security",
40
51
  "compliance"
41
- ],
42
- "scripts": {
43
- "build": "pnpm clean && tsc",
44
- "clean": "rimraf dist",
45
- "test": "pnpm run test:ts",
46
- "test:ts": "vitest run",
47
- "test:go": "echo 'No Go tests yet in hdf-diff'",
48
- "test:watch": "vitest",
49
- "test:coverage": "vitest run --coverage",
50
- "type-check": "tsc --noEmit",
51
- "lint": "eslint src test",
52
- "lint:fix": "eslint src test --fix"
53
- }
54
- }
52
+ ]
53
+ }
package/LICENSE.md DELETED
@@ -1,55 +0,0 @@
1
- # License
2
-
3
- Copyright © 2025 The MITRE Corporation.
4
-
5
- Approved for Public Release; Distribution Unlimited. Case Number 18-3678.
6
-
7
- Licensed under the Apache License, Version 2.0 (the "License"); you may
8
- not use this file except in compliance with the License. You may obtain a
9
- copy of the License at
10
-
11
- http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
- License for the specific language governing permissions and limitations
17
- under the License.
18
-
19
- ## Redistribution Terms
20
-
21
- Redistribution and use in source and binary forms, with or without
22
- modification, are permitted provided that the following conditions are
23
- met:
24
-
25
- - Redistributions of source code must retain the above copyright/digital
26
- rights legend, this list of conditions and the following Notice.
27
- - Redistributions in binary form must reproduce the above
28
- copyright/digital rights legend, this list of conditions and the
29
- following Notice in the documentation and/or other materials provided
30
- with the distribution.
31
- - Neither the name of The MITRE Corporation nor the names of its contributors
32
- may be used to endorse or promote products derived from this software
33
- without specific prior written permission.
34
-
35
- ## Notice
36
-
37
- The MITRE Corporation grants permission to reproduce, distribute, modify, and
38
- otherwise use this software to the extent permitted by the licensed terms
39
- provided in the LICENSE file included with this project.
40
-
41
- This software was produced by The MITRE Corporation for the U.S. Government
42
- under contract. As such the U.S. Government has certain use and data
43
- rights in this software. No use other than those granted to the U.S.
44
- Government, or to those acting on behalf of the U.S. Government, under
45
- these contract arrangements is authorized without the express written
46
- permission of The MITRE Corporation.
47
-
48
- Some files in this codebase were generated by generative AI, under the
49
- direction and review of The MITRE Corporation employees, for the purpose of
50
- development efficiency. All AI-generated code functionality was validated
51
- by standard quality and assurance testing.
52
-
53
- For further information, please contact The MITRE Corporation,
54
- Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539,
55
- (703) 983-6000.