@pdtf/schemas 0.5.14 → 0.6.2
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 +17 -8
- package/package.json +1 -1
- package/src/examples/exampleDocumentedVouch.json +1 -1
- package/src/examples/exampleElectronicRecord.json +5 -1
- package/src/examples/exampleTransaction.json +674 -0
- package/src/examples/exampleVouch.json +1 -1
- package/src/schemas/baspi-a-material-facts.json +6 -0
- package/src/schemas/pdtf-transaction.json +275 -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} +57 -26
- package/src/examples/examplePropertyPack.json +0 -377
- 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");
|
|
@@ -21,7 +21,7 @@ const subSchemas = {
|
|
|
21
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,
|
|
@@ -31,18 +31,26 @@ const ajv = new Ajv({
|
|
|
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
|
|
|
47
|
+
const isPathValid = (path) => {
|
|
48
|
+
try {
|
|
49
|
+
return getSubschema(path) !== undefined;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
46
54
|
const getSubschemaValidator = (path) => {
|
|
47
55
|
const subSchema = getSubschema(path);
|
|
48
56
|
let validator = ajv.getSchema(path);
|
|
@@ -99,9 +107,10 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
|
99
107
|
};
|
|
100
108
|
|
|
101
109
|
module.exports = {
|
|
102
|
-
|
|
110
|
+
transactionSchema,
|
|
103
111
|
validator,
|
|
104
112
|
getSubschema,
|
|
113
|
+
isPathValid,
|
|
105
114
|
getSubschemaValidator,
|
|
106
115
|
getTitleAtPath,
|
|
107
116
|
verifiedClaimsSchema,
|
package/package.json
CHANGED
|
@@ -5,9 +5,13 @@
|
|
|
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
16
|
"type": "postcode_address_file"
|
|
13
17
|
}
|