@mitre/hdf-parsers 3.6.0-rc.3 → 3.6.0-rc.5
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 +47 -11
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@ Parse and load Heimdall Data Format (HDF) documents with validation. Provides a
|
|
|
5
5
|
## Scope and Responsibilities
|
|
6
6
|
|
|
7
7
|
**hdf-parsers** provides validated parsing of HDF documents:
|
|
8
|
-
- Parse HDF Results and
|
|
8
|
+
- Parse HDF Results, Baseline, System, Plan, Evidence Package, and Comparison documents from JSON
|
|
9
9
|
- Automatic schema validation via hdf-validators
|
|
10
|
-
- Auto-detection of document type
|
|
10
|
+
- Auto-detection of document type across those six document types
|
|
11
11
|
- Type-safe output using hdf-schema types
|
|
12
12
|
- Detailed error reporting with validation messages
|
|
13
13
|
- Support for both TypeScript and Go implementations
|
|
@@ -37,7 +37,7 @@ npm install @mitre/hdf-parsers
|
|
|
37
37
|
### TypeScript
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
|
-
import { parseResults, parseBaseline, parse } from '@mitre/hdf-parsers';
|
|
40
|
+
import { parseResults, parseBaseline, parseSystem, parsePlan, parseEvidencePackage, parseComparison, parse } from '@mitre/hdf-parsers';
|
|
41
41
|
|
|
42
42
|
// Parse HDF Results
|
|
43
43
|
const json = '{"baselines":[...],"targets":[],"statistics":{}}';
|
|
@@ -64,11 +64,11 @@ if (baselineResult.success) {
|
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
66
|
// Auto-detect document type
|
|
67
|
-
const unknownJson = '...'; //
|
|
67
|
+
const unknownJson = '...'; // Any of the six detected document types
|
|
68
68
|
const autoResult = parse(unknownJson);
|
|
69
69
|
|
|
70
70
|
if (autoResult.success) {
|
|
71
|
-
console.log('Document type:', autoResult.type); // "results"
|
|
71
|
+
console.log('Document type:', autoResult.type); // "results" | "baseline" | "system" | "plan" | "evidencePackage" | "comparison"
|
|
72
72
|
console.log('Parsed data:', autoResult.data);
|
|
73
73
|
}
|
|
74
74
|
```
|
|
@@ -129,7 +129,7 @@ if result.Success {
|
|
|
129
129
|
result := parsers.Parse(data)
|
|
130
130
|
|
|
131
131
|
if result.Success {
|
|
132
|
-
fmt.Println("Document type:", result.Type) // "results" or "
|
|
132
|
+
fmt.Println("Document type:", result.Type) // "results", "baseline", "system", "plan", "evidencePackage", or "comparison"
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
@@ -153,9 +153,19 @@ Parse HDF Baseline document from JSON string or bytes.
|
|
|
153
153
|
- `input` - JSON string or Uint8Array to parse
|
|
154
154
|
- **Returns:** `ParseResult<HDFBaseline>` with parsed data or error
|
|
155
155
|
|
|
156
|
-
#### `
|
|
156
|
+
#### `parseSystem(input: string | Uint8Array): ParseResult<HDFSystem>`
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
#### `parsePlan(input: string | Uint8Array): ParseResult<HDFPlan>`
|
|
159
|
+
|
|
160
|
+
#### `parseEvidencePackage(input: string | Uint8Array): ParseResult<HDFEvidencePackage>`
|
|
161
|
+
|
|
162
|
+
#### `parseComparison(input: string | Uint8Array): ParseResult<HDFComparison>`
|
|
163
|
+
|
|
164
|
+
Typed parsers for the other HDF document types, with the same input handling and `ParseResult` shape as `parseResults`.
|
|
165
|
+
|
|
166
|
+
#### `parse(input: string | Uint8Array): ParseResult<HDFResults | HDFBaseline | HDFSystem | HDFPlan | HDFEvidencePackage | HDFComparison>`
|
|
167
|
+
|
|
168
|
+
Parse HDF document with auto-detection of type. Detection is by root-level discriminator, checked in this order: `baselines` (results), `requirementDiffs` (comparison), `assessments` (plan), `contents` (evidence package), `name` with `requirements` (baseline), then `components` (system).
|
|
159
169
|
|
|
160
170
|
- **Parameters:**
|
|
161
171
|
- `input` - JSON string or Uint8Array to parse
|
|
@@ -168,10 +178,18 @@ interface ParseResult<T> {
|
|
|
168
178
|
success: boolean; // True if parsing succeeded
|
|
169
179
|
data?: T; // Parsed data (undefined if failed)
|
|
170
180
|
error?: string; // Error message (undefined if succeeded)
|
|
171
|
-
type?: 'results' | 'baseline'; // Document type (only for parse())
|
|
181
|
+
type?: 'results' | 'baseline' | 'system' | 'plan' | 'evidencePackage' | 'comparison'; // Document type (only for parse())
|
|
172
182
|
}
|
|
173
183
|
```
|
|
174
184
|
|
|
185
|
+
#### `flattenOverlays(results: HDFResults): FlattenResult`
|
|
186
|
+
|
|
187
|
+
Flatten overlay and wrapper baselines in a parsed Results document into their root baselines. Handles deep nesting (overlay chains sharing control IDs via `parentBaseline`), wide nesting (wrapper profiles aggregating independent bases), and hybrids of both. Returns the flattened `results` plus `metadata` describing each merge (`FlattenMetadata`, `BaselineMerge`).
|
|
188
|
+
|
|
189
|
+
#### `normalizeTimestamps(input: string): string`
|
|
190
|
+
|
|
191
|
+
Rewrite zone-less ISO timestamps in raw JSON text to UTC (`Z`) so both language implementations parse them identically. Every parser above applies it before parsing.
|
|
192
|
+
|
|
175
193
|
### Go
|
|
176
194
|
|
|
177
195
|
#### `ParseResults(input []byte) ResultsParseResult`
|
|
@@ -190,14 +208,32 @@ Parse HDF Baseline document from JSON bytes.
|
|
|
190
208
|
- `input` - JSON bytes to parse
|
|
191
209
|
- **Returns:** `BaselineParseResult` with parsed data or error
|
|
192
210
|
|
|
211
|
+
#### `ParseSystem(input []byte) SystemParseResult`
|
|
212
|
+
|
|
213
|
+
#### `ParsePlan(input []byte) PlanParseResult`
|
|
214
|
+
|
|
215
|
+
#### `ParseEvidencePackage(input []byte) EvidencePackageParseResult`
|
|
216
|
+
|
|
217
|
+
#### `ParseComparison(input []byte) ComparisonParseResult`
|
|
218
|
+
|
|
219
|
+
Typed parsers for the other HDF document types; each result type carries `Success`, a typed `Data` pointer, and `Error`, like `ResultsParseResult`.
|
|
220
|
+
|
|
193
221
|
#### `Parse(input []byte) ParseResult`
|
|
194
222
|
|
|
195
|
-
Parse HDF document with auto-detection of type
|
|
223
|
+
Parse HDF document with auto-detection of type, using the same root-level discriminators as the TypeScript `parse()`.
|
|
196
224
|
|
|
197
225
|
- **Parameters:**
|
|
198
226
|
- `input` - JSON bytes to parse
|
|
199
227
|
- **Returns:** `ParseResult` with parsed data, type indicator, or error
|
|
200
228
|
|
|
229
|
+
#### `FlattenOverlays(results hdf.HDFResults) FlattenResult`
|
|
230
|
+
|
|
231
|
+
Go twin of `flattenOverlays`: merges overlay and wrapper baselines into their roots and returns the flattened `Results` with `Metadata` (`FlattenMetadata`, `BaselineMerge`, `MergePattern`).
|
|
232
|
+
|
|
233
|
+
#### `NormalizeTimestamps(input []byte) []byte`
|
|
234
|
+
|
|
235
|
+
Go twin of `normalizeTimestamps`; every parser above applies it before decoding.
|
|
236
|
+
|
|
201
237
|
#### Parse Result Types
|
|
202
238
|
|
|
203
239
|
```go
|
|
@@ -217,7 +253,7 @@ type ParseResult struct {
|
|
|
217
253
|
Success bool `json:"success"`
|
|
218
254
|
Data interface{} `json:"data,omitempty"`
|
|
219
255
|
Error string `json:"error,omitempty"`
|
|
220
|
-
Type string `json:"type,omitempty"` // "results" or "
|
|
256
|
+
Type string `json:"type,omitempty"` // "results", "baseline", "system", "plan", "evidencePackage", or "comparison"
|
|
221
257
|
}
|
|
222
258
|
```
|
|
223
259
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/hdf-parsers",
|
|
3
|
-
"version": "3.6.0-rc.
|
|
3
|
+
"version": "3.6.0-rc.5",
|
|
4
4
|
"description": "Parse and load HDF documents with validation",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"author": "MITRE Corporation",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@mitre/hdf-schema": "^3.6.0-rc.
|
|
29
|
-
"@mitre/hdf-validators": "^3.6.0-rc.
|
|
28
|
+
"@mitre/hdf-schema": "^3.6.0-rc.5",
|
|
29
|
+
"@mitre/hdf-validators": "^3.6.0-rc.5"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=22.0.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@stryker-mutator/core": "^9.5.1",
|
|
42
42
|
"@stryker-mutator/vitest-runner": "^9.5.1",
|
|
43
|
-
"@mitre/hdf-fixtures": "^3.6.0-rc.
|
|
43
|
+
"@mitre/hdf-fixtures": "^3.6.0-rc.5"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsdown",
|