@mitre/hdf-extension-graph 3.2.0 → 3.3.0
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/README.md +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -30,9 +30,9 @@ Requires `@mitre/hdf-schema` as a peer dependency.
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
import { buildExtensionGraph } from '@mitre/hdf-extension-graph';
|
|
33
|
-
import type {
|
|
33
|
+
import type { HDFResults } from '@mitre/hdf-schema';
|
|
34
34
|
|
|
35
|
-
const hdfResults:
|
|
35
|
+
const hdfResults: HDFResults = JSON.parse(fileContents);
|
|
36
36
|
const graph = buildExtensionGraph(hdfResults);
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -102,7 +102,7 @@ console.log(chain.map(b => b.data.name));
|
|
|
102
102
|
|
|
103
103
|
## API
|
|
104
104
|
|
|
105
|
-
### `buildExtensionGraph(results:
|
|
105
|
+
### `buildExtensionGraph(results: HDFResults): ExtensionGraph`
|
|
106
106
|
|
|
107
107
|
Builds a bidirectional extension graph from an HDF Results file. Links baselines via `parentBaseline` and requirements by matching `id` across linked baselines.
|
|
108
108
|
|
|
@@ -121,7 +121,7 @@ Builds a bidirectional extension graph from an HDF Results file. Links baselines
|
|
|
121
121
|
| Property | Type | Description |
|
|
122
122
|
|---|---|---|
|
|
123
123
|
| `data` | `EvaluatedBaseline` | Original baseline data |
|
|
124
|
-
| `sourcedFrom` | `
|
|
124
|
+
| `sourcedFrom` | `HDFResults` | The results file this came from |
|
|
125
125
|
| `extendsFrom` | `ContextualizedBaseline[]` | Parent baselines |
|
|
126
126
|
| `extendedBy` | `ContextualizedBaseline[]` | Child baselines |
|
|
127
127
|
| `requirements` | `ContextualizedRequirement[]` | Wrapped requirements |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvaluatedBaseline, EvaluatedRequirement,
|
|
1
|
+
import { EvaluatedBaseline, EvaluatedRequirement, HDFResults } from "@mitre/hdf-schema";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
/** A detected change between an overlay requirement and its parent. */
|
|
@@ -43,15 +43,15 @@ declare class ContextualizedRequirement {
|
|
|
43
43
|
declare class ContextualizedBaseline {
|
|
44
44
|
/** The original baseline data. */
|
|
45
45
|
readonly data: EvaluatedBaseline;
|
|
46
|
-
/** The
|
|
47
|
-
readonly sourcedFrom:
|
|
46
|
+
/** The HDFResults this baseline was sourced from. */
|
|
47
|
+
readonly sourcedFrom: HDFResults;
|
|
48
48
|
/** Parent baselines that this baseline extends. */
|
|
49
49
|
readonly extendsFrom: ContextualizedBaseline[];
|
|
50
50
|
/** Child baselines that extend this baseline. */
|
|
51
51
|
readonly extendedBy: ContextualizedBaseline[];
|
|
52
52
|
/** Contextualized wrappers for each requirement in this baseline. */
|
|
53
53
|
readonly requirements: ContextualizedRequirement[];
|
|
54
|
-
constructor(data: EvaluatedBaseline, sourcedFrom:
|
|
54
|
+
constructor(data: EvaluatedBaseline, sourcedFrom: HDFResults);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* A bidirectional extension graph built from an HDF Results file.
|
|
@@ -79,7 +79,7 @@ declare class ExtensionGraph {
|
|
|
79
79
|
* 3. Collect all requirements into a flat array
|
|
80
80
|
* 4. Link requirements by id matching across linked baselines
|
|
81
81
|
*/
|
|
82
|
-
declare function buildExtensionGraph(results:
|
|
82
|
+
declare function buildExtensionGraph(results: HDFResults): ExtensionGraph;
|
|
83
83
|
//#endregion
|
|
84
84
|
export { ContextualizedBaseline, ContextualizedRequirement, ExtensionGraph, Modification, buildExtensionGraph };
|
|
85
85
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index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AG9B,SAAA,WAAoB,sBAAA,IACpB,YAAA,WAAuB,yBAAA;EApCV;EA2Cf,YAAA,CAAa,IAAA,WAAe,sBAAA;EAxCN;EA6CtB,gBAAA,CAAiB,EAAA,WAAa,yBAAA;EA1CR;EAAA,IA+ClB,aAAA,IAAiB,sBAAA;AAAA;;;;;;;;;AAvCuC;iBAqD9C,mBAAA,CAAoB,OAAA,EAAS,UAAA,GAAa,cAAc"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { HdfResults, EvaluatedBaseline, EvaluatedRequirement } from '@mitre/hdf-schema';\n\n/** Fields compared for modification detection between overlay and parent. */\nconst TRACKED_FIELDS: readonly (string & keyof EvaluatedRequirement)[] = ['impact', 'title', 'severity', 'effectiveImpact', 'disposition'];\n\n/** A detected change between an overlay requirement and its parent. */\nexport interface Modification {\n field: string;\n originalValue: unknown;\n newValue: unknown;\n inBaseline: string;\n}\n\n/**\n * Wraps an EvaluatedRequirement with bidirectional extension links\n * and derived properties for navigating extension chains.\n */\nexport class ContextualizedRequirement {\n /** The original requirement data. */\n readonly data: EvaluatedRequirement;\n\n /** The baseline this requirement belongs to. */\n readonly sourcedFrom: ContextualizedBaseline;\n\n /** Requirements in parent baselines that this requirement extends (overlays). */\n readonly extendsFrom: ContextualizedRequirement[] = [];\n\n /** Requirements in child baselines that extend this requirement. */\n readonly extendedBy: ContextualizedRequirement[] = [];\n\n constructor(data: EvaluatedRequirement, sourcedFrom: ContextualizedBaseline) {\n this.data = data;\n this.sourcedFrom = sourcedFrom;\n }\n\n /** The root (base) requirement at the bottom of the extension chain. */\n get root(): ContextualizedRequirement {\n if (this.extendsFrom.length === 0) {\n return this;\n }\n // Walk to the first parent's root (first match, like Heimdall2)\n return this.extendsFrom[0]!.root;\n }\n\n /** True if this overlay adds no new code (empty/undefined or matches root). */\n get isRedundant(): boolean {\n if (this.extendsFrom.length === 0) {\n return false;\n }\n const code = this.data.code;\n if (!code) {\n return true;\n }\n return code === this.root.data.code;\n }\n\n /**\n * Full code concatenated from all layers, with baseline name headers.\n * Skips redundant overlay layers. Returns empty string if no code exists.\n */\n get fullCode(): string {\n if (this.isRedundant && this.extendsFrom.length > 0) {\n return this.extendsFrom[0]!.fullCode;\n }\n const code = this.data.code;\n if (!code) {\n return '';\n }\n const header = `# ${this.sourcedFrom.data.name}\\n${code}`;\n if (this.extendsFrom.length === 0) {\n return header;\n }\n const parentCode = this.extendsFrom[0]!.fullCode;\n return parentCode ? `${header}\\n\\n${parentCode}` : header;\n }\n\n /** Ordered chain of baselines from root to this requirement's baseline. */\n get extensionChain(): ContextualizedBaseline[] {\n if (this.extendsFrom.length === 0) {\n return [this.sourcedFrom];\n }\n return [...this.extendsFrom[0]!.extensionChain, this.sourcedFrom];\n }\n\n /** Fields that differ between this requirement and its immediate parent. */\n get modifications(): Modification[] {\n if (this.extendsFrom.length === 0) {\n return [];\n }\n const parent = this.extendsFrom[0]!;\n const mods: Modification[] = [];\n for (const field of TRACKED_FIELDS) {\n const parentVal = (parent.data as Record<string, unknown>)[field];\n const thisVal = (this.data as Record<string, unknown>)[field];\n if (parentVal !== thisVal) {\n mods.push({\n field,\n originalValue: parentVal,\n newValue: thisVal,\n inBaseline: this.sourcedFrom.data.name,\n });\n }\n }\n return mods;\n }\n}\n\n/**\n * Wraps an EvaluatedBaseline with bidirectional extension links\n * and contextualized requirements.\n */\nexport class ContextualizedBaseline {\n /** The original baseline data. */\n readonly data: EvaluatedBaseline;\n\n /** The HdfResults this baseline was sourced from. */\n readonly sourcedFrom: HdfResults;\n\n /** Parent baselines that this baseline extends. */\n readonly extendsFrom: ContextualizedBaseline[] = [];\n\n /** Child baselines that extend this baseline. */\n readonly extendedBy: ContextualizedBaseline[] = [];\n\n /** Contextualized wrappers for each requirement in this baseline. */\n readonly requirements: ContextualizedRequirement[];\n\n constructor(data: EvaluatedBaseline, sourcedFrom: HdfResults) {\n this.data = data;\n this.sourcedFrom = sourcedFrom;\n this.requirements = data.requirements.map(\n (req) => new ContextualizedRequirement(req, this)\n );\n }\n}\n\n/**\n * A bidirectional extension graph built from an HDF Results file.\n * Contains all baselines and requirements with their extension relationships.\n */\nexport class ExtensionGraph {\n /** All contextualized baselines in the graph. */\n readonly baselines: readonly ContextualizedBaseline[];\n\n /** All contextualized requirements across all baselines. */\n readonly requirements: readonly ContextualizedRequirement[];\n\n constructor(\n baselines: readonly ContextualizedBaseline[],\n requirements: readonly ContextualizedRequirement[]\n ) {\n this.baselines = baselines;\n this.requirements = requirements;\n }\n\n /** Find a baseline by name. Returns undefined if not found. */\n findBaseline(name: string): ContextualizedBaseline | undefined {\n return this.baselines.find((b) => b.data.name === name);\n }\n\n /** Find all requirements with the given id across all baselines. */\n findRequirements(id: string): ContextualizedRequirement[] {\n return this.requirements.filter((r) => r.data.id === id);\n }\n\n /** Baselines that have no parent (root of extension chains). */\n get rootBaselines(): ContextualizedBaseline[] {\n return this.baselines.filter((b) => !b.data.parentBaseline);\n }\n}\n\n/**\n * Build a bidirectional extension graph from an HDF Results file.\n *\n * Four phases:\n * 1. Wrap each EvaluatedBaseline in a ContextualizedBaseline\n * 2. Link baselines via parentBaseline name matching (bidirectional)\n * 3. Collect all requirements into a flat array\n * 4. Link requirements by id matching across linked baselines\n */\nexport function buildExtensionGraph(results: HdfResults): ExtensionGraph {\n // Phase 1: Wrap baselines\n const baselineMap = new Map<string, ContextualizedBaseline>();\n const baselines: ContextualizedBaseline[] = [];\n\n for (const baseline of results.baselines) {\n const ctx = new ContextualizedBaseline(baseline, results);\n baselines.push(ctx);\n baselineMap.set(baseline.name, ctx);\n }\n\n // Phase 2: Link baselines via parentBaseline\n for (const ctx of baselines) {\n const parentName = ctx.data.parentBaseline;\n if (parentName) {\n const parent = baselineMap.get(parentName);\n if (parent) {\n ctx.extendsFrom.push(parent);\n parent.extendedBy.push(ctx);\n }\n }\n }\n\n // Phase 3: Collect all requirements\n const allRequirements: ContextualizedRequirement[] = [];\n for (const ctx of baselines) {\n allRequirements.push(...ctx.requirements);\n }\n\n // Phase 4: Link requirements by id across linked baselines\n for (const ctx of baselines) {\n if (ctx.extendsFrom.length === 0) {\n continue;\n }\n for (const childReq of ctx.requirements) {\n for (const parentBaseline of ctx.extendsFrom) {\n const parentReq = parentBaseline.requirements.find(\n (r) => r.data.id === childReq.data.id\n );\n if (parentReq) {\n childReq.extendsFrom.push(parentReq);\n parentReq.extendedBy.push(childReq);\n }\n }\n }\n }\n\n return new ExtensionGraph(baselines, allRequirements);\n}\n"],"mappings":";;AAGA,MAAM,iBAAmE;CAAC;CAAU;CAAS;CAAY;CAAmB;AAAa;;;;;AAczI,IAAa,4BAAb,MAAuC;CAarC,YAAY,MAA4B,aAAqC;qBALzB,CAAC;oBAGF,CAAC;EAGlD,KAAK,OAAO;EACZ,KAAK,cAAc;CACrB;;CAGA,IAAI,OAAkC;EACpC,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO;EAGT,OAAO,KAAK,YAAY,GAAI;CAC9B;;CAGA,IAAI,cAAuB;EACzB,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO;EAET,MAAM,OAAO,KAAK,KAAK;EACvB,IAAI,CAAC,MACH,OAAO;EAET,OAAO,SAAS,KAAK,KAAK,KAAK;CACjC;;;;;CAMA,IAAI,WAAmB;EACrB,IAAI,KAAK,eAAe,KAAK,YAAY,SAAS,GAChD,OAAO,KAAK,YAAY,GAAI;EAE9B,MAAM,OAAO,KAAK,KAAK;EACvB,IAAI,CAAC,MACH,OAAO;EAET,MAAM,SAAS,KAAK,KAAK,YAAY,KAAK,KAAK,IAAI;EACnD,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO;EAET,MAAM,aAAa,KAAK,YAAY,GAAI;EACxC,OAAO,aAAa,GAAG,OAAO,MAAM,eAAe;CACrD;;CAGA,IAAI,iBAA2C;EAC7C,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO,CAAC,KAAK,WAA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,MAAM,GAAG;CACpC;CAGA,KAAK,MAAM,OAAO,WAAW;EAC3B,MAAM,aAAa,IAAI,KAAK;EAC5B,IAAI,YAAY;GACd,MAAM,SAAS,YAAY,IAAI,UAAU;GACzC,IAAI,QAAQ;IACV,IAAI,YAAY,KAAK,MAAM;IAC3B,OAAO,WAAW,KAAK,GAAG;GAC5B;EACF;CACF;CAGA,MAAM,kBAA+C,CAAC;CACtD,KAAK,MAAM,OAAO,WAChB,gBAAgB,KAAK,GAAG,IAAI,YAAY;CAI1C,KAAK,MAAM,OAAO,WAAW;EAC3B,IAAI,IAAI,YAAY,WAAW,GAC7B;EAEF,KAAK,MAAM,YAAY,IAAI,cACzB,KAAK,MAAM,kBAAkB,IAAI,aAAa;GAC5C,MAAM,YAAY,eAAe,aAAa,MAC3C,MAAM,EAAE,KAAK,OAAO,SAAS,KAAK,EACrC;GACA,IAAI,WAAW;IACb,SAAS,YAAY,KAAK,SAAS;IACnC,UAAU,WAAW,KAAK,QAAQ;GACpC;EACF;CAEJ;CAEA,OAAO,IAAI,eAAe,WAAW,eAAe;AACtD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { HDFResults, EvaluatedBaseline, EvaluatedRequirement } from '@mitre/hdf-schema';\n\n/** Fields compared for modification detection between overlay and parent. */\nconst TRACKED_FIELDS: readonly (string & keyof EvaluatedRequirement)[] = ['impact', 'title', 'severity', 'effectiveImpact', 'disposition'];\n\n/** A detected change between an overlay requirement and its parent. */\nexport interface Modification {\n field: string;\n originalValue: unknown;\n newValue: unknown;\n inBaseline: string;\n}\n\n/**\n * Wraps an EvaluatedRequirement with bidirectional extension links\n * and derived properties for navigating extension chains.\n */\nexport class ContextualizedRequirement {\n /** The original requirement data. */\n readonly data: EvaluatedRequirement;\n\n /** The baseline this requirement belongs to. */\n readonly sourcedFrom: ContextualizedBaseline;\n\n /** Requirements in parent baselines that this requirement extends (overlays). */\n readonly extendsFrom: ContextualizedRequirement[] = [];\n\n /** Requirements in child baselines that extend this requirement. */\n readonly extendedBy: ContextualizedRequirement[] = [];\n\n constructor(data: EvaluatedRequirement, sourcedFrom: ContextualizedBaseline) {\n this.data = data;\n this.sourcedFrom = sourcedFrom;\n }\n\n /** The root (base) requirement at the bottom of the extension chain. */\n get root(): ContextualizedRequirement {\n if (this.extendsFrom.length === 0) {\n return this;\n }\n // Walk to the first parent's root (first match, like Heimdall2)\n return this.extendsFrom[0]!.root;\n }\n\n /** True if this overlay adds no new code (empty/undefined or matches root). */\n get isRedundant(): boolean {\n if (this.extendsFrom.length === 0) {\n return false;\n }\n const code = this.data.code;\n if (!code) {\n return true;\n }\n return code === this.root.data.code;\n }\n\n /**\n * Full code concatenated from all layers, with baseline name headers.\n * Skips redundant overlay layers. Returns empty string if no code exists.\n */\n get fullCode(): string {\n if (this.isRedundant && this.extendsFrom.length > 0) {\n return this.extendsFrom[0]!.fullCode;\n }\n const code = this.data.code;\n if (!code) {\n return '';\n }\n const header = `# ${this.sourcedFrom.data.name}\\n${code}`;\n if (this.extendsFrom.length === 0) {\n return header;\n }\n const parentCode = this.extendsFrom[0]!.fullCode;\n return parentCode ? `${header}\\n\\n${parentCode}` : header;\n }\n\n /** Ordered chain of baselines from root to this requirement's baseline. */\n get extensionChain(): ContextualizedBaseline[] {\n if (this.extendsFrom.length === 0) {\n return [this.sourcedFrom];\n }\n return [...this.extendsFrom[0]!.extensionChain, this.sourcedFrom];\n }\n\n /** Fields that differ between this requirement and its immediate parent. */\n get modifications(): Modification[] {\n if (this.extendsFrom.length === 0) {\n return [];\n }\n const parent = this.extendsFrom[0]!;\n const mods: Modification[] = [];\n for (const field of TRACKED_FIELDS) {\n const parentVal = (parent.data as Record<string, unknown>)[field];\n const thisVal = (this.data as Record<string, unknown>)[field];\n if (parentVal !== thisVal) {\n mods.push({\n field,\n originalValue: parentVal,\n newValue: thisVal,\n inBaseline: this.sourcedFrom.data.name,\n });\n }\n }\n return mods;\n }\n}\n\n/**\n * Wraps an EvaluatedBaseline with bidirectional extension links\n * and contextualized requirements.\n */\nexport class ContextualizedBaseline {\n /** The original baseline data. */\n readonly data: EvaluatedBaseline;\n\n /** The HDFResults this baseline was sourced from. */\n readonly sourcedFrom: HDFResults;\n\n /** Parent baselines that this baseline extends. */\n readonly extendsFrom: ContextualizedBaseline[] = [];\n\n /** Child baselines that extend this baseline. */\n readonly extendedBy: ContextualizedBaseline[] = [];\n\n /** Contextualized wrappers for each requirement in this baseline. */\n readonly requirements: ContextualizedRequirement[];\n\n constructor(data: EvaluatedBaseline, sourcedFrom: HDFResults) {\n this.data = data;\n this.sourcedFrom = sourcedFrom;\n this.requirements = data.requirements.map(\n (req) => new ContextualizedRequirement(req, this)\n );\n }\n}\n\n/**\n * A bidirectional extension graph built from an HDF Results file.\n * Contains all baselines and requirements with their extension relationships.\n */\nexport class ExtensionGraph {\n /** All contextualized baselines in the graph. */\n readonly baselines: readonly ContextualizedBaseline[];\n\n /** All contextualized requirements across all baselines. */\n readonly requirements: readonly ContextualizedRequirement[];\n\n constructor(\n baselines: readonly ContextualizedBaseline[],\n requirements: readonly ContextualizedRequirement[]\n ) {\n this.baselines = baselines;\n this.requirements = requirements;\n }\n\n /** Find a baseline by name. Returns undefined if not found. */\n findBaseline(name: string): ContextualizedBaseline | undefined {\n return this.baselines.find((b) => b.data.name === name);\n }\n\n /** Find all requirements with the given id across all baselines. */\n findRequirements(id: string): ContextualizedRequirement[] {\n return this.requirements.filter((r) => r.data.id === id);\n }\n\n /** Baselines that have no parent (root of extension chains). */\n get rootBaselines(): ContextualizedBaseline[] {\n return this.baselines.filter((b) => !b.data.parentBaseline);\n }\n}\n\n/**\n * Build a bidirectional extension graph from an HDF Results file.\n *\n * Four phases:\n * 1. Wrap each EvaluatedBaseline in a ContextualizedBaseline\n * 2. Link baselines via parentBaseline name matching (bidirectional)\n * 3. Collect all requirements into a flat array\n * 4. Link requirements by id matching across linked baselines\n */\nexport function buildExtensionGraph(results: HDFResults): ExtensionGraph {\n // Phase 1: Wrap baselines\n const baselineMap = new Map<string, ContextualizedBaseline>();\n const baselines: ContextualizedBaseline[] = [];\n\n for (const baseline of results.baselines) {\n const ctx = new ContextualizedBaseline(baseline, results);\n baselines.push(ctx);\n baselineMap.set(baseline.name, ctx);\n }\n\n // Phase 2: Link baselines via parentBaseline\n for (const ctx of baselines) {\n const parentName = ctx.data.parentBaseline;\n if (parentName) {\n const parent = baselineMap.get(parentName);\n if (parent) {\n ctx.extendsFrom.push(parent);\n parent.extendedBy.push(ctx);\n }\n }\n }\n\n // Phase 3: Collect all requirements\n const allRequirements: ContextualizedRequirement[] = [];\n for (const ctx of baselines) {\n allRequirements.push(...ctx.requirements);\n }\n\n // Phase 4: Link requirements by id across linked baselines\n for (const ctx of baselines) {\n if (ctx.extendsFrom.length === 0) {\n continue;\n }\n for (const childReq of ctx.requirements) {\n for (const parentBaseline of ctx.extendsFrom) {\n const parentReq = parentBaseline.requirements.find(\n (r) => r.data.id === childReq.data.id\n );\n if (parentReq) {\n childReq.extendsFrom.push(parentReq);\n parentReq.extendedBy.push(childReq);\n }\n }\n }\n }\n\n return new ExtensionGraph(baselines, allRequirements);\n}\n"],"mappings":";;AAGA,MAAM,iBAAmE;CAAC;CAAU;CAAS;CAAY;CAAmB;AAAa;;;;;AAczI,IAAa,4BAAb,MAAuC;CAarC,YAAY,MAA4B,aAAqC;qBALzB,CAAC;oBAGF,CAAC;EAGlD,KAAK,OAAO;EACZ,KAAK,cAAc;CACrB;;CAGA,IAAI,OAAkC;EACpC,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO;EAGT,OAAO,KAAK,YAAY,EAAE,CAAE;CAC9B;;CAGA,IAAI,cAAuB;EACzB,IAAI,KAAK,YAAY,WAAW,GAC9B,OAAO;EAET,MAAM,OAAO,KAAK,KAAK;EACvB,IAAI,CAAC,MACH,OAAO;EAET,OAAO,SAAS,KAAK,KAAK,KAAK;CACjC;;;;;CAMA,IAAI,WAAmB;EACrB,IAAI,KAAK,eAA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graph processing for HDF profile/baseline hierarchies",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,7 +25,11 @@
|
|
|
25
25
|
"author": "MITRE Corporation",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@mitre/hdf-schema": "^3.
|
|
28
|
+
"@mitre/hdf-schema": "^3.3.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@mitre/hdf-fixtures": "^3.3.0",
|
|
32
|
+
"@mitre/hdf-parsers": "^3.3.0"
|
|
29
33
|
},
|
|
30
34
|
"engines": {
|
|
31
35
|
"node": ">=22.0.0"
|