@pdtf/schemas 0.5.13 → 0.6.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/index.js +20 -12
- package/package.json +1 -1
- package/src/examples/exampleDocumentedVouch.json +1 -1
- package/src/examples/exampleElectronicRecord.json +7 -3
- package/src/examples/exampleTransaction.json +670 -0
- package/src/examples/exampleVouch.json +1 -1
- package/src/schemas/baspi-a-material-facts.json +6 -0
- package/src/schemas/energy-performance-certificate.json +3 -0
- package/src/schemas/pdtf-transaction.json +167 -0
- package/src/schemas/pdtf-verified-claims.json +8 -7
- package/src/schemas/title-deed.json +168 -105
- package/src/tests/pdtfVerifiedClaims.test.js +2 -5
- package/src/tests/{propertyPackSchema.test.js → transactionSchema.test.js} +53 -27
- package/src/examples/examplePropertyPack.json +0 -376
- package/src/schemas/property-pack.json +0 -193
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const { dereference } = require("@jdw/jst");
|
|
|
2
2
|
const Ajv = require("ajv");
|
|
3
3
|
const addFormats = require("ajv-formats");
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const pdtfTransaction = require("./src/schemas/pdtf-transaction.json");
|
|
6
6
|
const baspiMaterialFacts = require("./src/schemas/baspi-a-material-facts.json");
|
|
7
7
|
const baspiLegalInformation = require("./src/schemas/baspi-b-legal-information.json");
|
|
8
8
|
const energyPerformanceCertificate = require("./src/schemas/energy-performance-certificate.json");
|
|
@@ -18,33 +18,41 @@ const subSchemas = {
|
|
|
18
18
|
"https://homebuyingandsellinggroup.co.uk/schemas/energy-performance-certificate.json":
|
|
19
19
|
energyPerformanceCertificate,
|
|
20
20
|
"https://geojson.org/schema/GeoJSON.json": geoJson,
|
|
21
|
-
"https://homebuyingandsellinggroup.co.uk/schemas/title-deed.json": titleDeed
|
|
21
|
+
"https://homebuyingandsellinggroup.co.uk/schemas/title-deed.json": titleDeed,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const transactionSchema = dereference(pdtfTransaction, (id) => subSchemas[id]);
|
|
25
25
|
|
|
26
26
|
const ajv = new Ajv({
|
|
27
27
|
allErrors: true,
|
|
28
28
|
// schema contains additional baspiRef and RDSRef metadata which is not strictly valid
|
|
29
|
-
strictSchema: false
|
|
29
|
+
strictSchema: false,
|
|
30
30
|
});
|
|
31
31
|
// Adds date formats among other types to the validator.
|
|
32
32
|
addFormats(ajv);
|
|
33
33
|
|
|
34
|
-
const validator = ajv.compile(
|
|
34
|
+
const validator = ajv.compile(transactionSchema);
|
|
35
35
|
|
|
36
36
|
const getSubschema = (path) => {
|
|
37
37
|
const pathArray = path.split("/").slice(1);
|
|
38
38
|
if (pathArray.length < 1) {
|
|
39
|
-
return
|
|
39
|
+
return transactionSchema;
|
|
40
40
|
}
|
|
41
|
-
return pathArray.reduce((
|
|
42
|
-
return
|
|
43
|
-
|
|
41
|
+
return pathArray.reduce((schema, pathElement) => {
|
|
42
|
+
if (schema.type === "array") return schema.items;
|
|
43
|
+
return schema.properties[pathElement];
|
|
44
|
+
}, transactionSchema);
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
const getSubschemaValidator = (path) => {
|
|
47
|
-
|
|
48
|
+
const subSchema = getSubschema(path);
|
|
49
|
+
let validator = ajv.getSchema(path);
|
|
50
|
+
if (!validator && subSchema.$id) validator = ajv.getSchema(subSchema.$id);
|
|
51
|
+
if (!validator) {
|
|
52
|
+
ajv.addSchema(subSchema, path);
|
|
53
|
+
validator = ajv.getSchema(path);
|
|
54
|
+
}
|
|
55
|
+
return validator;
|
|
48
56
|
};
|
|
49
57
|
|
|
50
58
|
const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
@@ -92,10 +100,10 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
|
92
100
|
};
|
|
93
101
|
|
|
94
102
|
module.exports = {
|
|
95
|
-
|
|
103
|
+
transactionSchema,
|
|
96
104
|
validator,
|
|
97
105
|
getSubschema,
|
|
98
106
|
getSubschemaValidator,
|
|
99
107
|
getTitleAtPath,
|
|
100
|
-
verifiedClaimsSchema
|
|
108
|
+
verifiedClaimsSchema,
|
|
101
109
|
};
|
package/package.json
CHANGED
|
@@ -5,17 +5,21 @@
|
|
|
5
5
|
"evidence": [
|
|
6
6
|
{
|
|
7
7
|
"type": "electronic_record",
|
|
8
|
+
"verifier": {
|
|
9
|
+
"organization": "Property Pack Assembly Software Ltd"
|
|
10
|
+
},
|
|
8
11
|
"record": {
|
|
9
12
|
"source": {
|
|
10
|
-
"name": "Royal Mail Postcode Address File
|
|
13
|
+
"name": "Royal Mail Postcode Address File",
|
|
14
|
+
"rights": "(c) Royal Mail"
|
|
11
15
|
},
|
|
12
|
-
"type": "
|
|
16
|
+
"type": "postcode_address_file"
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
]
|
|
16
20
|
},
|
|
17
21
|
"claims": {
|
|
18
|
-
"/propertyPack/materialFacts/
|
|
22
|
+
"/propertyPack/materialFacts/address": {
|
|
19
23
|
"address1": "3 The Hollys",
|
|
20
24
|
"address2": "Birtley",
|
|
21
25
|
"town": "CHESTER LE STREET",
|