@mitre/hdf-validators 3.0.0 → 3.1.0-rc.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/LICENSE.md +55 -0
- package/README.md +45 -5
- package/dist/index.d.ts +19 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -219
- package/dist/index.js.map +1 -1
- package/package.json +19 -20
package/LICENSE.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @mitre/hdf-validators
|
|
2
2
|
|
|
3
|
-
JSON Schema validation for Heimdall Data Format (HDF) documents. Validates HDF
|
|
3
|
+
JSON Schema validation for Heimdall Data Format (HDF) documents. Validates all 7 HDF document types against their official schemas to ensure structural correctness and data integrity.
|
|
4
4
|
|
|
5
5
|
## Scope and Responsibilities
|
|
6
6
|
|
|
7
7
|
**hdf-validators** provides schema-based validation:
|
|
8
|
-
- Validate HDF Results
|
|
9
|
-
-
|
|
8
|
+
- Validate all HDF document types: Results, Baseline, System, Plan, Amendments, Evidence Package, Comparison
|
|
9
|
+
- Auto-detect document type via the generic `validate()` function
|
|
10
10
|
- Detailed error reporting with field-level validation messages
|
|
11
11
|
- Support for both TypeScript and Go implementations
|
|
12
12
|
|
|
@@ -114,7 +114,7 @@ import (
|
|
|
114
114
|
"fmt"
|
|
115
115
|
"os"
|
|
116
116
|
|
|
117
|
-
validators "github.com/mitre/hdf-validators/go"
|
|
117
|
+
validators "github.com/mitre/hdf-libs/hdf-validators/go"
|
|
118
118
|
)
|
|
119
119
|
|
|
120
120
|
func main() {
|
|
@@ -174,6 +174,46 @@ Validate data against the HDF Baseline schema.
|
|
|
174
174
|
- `data` - JavaScript object to validate
|
|
175
175
|
- **Returns:** `ValidationResult` with validation status and errors
|
|
176
176
|
|
|
177
|
+
#### `validateComparison(data: unknown): ValidationResult`
|
|
178
|
+
|
|
179
|
+
Validate data against the HDF Comparison schema.
|
|
180
|
+
|
|
181
|
+
- **Parameters:**
|
|
182
|
+
- `data` - JavaScript object to validate
|
|
183
|
+
- **Returns:** `ValidationResult` with validation status and errors
|
|
184
|
+
|
|
185
|
+
#### `validateSystem(data: unknown): ValidationResult`
|
|
186
|
+
|
|
187
|
+
Validate data against the HDF System schema.
|
|
188
|
+
|
|
189
|
+
- **Parameters:**
|
|
190
|
+
- `data` - JavaScript object to validate
|
|
191
|
+
- **Returns:** `ValidationResult` with validation status and errors
|
|
192
|
+
|
|
193
|
+
#### `validatePlan(data: unknown): ValidationResult`
|
|
194
|
+
|
|
195
|
+
Validate data against the HDF Plan schema.
|
|
196
|
+
|
|
197
|
+
- **Parameters:**
|
|
198
|
+
- `data` - JavaScript object to validate
|
|
199
|
+
- **Returns:** `ValidationResult` with validation status and errors
|
|
200
|
+
|
|
201
|
+
#### `validateAmendments(data: unknown): ValidationResult`
|
|
202
|
+
|
|
203
|
+
Validate data against the HDF Amendments schema.
|
|
204
|
+
|
|
205
|
+
- **Parameters:**
|
|
206
|
+
- `data` - JavaScript object to validate
|
|
207
|
+
- **Returns:** `ValidationResult` with validation status and errors
|
|
208
|
+
|
|
209
|
+
#### `validateEvidencePackage(data: unknown): ValidationResult`
|
|
210
|
+
|
|
211
|
+
Validate data against the HDF Evidence Package schema.
|
|
212
|
+
|
|
213
|
+
- **Parameters:**
|
|
214
|
+
- `data` - JavaScript object to validate
|
|
215
|
+
- **Returns:** `ValidationResult` with validation status and errors
|
|
216
|
+
|
|
177
217
|
#### `validate(data: unknown): ValidationResult`
|
|
178
218
|
|
|
179
219
|
Auto-detect document type and validate.
|
|
@@ -288,7 +328,7 @@ The `name` field is required for each baseline.
|
|
|
288
328
|
results[0].status: must be equal to one of the allowed values
|
|
289
329
|
```
|
|
290
330
|
|
|
291
|
-
Result status must be one of: `passed`, `failed`, `error`, `
|
|
331
|
+
Result status must be one of: `passed`, `failed`, `error`, `notApplicable`, `notReviewed`.
|
|
292
332
|
|
|
293
333
|
### Invalid Numeric Ranges
|
|
294
334
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
|
+
//#region typescript/index.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Validation error details
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
interface ValidationError {
|
|
6
|
+
field: string;
|
|
7
|
+
message: string;
|
|
8
|
+
value?: unknown;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Result of schema validation
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
interface ValidationResult {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
errors: ValidationError[];
|
|
16
|
+
getErrorMessage(): string;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Validate HDF Results document against schema
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function validateResults(data: unknown): ValidationResult;
|
|
21
22
|
/**
|
|
22
23
|
* Validate HDF Baseline document against schema
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
declare function validateBaseline(data: unknown): ValidationResult;
|
|
25
26
|
/**
|
|
26
27
|
* Validate HDF Comparison document against schema
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
declare function validateComparison(data: unknown): ValidationResult;
|
|
29
30
|
/**
|
|
30
31
|
* Validate HDF System document against schema
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
declare function validateSystem(data: unknown): ValidationResult;
|
|
33
34
|
/**
|
|
34
35
|
* Validate HDF Plan document against schema
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
+
declare function validatePlan(data: unknown): ValidationResult;
|
|
37
38
|
/**
|
|
38
39
|
* Validate HDF Amendments document against schema
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
declare function validateAmendments(data: unknown): ValidationResult;
|
|
41
42
|
/**
|
|
42
43
|
* Validate HDF Evidence Package document against schema
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
declare function validateEvidencePackage(data: unknown): ValidationResult;
|
|
45
46
|
/**
|
|
46
47
|
* Validate HDF document (auto-detect type based on structure)
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
declare function validate(data: unknown): ValidationResult;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ValidationError, ValidationResult, validate, validateAmendments, validateBaseline, validateComparison, validateEvidencePackage, validatePlan, validateResults, validateSystem };
|
|
49
52
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../typescript/index.ts"],"mappings":";;AAkCA;;UAAiB,eAAA;EACf,KAAA;EACA,OAAA;EACA,KAAA;AAAA;;;AAMF;UAAiB,gBAAA;EACf,KAAA;EACA,MAAA,EAAQ,eAAA;EACR,eAAA;AAAA;;;;iBAuLc,eAAA,CAAgB,IAAA,YAAgB,gBAAA;AAAhD;;;AAAA,iBAQgB,gBAAA,CAAiB,IAAA,YAAgB,gBAAA;;AAAjD;;iBAQgB,kBAAA,CAAmB,IAAA,YAAgB,gBAAA;;;AAAnD;iBAQgB,cAAA,CAAe,IAAA,YAAgB,gBAAA;;;;iBAQ/B,YAAA,CAAa,IAAA,YAAgB,gBAAA;;;;iBAQ7B,kBAAA,CAAmB,IAAA,YAAgB,gBAAA;AARnD;;;AAAA,iBAgBgB,uBAAA,CAAwB,IAAA,YAAgB,gBAAA;;AARxD;;iBAgBgB,QAAA,CAAS,IAAA,YAAgB,gBAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,43 @@
|
|
|
1
|
-
import Ajv from
|
|
2
|
-
import addFormats from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import hdfBaselineSchema from '@mitre/hdf-schema/schemas/hdf-baseline.schema.json';
|
|
6
|
-
import hdfComparisonSchema from '@mitre/hdf-schema/schemas/hdf-comparison.schema.json';
|
|
7
|
-
import hdfSystemSchema from '@mitre/hdf-schema/schemas/hdf-system.schema.json';
|
|
8
|
-
import hdfPlanSchema from '@mitre/hdf-schema/schemas/hdf-plan.schema.json';
|
|
9
|
-
import hdfAmendmentsSchema from '@mitre/hdf-schema/schemas/hdf-amendments.schema.json';
|
|
10
|
-
import hdfEvidencePackageSchema from '@mitre/hdf-schema/schemas/hdf-evidence-package.schema.json';
|
|
11
|
-
import commonSchema from '@mitre/hdf-schema/schemas/primitives/common.schema.json';
|
|
12
|
-
import extensionsSchema from '@mitre/hdf-schema/schemas/primitives/extensions.schema.json';
|
|
13
|
-
import platformSchema from '@mitre/hdf-schema/schemas/primitives/platform.schema.json';
|
|
14
|
-
import resultSchema from '@mitre/hdf-schema/schemas/primitives/result.schema.json';
|
|
15
|
-
import runnerSchema from '@mitre/hdf-schema/schemas/primitives/runner.schema.json';
|
|
16
|
-
import statisticsSchema from '@mitre/hdf-schema/schemas/primitives/statistics.schema.json';
|
|
17
|
-
import targetSchema from '@mitre/hdf-schema/schemas/primitives/target.schema.json';
|
|
18
|
-
import parameterSchema from '@mitre/hdf-schema/schemas/primitives/parameter.schema.json';
|
|
19
|
-
import systemSchema from '@mitre/hdf-schema/schemas/primitives/system.schema.json';
|
|
20
|
-
import planSchema from '@mitre/hdf-schema/schemas/primitives/plan.schema.json';
|
|
21
|
-
import amendmentsSchema from '@mitre/hdf-schema/schemas/primitives/amendments.schema.json';
|
|
22
|
-
import comparisonSchema from '@mitre/hdf-schema/schemas/primitives/comparison.schema.json';
|
|
23
|
-
import componentSchema from '@mitre/hdf-schema/schemas/primitives/component.schema.json';
|
|
24
|
-
import dataFlowSchema from '@mitre/hdf-schema/schemas/primitives/data-flow.schema.json';
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
import { amendmentsSchema, commonSchema, comparisonSchema, componentSchema, dataFlowSchema, extensionsSchema, hdfAmendmentsSchema, hdfBaselineSchema, hdfComparisonSchema, hdfEvidencePackageSchema, hdfPlanSchema, hdfResultsSchema, hdfSystemSchema, parameterSchema, planSchema, platformSchema, resultSchema, runnerSchema, statisticsSchema, systemSchema, targetSchema } from "@mitre/hdf-schema";
|
|
4
|
+
//#region typescript/index.ts
|
|
25
5
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
* Create and configure Ajv instance with all HDF schemas
|
|
7
|
+
*/
|
|
28
8
|
function createValidator() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
9
|
+
const ajv = new Ajv({
|
|
10
|
+
allErrors: true,
|
|
11
|
+
verbose: true,
|
|
12
|
+
strict: false,
|
|
13
|
+
validateFormats: true,
|
|
14
|
+
validateSchema: false
|
|
15
|
+
});
|
|
16
|
+
addFormats(ajv);
|
|
17
|
+
ajv.addSchema(commonSchema);
|
|
18
|
+
ajv.addSchema(platformSchema);
|
|
19
|
+
ajv.addSchema(resultSchema);
|
|
20
|
+
ajv.addSchema(runnerSchema);
|
|
21
|
+
ajv.addSchema(statisticsSchema);
|
|
22
|
+
ajv.addSchema(targetSchema);
|
|
23
|
+
ajv.addSchema(parameterSchema);
|
|
24
|
+
ajv.addSchema(amendmentsSchema);
|
|
25
|
+
ajv.addSchema(extensionsSchema);
|
|
26
|
+
ajv.addSchema(systemSchema);
|
|
27
|
+
ajv.addSchema(planSchema);
|
|
28
|
+
ajv.addSchema(comparisonSchema);
|
|
29
|
+
ajv.addSchema(componentSchema);
|
|
30
|
+
ajv.addSchema(dataFlowSchema);
|
|
31
|
+
ajv.addSchema(hdfResultsSchema);
|
|
32
|
+
ajv.addSchema(hdfBaselineSchema);
|
|
33
|
+
ajv.addSchema(hdfComparisonSchema);
|
|
34
|
+
ajv.addSchema(hdfSystemSchema);
|
|
35
|
+
ajv.addSchema(hdfPlanSchema);
|
|
36
|
+
ajv.addSchema(hdfAmendmentsSchema);
|
|
37
|
+
ajv.addSchema(hdfEvidencePackageSchema);
|
|
38
|
+
return ajv;
|
|
54
39
|
}
|
|
55
|
-
// Singleton Ajv instance
|
|
56
40
|
const ajv = createValidator();
|
|
57
|
-
// Compile schemas once (lazy initialization)
|
|
58
41
|
let resultsValidator = null;
|
|
59
42
|
let baselineValidator = null;
|
|
60
43
|
let comparisonValidator = null;
|
|
@@ -63,204 +46,142 @@ let planValidator = null;
|
|
|
63
46
|
let amendmentsValidator = null;
|
|
64
47
|
let evidencePackageValidator = null;
|
|
65
48
|
function getResultsValidator() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return resultsValidator;
|
|
49
|
+
if (!resultsValidator) resultsValidator = ajv.compile(hdfResultsSchema);
|
|
50
|
+
return resultsValidator;
|
|
70
51
|
}
|
|
71
52
|
function getBaselineValidator() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
return baselineValidator;
|
|
53
|
+
if (!baselineValidator) baselineValidator = ajv.compile(hdfBaselineSchema);
|
|
54
|
+
return baselineValidator;
|
|
76
55
|
}
|
|
77
56
|
function getComparisonValidator() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return comparisonValidator;
|
|
57
|
+
if (!comparisonValidator) comparisonValidator = ajv.compile(hdfComparisonSchema);
|
|
58
|
+
return comparisonValidator;
|
|
82
59
|
}
|
|
83
60
|
function getSystemValidator() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
return systemValidator;
|
|
61
|
+
if (!systemValidator) systemValidator = ajv.compile(hdfSystemSchema);
|
|
62
|
+
return systemValidator;
|
|
88
63
|
}
|
|
89
64
|
function getPlanValidator() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return planValidator;
|
|
65
|
+
if (!planValidator) planValidator = ajv.compile(hdfPlanSchema);
|
|
66
|
+
return planValidator;
|
|
94
67
|
}
|
|
95
68
|
function getAmendmentsValidator() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return amendmentsValidator;
|
|
69
|
+
if (!amendmentsValidator) amendmentsValidator = ajv.compile(hdfAmendmentsSchema);
|
|
70
|
+
return amendmentsValidator;
|
|
100
71
|
}
|
|
101
72
|
function getEvidencePackageValidator() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
return evidencePackageValidator;
|
|
73
|
+
if (!evidencePackageValidator) evidencePackageValidator = ajv.compile(hdfEvidencePackageSchema);
|
|
74
|
+
return evidencePackageValidator;
|
|
106
75
|
}
|
|
107
76
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
77
|
+
* Convert Ajv errors to ValidationError format
|
|
78
|
+
*/
|
|
110
79
|
function formatErrors(errors) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
message = 'is not allowed';
|
|
135
|
-
}
|
|
136
|
-
else if ('limit' in err.params) {
|
|
137
|
-
message = `${message} (limit: ${err.params.limit})`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
field: field || '(root)',
|
|
142
|
-
message,
|
|
143
|
-
value: err.data
|
|
144
|
-
};
|
|
145
|
-
});
|
|
80
|
+
if (!errors || errors.length === 0) return [];
|
|
81
|
+
return errors.map((err) => {
|
|
82
|
+
let field = err.instancePath.replace(/^\//, "").replace(/\//g, ".");
|
|
83
|
+
if (!field && err.schemaPath) {
|
|
84
|
+
const pathParts = err.schemaPath.split("/");
|
|
85
|
+
field = pathParts[pathParts.length - 1] || "(root)";
|
|
86
|
+
}
|
|
87
|
+
let message = err.message || "validation failed";
|
|
88
|
+
if (err.params) {
|
|
89
|
+
if ("missingProperty" in err.params) {
|
|
90
|
+
field = field ? `${field}.${err.params.missingProperty}` : err.params.missingProperty;
|
|
91
|
+
message = "is required";
|
|
92
|
+
} else if ("additionalProperty" in err.params) {
|
|
93
|
+
field = field ? `${field}.${err.params.additionalProperty}` : err.params.additionalProperty;
|
|
94
|
+
message = "is not allowed";
|
|
95
|
+
} else if ("limit" in err.params) message = `${message} (limit: ${err.params.limit})`;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
field: field || "(root)",
|
|
99
|
+
message,
|
|
100
|
+
value: err.data
|
|
101
|
+
};
|
|
102
|
+
});
|
|
146
103
|
}
|
|
147
104
|
/**
|
|
148
|
-
|
|
149
|
-
|
|
105
|
+
* Create ValidationResult from validator output
|
|
106
|
+
*/
|
|
150
107
|
function createResult(validator, data) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
return `${e.field}: ${e.message}`;
|
|
166
|
-
})
|
|
167
|
-
.join('; ');
|
|
168
|
-
}
|
|
169
|
-
};
|
|
108
|
+
const valid = validator(data);
|
|
109
|
+
const errors = formatErrors(validator.errors);
|
|
110
|
+
return {
|
|
111
|
+
valid: valid === true,
|
|
112
|
+
errors,
|
|
113
|
+
getErrorMessage() {
|
|
114
|
+
if (this.valid) return "";
|
|
115
|
+
return this.errors.map((e) => {
|
|
116
|
+
if (e.field === "(root)") return e.message;
|
|
117
|
+
return `${e.field}: ${e.message}`;
|
|
118
|
+
}).join("; ");
|
|
119
|
+
}
|
|
120
|
+
};
|
|
170
121
|
}
|
|
171
122
|
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return createResult(validator, data);
|
|
123
|
+
* Validate HDF Results document against schema
|
|
124
|
+
*/
|
|
125
|
+
function validateResults(data) {
|
|
126
|
+
return createResult(getResultsValidator(), data);
|
|
177
127
|
}
|
|
178
128
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return createResult(validator, data);
|
|
129
|
+
* Validate HDF Baseline document against schema
|
|
130
|
+
*/
|
|
131
|
+
function validateBaseline(data) {
|
|
132
|
+
return createResult(getBaselineValidator(), data);
|
|
184
133
|
}
|
|
185
134
|
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return createResult(validator, data);
|
|
135
|
+
* Validate HDF Comparison document against schema
|
|
136
|
+
*/
|
|
137
|
+
function validateComparison(data) {
|
|
138
|
+
return createResult(getComparisonValidator(), data);
|
|
191
139
|
}
|
|
192
140
|
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return createResult(validator, data);
|
|
141
|
+
* Validate HDF System document against schema
|
|
142
|
+
*/
|
|
143
|
+
function validateSystem(data) {
|
|
144
|
+
return createResult(getSystemValidator(), data);
|
|
198
145
|
}
|
|
199
146
|
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return createResult(validator, data);
|
|
147
|
+
* Validate HDF Plan document against schema
|
|
148
|
+
*/
|
|
149
|
+
function validatePlan(data) {
|
|
150
|
+
return createResult(getPlanValidator(), data);
|
|
205
151
|
}
|
|
206
152
|
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return createResult(validator, data);
|
|
153
|
+
* Validate HDF Amendments document against schema
|
|
154
|
+
*/
|
|
155
|
+
function validateAmendments(data) {
|
|
156
|
+
return createResult(getAmendmentsValidator(), data);
|
|
212
157
|
}
|
|
213
158
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return createResult(validator, data);
|
|
159
|
+
* Validate HDF Evidence Package document against schema
|
|
160
|
+
*/
|
|
161
|
+
function validateEvidencePackage(data) {
|
|
162
|
+
return createResult(getEvidencePackageValidator(), data);
|
|
219
163
|
}
|
|
220
164
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if ('name' in obj && 'overrides' in obj) {
|
|
244
|
-
return validateAmendments(data);
|
|
245
|
-
}
|
|
246
|
-
// HDF Comparison has 'mode' and 'sources' at root
|
|
247
|
-
if ('mode' in obj && 'sources' in obj) {
|
|
248
|
-
return validateComparison(data);
|
|
249
|
-
}
|
|
250
|
-
// HDF Evidence Package has 'name' and 'contents' at root
|
|
251
|
-
if ('name' in obj && 'contents' in obj) {
|
|
252
|
-
return validateEvidencePackage(data);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
// Cannot determine type, try results first (most common)
|
|
256
|
-
const resultsResult = validateResults(data);
|
|
257
|
-
if (resultsResult.valid) {
|
|
258
|
-
return resultsResult;
|
|
259
|
-
}
|
|
260
|
-
const baselineResult = validateBaseline(data);
|
|
261
|
-
if (baselineResult.valid) {
|
|
262
|
-
return baselineResult;
|
|
263
|
-
}
|
|
264
|
-
return resultsResult;
|
|
265
|
-
}
|
|
165
|
+
* Validate HDF document (auto-detect type based on structure)
|
|
166
|
+
*/
|
|
167
|
+
function validate(data) {
|
|
168
|
+
if (typeof data === "object" && data !== null) {
|
|
169
|
+
const obj = data;
|
|
170
|
+
if ("baselines" in obj) return validateResults(data);
|
|
171
|
+
if ("name" in obj && "requirements" in obj) return validateBaseline(data);
|
|
172
|
+
if ("name" in obj && "components" in obj) return validateSystem(data);
|
|
173
|
+
if ("name" in obj && "assessments" in obj) return validatePlan(data);
|
|
174
|
+
if ("name" in obj && "overrides" in obj) return validateAmendments(data);
|
|
175
|
+
if ("mode" in obj && "sources" in obj) return validateComparison(data);
|
|
176
|
+
if ("name" in obj && "contents" in obj) return validateEvidencePackage(data);
|
|
177
|
+
}
|
|
178
|
+
const resultsResult = validateResults(data);
|
|
179
|
+
if (resultsResult.valid) return resultsResult;
|
|
180
|
+
const baselineResult = validateBaseline(data);
|
|
181
|
+
if (baselineResult.valid) return baselineResult;
|
|
182
|
+
return resultsResult;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { validate, validateAmendments, validateBaseline, validateComparison, validateEvidencePackage, validatePlan, validateResults, validateSystem };
|
|
186
|
+
|
|
266
187
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":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CAAC,CAAC;QAC9B,CAAC;QAED,gDAAgD;QAChD,IAAI,MAAM,IAAI,GAAG,IAAI,aAAa,IAAI,GAAG,EAAE,CAAC;YAC1C,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAED,oDAAoD;QACpD,IAAI,MAAM,IAAI,GAAG,IAAI,WAAW,IAAI,GAAG,EAAE,CAAC;YACxC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAED,kDAAkD;QAClD,IAAI,MAAM,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,EAAE,CAAC;YACtC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAED,yDAAyD;QACzD,IAAI,MAAM,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;YACvC,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,MAAM,aAAa,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;QACxB,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,cAAc,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC;QACzB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../typescript/index.ts"],"sourcesContent":["import Ajv, { type ValidateFunction, type ErrorObject } from 'ajv';\nimport addFormats from 'ajv-formats';\n\n// Named JS-object schema imports — the schemas are inlined into\n// @mitre/hdf-schema's dist/index.js at build time, so downstream consumers\n// never see raw JSON imports. Works uniformly in raw Node ESM, Vite/Nuxt,\n// webpack, esbuild — no consumer-side noExternal configuration required.\nimport {\n hdfResultsSchema,\n hdfBaselineSchema,\n hdfComparisonSchema,\n hdfSystemSchema,\n hdfPlanSchema,\n hdfAmendmentsSchema,\n hdfEvidencePackageSchema,\n commonSchema,\n extensionsSchema,\n platformSchema,\n resultSchema,\n runnerSchema,\n statisticsSchema,\n targetSchema,\n parameterSchema,\n systemSchema,\n planSchema,\n amendmentsSchema,\n comparisonSchema,\n componentSchema,\n dataFlowSchema,\n} from '@mitre/hdf-schema';\n\n/**\n * Validation error details\n */\nexport interface ValidationError {\n field: string;\n message: string;\n value?: unknown;\n}\n\n/**\n * Result of schema validation\n */\nexport interface ValidationResult {\n valid: boolean;\n errors: ValidationError[];\n getErrorMessage(): string;\n}\n\n/**\n * Create and configure Ajv instance with all HDF schemas\n */\nfunction createValidator(): Ajv {\n const ajv = new Ajv({\n allErrors: true,\n verbose: true,\n strict: false,\n validateFormats: true,\n validateSchema: false // Skip meta-schema validation for performance\n });\n\n // Add format validators (date-time, uri, etc.)\n addFormats(ajv);\n\n // Add all primitive schemas so they can be referenced via $ref\n ajv.addSchema(commonSchema);\n ajv.addSchema(platformSchema);\n ajv.addSchema(resultSchema);\n ajv.addSchema(runnerSchema);\n ajv.addSchema(statisticsSchema);\n ajv.addSchema(targetSchema);\n ajv.addSchema(parameterSchema);\n ajv.addSchema(amendmentsSchema); // before extensions (extensions $refs amendments Override_Type)\n ajv.addSchema(extensionsSchema);\n ajv.addSchema(systemSchema);\n ajv.addSchema(planSchema);\n ajv.addSchema(comparisonSchema);\n ajv.addSchema(componentSchema);\n ajv.addSchema(dataFlowSchema);\n\n // Register top-level schemas so cross-schema $refs resolve.\n // The comparison primitive references hdf-results#/$defs/Evaluated_Requirement,\n // so hdf-results must be registered before compiling comparison.\n // Schemas are compiled lazily (in getXxxValidator) for performance.\n ajv.addSchema(hdfResultsSchema);\n ajv.addSchema(hdfBaselineSchema);\n ajv.addSchema(hdfComparisonSchema);\n ajv.addSchema(hdfSystemSchema);\n ajv.addSchema(hdfPlanSchema);\n ajv.addSchema(hdfAmendmentsSchema);\n ajv.addSchema(hdfEvidencePackageSchema);\n\n return ajv;\n}\n\n// Singleton Ajv instance\nconst ajv = createValidator();\n\n// Compile schemas once (lazy initialization)\nlet resultsValidator: ValidateFunction | null = null;\nlet baselineValidator: ValidateFunction | null = null;\nlet comparisonValidator: ValidateFunction | null = null;\nlet systemValidator: ValidateFunction | null = null;\nlet planValidator: ValidateFunction | null = null;\nlet amendmentsValidator: ValidateFunction | null = null;\nlet evidencePackageValidator: ValidateFunction | null = null;\n\nfunction getResultsValidator(): ValidateFunction {\n if (!resultsValidator) {\n resultsValidator = ajv.compile(hdfResultsSchema);\n }\n return resultsValidator;\n}\n\nfunction getBaselineValidator(): ValidateFunction {\n if (!baselineValidator) {\n baselineValidator = ajv.compile(hdfBaselineSchema);\n }\n return baselineValidator;\n}\n\nfunction getComparisonValidator(): ValidateFunction {\n if (!comparisonValidator) {\n comparisonValidator = ajv.compile(hdfComparisonSchema);\n }\n return comparisonValidator;\n}\n\nfunction getSystemValidator(): ValidateFunction {\n if (!systemValidator) {\n systemValidator = ajv.compile(hdfSystemSchema);\n }\n return systemValidator;\n}\n\nfunction getPlanValidator(): ValidateFunction {\n if (!planValidator) {\n planValidator = ajv.compile(hdfPlanSchema);\n }\n return planValidator;\n}\n\nfunction getAmendmentsValidator(): ValidateFunction {\n if (!amendmentsValidator) {\n amendmentsValidator = ajv.compile(hdfAmendmentsSchema);\n }\n return amendmentsValidator;\n}\n\nfunction getEvidencePackageValidator(): ValidateFunction {\n if (!evidencePackageValidator) {\n evidencePackageValidator = ajv.compile(hdfEvidencePackageSchema);\n }\n return evidencePackageValidator;\n}\n\n/**\n * Convert Ajv errors to ValidationError format\n */\nfunction formatErrors(errors: ErrorObject[] | null | undefined): ValidationError[] {\n if (!errors || errors.length === 0) {\n return [];\n }\n\n return errors.map(err => {\n // Clean up field path (remove leading slash, use dot notation)\n let field = err.instancePath\n .replace(/^\\//, '')\n .replace(/\\//g, '.');\n\n // If field is empty, use the data path from the error\n if (!field && err.schemaPath) {\n const pathParts = err.schemaPath.split('/');\n field = pathParts[pathParts.length - 1] || '(root)';\n }\n\n // Build message\n let message = err.message || 'validation failed';\n if (err.params) {\n // Add parameter info for more context\n if ('missingProperty' in err.params) {\n field = field ? `${field}.${err.params.missingProperty}` : err.params.missingProperty;\n message = 'is required';\n } else if ('additionalProperty' in err.params) {\n field = field ? `${field}.${err.params.additionalProperty}` : err.params.additionalProperty;\n message = 'is not allowed';\n } else if ('limit' in err.params) {\n message = `${message} (limit: ${err.params.limit})`;\n }\n }\n\n return {\n field: field || '(root)',\n message,\n value: err.data\n };\n });\n}\n\n/**\n * Create ValidationResult from validator output\n */\nfunction createResult(validator: ValidateFunction, data: unknown): ValidationResult {\n const valid = validator(data);\n\n const errors = formatErrors(validator.errors);\n\n return {\n valid: valid === true,\n errors,\n getErrorMessage(): string {\n if (this.valid) {\n return '';\n }\n return this.errors\n .map(e => {\n if (e.field === '(root)') {\n return e.message;\n }\n return `${e.field}: ${e.message}`;\n })\n .join('; ');\n }\n };\n}\n\n/**\n * Validate HDF Results document against schema\n */\nexport function validateResults(data: unknown): ValidationResult {\n const validator = getResultsValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF Baseline document against schema\n */\nexport function validateBaseline(data: unknown): ValidationResult {\n const validator = getBaselineValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF Comparison document against schema\n */\nexport function validateComparison(data: unknown): ValidationResult {\n const validator = getComparisonValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF System document against schema\n */\nexport function validateSystem(data: unknown): ValidationResult {\n const validator = getSystemValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF Plan document against schema\n */\nexport function validatePlan(data: unknown): ValidationResult {\n const validator = getPlanValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF Amendments document against schema\n */\nexport function validateAmendments(data: unknown): ValidationResult {\n const validator = getAmendmentsValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF Evidence Package document against schema\n */\nexport function validateEvidencePackage(data: unknown): ValidationResult {\n const validator = getEvidencePackageValidator();\n return createResult(validator, data);\n}\n\n/**\n * Validate HDF document (auto-detect type based on structure)\n */\nexport function validate(data: unknown): ValidationResult {\n if (typeof data === 'object' && data !== null) {\n const obj = data as Record<string, unknown>;\n\n // HDF Results has 'baselines' array at root\n if ('baselines' in obj) {\n return validateResults(data);\n }\n\n // HDF Baseline has 'name' and 'requirements' at root\n if ('name' in obj && 'requirements' in obj) {\n return validateBaseline(data);\n }\n\n // HDF System has 'name' and 'components' at root\n if ('name' in obj && 'components' in obj) {\n return validateSystem(data);\n }\n\n // HDF Plan has 'name' and 'assessments' at root\n if ('name' in obj && 'assessments' in obj) {\n return validatePlan(data);\n }\n\n // HDF Amendments has 'name' and 'overrides' at root\n if ('name' in obj && 'overrides' in obj) {\n return validateAmendments(data);\n }\n\n // HDF Comparison has 'mode' and 'sources' at root\n if ('mode' in obj && 'sources' in obj) {\n return validateComparison(data);\n }\n\n // HDF Evidence Package has 'name' and 'contents' at root\n if ('name' in obj && 'contents' in obj) {\n return validateEvidencePackage(data);\n }\n }\n\n // Cannot determine type, try results first (most common)\n const resultsResult = validateResults(data);\n if (resultsResult.valid) {\n return resultsResult;\n }\n\n const baselineResult = validateBaseline(data);\n if (baselineResult.valid) {\n return baselineResult;\n }\n\n return resultsResult;\n}\n"],"mappings":";;;;;;;AAoDA,SAAS,kBAAuB;CAC9B,MAAM,MAAM,IAAI,IAAI;EAClB,WAAW;EACX,SAAS;EACT,QAAQ;EACR,iBAAiB;EACjB,gBAAgB;EACjB,CAAC;AAGF,YAAW,IAAI;AAGf,KAAI,UAAU,aAAa;AAC3B,KAAI,UAAU,eAAe;AAC7B,KAAI,UAAU,aAAa;AAC3B,KAAI,UAAU,aAAa;AAC3B,KAAI,UAAU,iBAAiB;AAC/B,KAAI,UAAU,aAAa;AAC3B,KAAI,UAAU,gBAAgB;AAC9B,KAAI,UAAU,iBAAiB;AAC/B,KAAI,UAAU,iBAAiB;AAC/B,KAAI,UAAU,aAA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AE5D,QAAO,aADW,kBAAkB,EACL,KAAK;;;;;AAMtC,SAAgB,mBAAmB,MAAiC;AAElE,QAAO,aADW,wBAAwB,EACX,KAAK;;;;;AAMtC,SAAgB,wBAAwB,MAAiC;AAEvE,QAAO,aADW,6BAA6B,EAChB,KAAK;;;;;AAMtC,SAAgB,SAAS,MAAiC;AACxD,KAAI,OAAO,SAAS,YAAY,SAAS,MAAM;EAC7C,MAAM,MAAM;AAGZ,MAAI,eAAe,IACjB,QAAO,gBAAgB,KAAK;AAI9B,MAAI,UAAU,OAAO,kBAAkB,IACrC,QAAO,iBAAiB,KAAK;AAI/B,MAAI,UAAU,OAAO,gBAAgB,IACnC,QAAO,eAAe,KAAK;AAI7B,MAAI,UAAU,OAAO,iBAAiB,IACpC,QAAO,aAAa,KAAK;AAI3B,MAAI,UAAU,OAAO,eAAe,IAClC,QAAO,mBAAmB,KAAK;AAIjC,MAAI,UAAU,OAAO,aAAa,IAChC,QAAO,mBAAmB,KAAK;AAIjC,MAAI,UAAU,OAAO,cAAc,IACjC,QAAO,wBAAwB,KAAK;;CAKxC,MAAM,gBAAgB,gBAAgB,KAAK;AAC3C,KAAI,cAAc,MAChB,QAAO;CAGT,MAAM,iBAAiB,iBAAiB,KAAK;AAC7C,KAAI,eAAe,MACjB,QAAO;AAGT,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/hdf-validators",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-rc.1",
|
|
4
4
|
"description": "JSON Schema validation for HDF documents (Results and Baselines)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,26 +10,13 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"import": "./dist/index.js"
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
17
|
"files": [
|
|
19
18
|
"dist"
|
|
20
19
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "pnpm clean && tsc",
|
|
23
|
-
"clean": "rimraf dist",
|
|
24
|
-
"test": "pnpm run test:ts && pnpm run test:go",
|
|
25
|
-
"test:ts": "vitest run",
|
|
26
|
-
"test:go": "cd go && go test ./...",
|
|
27
|
-
"test:watch": "vitest",
|
|
28
|
-
"test:coverage": "vitest run --coverage",
|
|
29
|
-
"type-check": "tsc --noEmit",
|
|
30
|
-
"lint": "eslint typescript",
|
|
31
|
-
"lint:fix": "eslint typescript --fix"
|
|
32
|
-
},
|
|
33
20
|
"repository": {
|
|
34
21
|
"type": "git",
|
|
35
22
|
"url": "https://github.com/mitre/hdf-libs.git",
|
|
@@ -38,12 +25,12 @@
|
|
|
38
25
|
"author": "MITRE Corporation",
|
|
39
26
|
"license": "Apache-2.0",
|
|
40
27
|
"dependencies": {
|
|
41
|
-
"@mitre/hdf-schema": "workspace:*",
|
|
42
28
|
"ajv": "^8.17.1",
|
|
43
|
-
"ajv-formats": "^3.0.1"
|
|
29
|
+
"ajv-formats": "^3.0.1",
|
|
30
|
+
"@mitre/hdf-schema": "^3.1.0-rc.1"
|
|
44
31
|
},
|
|
45
32
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
33
|
+
"node": ">=22.0.0"
|
|
47
34
|
},
|
|
48
35
|
"keywords": [
|
|
49
36
|
"hdf",
|
|
@@ -54,5 +41,17 @@
|
|
|
54
41
|
"devDependencies": {
|
|
55
42
|
"@stryker-mutator/core": "^9.5.1",
|
|
56
43
|
"@stryker-mutator/vitest-runner": "^9.5.1"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"clean": "rimraf dist",
|
|
48
|
+
"test": "pnpm run test:ts && pnpm run test:go",
|
|
49
|
+
"test:ts": "vitest run",
|
|
50
|
+
"test:go": "cd go && go test ./...",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"test:coverage": "vitest run --coverage",
|
|
53
|
+
"type-check": "tsc --noEmit",
|
|
54
|
+
"lint": "eslint typescript",
|
|
55
|
+
"lint:fix": "eslint typescript --fix"
|
|
57
56
|
}
|
|
58
|
-
}
|
|
57
|
+
}
|