@mitre/hdf-diff
Advanced tools
@@ -13,4 +13,4 @@ /** | ||
| * | ||
| * Loads and compiles all required schemas from the sibling hdf-schema package. | ||
| * The compiled validator is cached for performance on subsequent calls. | ||
| * Delegates to @mitre/hdf-validators which loads schemas from embedded | ||
| * bundled JSON (no filesystem access, no hardcoded version URLs). | ||
| * | ||
@@ -17,0 +17,0 @@ * @param doc - The document to validate (typically the output of `diffHdf()`) |
@@ -1,1 +0,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"} | ||
| {"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"} |
+7
-96
@@ -1,97 +0,7 @@ | ||
| import Ajv2020 from 'ajv/dist/2020.js'; | ||
| import addFormats from 'ajv-formats'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { resolve, dirname } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| /** Schema ID for the hdf-comparison schema */ | ||
| const COMPARISON_SCHEMA_ID = 'https://mitre.github.io/hdf-libs/schemas/hdf-comparison/v1.0.0'; | ||
| import { validateComparison as validatorsValidateComparison } from '@mitre/hdf-validators'; | ||
| /** | ||
| * Resolve the path to the hdf-schema package's schemas directory. | ||
| * | ||
| * In the monorepo layout, hdf-schema is a sibling package at `../hdf-schema`. | ||
| * The schemas are in `src/schemas/` within that package. | ||
| */ | ||
| function schemasDir() { | ||
| // From src/validate.ts (or dist/validate.js), go up to hdf-diff root, then to sibling | ||
| return resolve(__dirname, '..', '..', 'hdf-schema', 'src', 'schemas'); | ||
| } | ||
| /** | ||
| * Load a JSON schema file from the hdf-schema package. | ||
| */ | ||
| function loadSchema(relativePath) { | ||
| const fullPath = resolve(schemasDir(), relativePath); | ||
| return JSON.parse(readFileSync(fullPath, 'utf-8')); | ||
| } | ||
| /** Cached compiled validator function */ | ||
| let cachedValidator = null; | ||
| /** | ||
| * Build and cache an Ajv 2020-12 validator for the hdf-comparison schema. | ||
| * | ||
| * Loads schemas in dependency order: | ||
| * 1. All primitive schemas (common, platform, target, runner, statistics, result, extensions, comparison) | ||
| * 2. hdf-results schema (defines Evaluated_Requirement, referenced by comparison) | ||
| * 3. hdf-comparison schema (the top-level schema we validate against) | ||
| * | ||
| * The validator is compiled once and cached for all subsequent calls. | ||
| */ | ||
| function getValidator() { | ||
| if (cachedValidator) | ||
| return cachedValidator; | ||
| const ajv = new Ajv2020({ | ||
| strict: false, | ||
| allErrors: true, | ||
| validateFormats: true, | ||
| }); | ||
| addFormats(ajv); | ||
| // Load all primitive schemas first (order matters for $ref resolution) | ||
| const primitiveFiles = [ | ||
| 'primitives/common.schema.json', | ||
| 'primitives/platform.schema.json', | ||
| 'primitives/target.schema.json', | ||
| 'primitives/runner.schema.json', | ||
| 'primitives/statistics.schema.json', | ||
| 'primitives/result.schema.json', | ||
| 'primitives/amendments.schema.json', | ||
| 'primitives/extensions.schema.json', | ||
| 'primitives/parameter.schema.json', | ||
| 'primitives/component.schema.json', | ||
| 'primitives/data-flow.schema.json', | ||
| 'primitives/system.schema.json', | ||
| 'primitives/comparison.schema.json', | ||
| ]; | ||
| for (const file of primitiveFiles) { | ||
| ajv.addSchema(loadSchema(file)); | ||
| } | ||
| // Load hdf-results (defines Evaluated_Requirement referenced by comparison) | ||
| ajv.addSchema(loadSchema('hdf-results.schema.json')); | ||
| // Load and compile hdf-comparison (the top-level schema we validate against) | ||
| ajv.addSchema(loadSchema('hdf-comparison.schema.json')); | ||
| // getSchema compiles on first access; the schema was just added so this always succeeds | ||
| cachedValidator = ajv.getSchema(COMPARISON_SCHEMA_ID); | ||
| return cachedValidator; | ||
| } | ||
| /** | ||
| * Format Ajv validation errors into human-readable strings. | ||
| */ | ||
| function formatErrors(validate) { | ||
| /* c8 ignore next -- Ajv always populates errors array when validation fails */ | ||
| return (validate.errors ?? []).map((err) => { | ||
| const path = err.instancePath || '/'; | ||
| /* c8 ignore next -- Ajv always populates err.message */ | ||
| const msg = err.message ?? 'unknown error'; | ||
| // Ajv always populates err.params on validation errors. | ||
| // The else branch exists for defensive typing since params is typed as optional. | ||
| /* c8 ignore start */ | ||
| return err.params | ||
| ? `${path}: ${msg} (${JSON.stringify(err.params)})` | ||
| : `${path}: ${msg}`; | ||
| /* c8 ignore stop */ | ||
| }); | ||
| } | ||
| /** | ||
| * Validate a document against the hdf-comparison schema. | ||
| * | ||
| * Loads and compiles all required schemas from the sibling hdf-schema package. | ||
| * The compiled validator is cached for performance on subsequent calls. | ||
| * Delegates to @mitre/hdf-validators which loads schemas from embedded | ||
| * bundled JSON (no filesystem access, no hardcoded version URLs). | ||
| * | ||
@@ -102,8 +12,9 @@ * @param doc - The document to validate (typically the output of `diffHdf()`) | ||
| export function validateComparison(doc) { | ||
| const validate = getValidator(); | ||
| if (validate(doc)) { | ||
| const result = validatorsValidateComparison(doc); | ||
| if (result.valid) { | ||
| return { valid: true }; | ||
| } | ||
| return { valid: false, errors: formatErrors(validate) }; | ||
| const errors = result.errors.map(e => e.field === '(root)' ? e.message : `${e.field}: ${e.message}`); | ||
| return { valid: false, errors }; | ||
| } | ||
| //# sourceMappingURL=validate.js.map |
@@ -1,1 +0,1 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AAI,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"} | ||
| {"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"} |
+2
-3
| { | ||
| "name": "@mitre/hdf-diff", | ||
| "version": "3.0.0", | ||
| "version": "3.0.1", | ||
| "description": "Structured comparison of HDF evaluation results — tracks what changed, why, and by how much", | ||
@@ -40,4 +40,3 @@ "publishConfig": { | ||
| "dependencies": { | ||
| "ajv": "^8.17.0", | ||
| "ajv-formats": "^3.0.0" | ||
| "@mitre/hdf-validators": "workspace:*" | ||
| }, | ||
@@ -44,0 +43,0 @@ "engines": { |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1
-50%0
-100%209212
-2.48%3021
-2.86%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed