@dvsa/cvs-type-definitions 2.0.11 → 2.0.12
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/package.json +4 -2
- package/schemas.ts +49 -0
- package/src/schema-validation/schema-validator.ts +25 -0
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvsa/cvs-type-definitions",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "type definitions for cvs vta application",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/**/*",
|
|
8
8
|
"json-schemas/**/*",
|
|
9
|
-
"types/**/*"
|
|
9
|
+
"types/**/*",
|
|
10
|
+
"src/**/*",
|
|
11
|
+
"schemas.ts"
|
|
10
12
|
],
|
|
11
13
|
"repository": {
|
|
12
14
|
"url": "git://github.com/dvsa/cvs-type-definitions.git"
|
package/schemas.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const schemas = [
|
|
2
|
+
"v1/activity/index.json",
|
|
3
|
+
"v1/defect-category-reference-data/index.json",
|
|
4
|
+
"v1/defect-details/index.json",
|
|
5
|
+
"v1/defect-location/index.json",
|
|
6
|
+
"v1/reason-item/index.json",
|
|
7
|
+
"v1/tech-record/index.json",
|
|
8
|
+
"v1/test/index.json",
|
|
9
|
+
"v1/test-result/index.json",
|
|
10
|
+
"v1/test-station/index.json",
|
|
11
|
+
"v1/test-type/index.json",
|
|
12
|
+
"v1/vehicle/index.json",
|
|
13
|
+
"v1/vehicle-tech-record/index.json",
|
|
14
|
+
"v1/visit/index.json",
|
|
15
|
+
"v3/tech-record/get/car/complete/index.json",
|
|
16
|
+
"v3/tech-record/get/car/skeleton/index.json",
|
|
17
|
+
"v3/tech-record/get/hgv/complete/index.json",
|
|
18
|
+
"v3/tech-record/get/hgv/skeleton/index.json",
|
|
19
|
+
"v3/tech-record/get/hgv/testable/index.json",
|
|
20
|
+
"v3/tech-record/get/lgv/complete/index.json",
|
|
21
|
+
"v3/tech-record/get/lgv/skeleton/index.json",
|
|
22
|
+
"v3/tech-record/get/motorcycle/complete/index.json",
|
|
23
|
+
"v3/tech-record/get/motorcycle/skeleton/index.json",
|
|
24
|
+
"v3/tech-record/get/psv/complete/index.json",
|
|
25
|
+
"v3/tech-record/get/psv/skeleton/index.json",
|
|
26
|
+
"v3/tech-record/get/psv/testable/index.json",
|
|
27
|
+
"v3/tech-record/get/search/complete/index.json",
|
|
28
|
+
"v3/tech-record/get/search/skeleton/index.json",
|
|
29
|
+
"v3/tech-record/get/trl/complete/index.json",
|
|
30
|
+
"v3/tech-record/get/trl/skeleton/index.json",
|
|
31
|
+
"v3/tech-record/get/trl/testable/index.json",
|
|
32
|
+
"v3/tech-record/post/psv/complete/index.json",
|
|
33
|
+
"v3/tech-record/post/psv/skeleton/index.json",
|
|
34
|
+
"v3/tech-record/post/psv/testable/index.json",
|
|
35
|
+
"v3/tech-record/put/car/complete/request/index.json",
|
|
36
|
+
"v3/tech-record/put/car/complete/response/index.json",
|
|
37
|
+
"v3/tech-record/put/car/skeleton/request/index.json",
|
|
38
|
+
"v3/tech-record/put/car/skeleton/response/index.json",
|
|
39
|
+
"v3/tech-record/put/hgv/complete/index.json",
|
|
40
|
+
"v3/tech-record/put/hgv/skeleton/index.json",
|
|
41
|
+
"v3/tech-record/put/hgv/testable/index.json",
|
|
42
|
+
"v3/tech-record/put/lgv/complete/request/index.json",
|
|
43
|
+
"v3/tech-record/put/lgv/complete/response/index.json",
|
|
44
|
+
"v3/tech-record/put/lgv/skeleton/request/index.json",
|
|
45
|
+
"v3/tech-record/put/lgv/skeleton/response/index.json",
|
|
46
|
+
"v3/tech-record/put/trl/complete/index.json",
|
|
47
|
+
"v3/tech-record/put/trl/skeleton/index.json",
|
|
48
|
+
"v3/tech-record/put/trl/testable/index.json",
|
|
49
|
+
] as const;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import { schemas } from "../../schemas";
|
|
3
|
+
|
|
4
|
+
export type Schema = typeof schemas[number];
|
|
5
|
+
|
|
6
|
+
export const isValidObject = (
|
|
7
|
+
schemaName: Schema,
|
|
8
|
+
objectToValidate: object,
|
|
9
|
+
logErrors = false
|
|
10
|
+
): boolean => {
|
|
11
|
+
const ajv = new Ajv({ removeAdditional: true, allErrors: true });
|
|
12
|
+
const schemaPath = `json-schemas/${schemaName}`;
|
|
13
|
+
const schema = require(schemaPath);
|
|
14
|
+
|
|
15
|
+
const validateFunction = ajv.compile(schema);
|
|
16
|
+
const isValid = validateFunction(objectToValidate);
|
|
17
|
+
|
|
18
|
+
if(logErrors && validateFunction.errors){
|
|
19
|
+
console.error(validateFunction.errors)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return isValid
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
};
|