@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 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 propertyPack = require("./src/schemas/property-pack.json");
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 propertyPackSchema = dereference(propertyPack, (id) => subSchemas[id]);
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(propertyPackSchema);
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 schema;
39
+ return transactionSchema;
40
40
  }
41
- return pathArray.reduce((propertyPackSchema, pathElement) => {
42
- return propertyPackSchema.properties[pathElement];
43
- }, propertyPackSchema);
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
- return ajv.getSchema(path) || ajv.compile(getSubschema(path));
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
- propertyPackSchema,
103
+ transactionSchema,
96
104
  validator,
97
105
  getSubschema,
98
106
  getSubschemaValidator,
99
107
  getTitleAtPath,
100
- verifiedClaimsSchema
108
+ verifiedClaimsSchema,
101
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.5.13",
3
+ "version": "0.6.0",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -31,7 +31,7 @@
31
31
  ]
32
32
  },
33
33
  "claims": {
34
- "/propertyPack/materialFacts/propertyToBeSold/councilTax": {
34
+ "/propertyPack/materialFacts/councilTax": {
35
35
  "councilTaxBand": "D",
36
36
  "councilTaxAffectingAlterations": {
37
37
  "yesNo": "Yes",
@@ -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 record via ideal-postcodes.co.uk"
13
+ "name": "Royal Mail Postcode Address File",
14
+ "rights": "(c) Royal Mail"
11
15
  },
12
- "type": "paf"
16
+ "type": "postcode_address_file"
13
17
  }
14
18
  }
15
19
  ]
16
20
  },
17
21
  "claims": {
18
- "/propertyPack/materialFacts/propertyToBeSold/address": {
22
+ "/propertyPack/materialFacts/address": {
19
23
  "address1": "3 The Hollys",
20
24
  "address2": "Birtley",
21
25
  "town": "CHESTER LE STREET",