@pdtf/schemas 2.3.0 → 3.0.0-10

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.
Files changed (41) hide show
  1. package/index.js +52 -94
  2. package/package.json +1 -1
  3. package/src/examples/v2/exampleTransaction.json +6 -20
  4. package/src/examples/v3/exampleTransaction.json +904 -0
  5. package/src/mappings/SendPropertyDetailsRequestSchema.json +1588 -0
  6. package/src/mappings/adf.js +1 -1
  7. package/src/schemas/v2/combined.json +13206 -12615
  8. package/src/schemas/v2/overlays/baspi.json +510 -2331
  9. package/src/schemas/v2/overlays/con29DW.json +682 -762
  10. package/src/schemas/v2/overlays/con29R.json +2914 -3073
  11. package/src/schemas/v2/overlays/fme1.json +48 -233
  12. package/src/schemas/v2/overlays/llc1.json +12 -33
  13. package/src/schemas/v2/overlays/lpe1.json +75 -367
  14. package/src/schemas/v2/overlays/nts.json +17 -103
  15. package/src/schemas/v2/overlays/piq.json +146 -693
  16. package/src/schemas/v2/overlays/rds.json +66 -300
  17. package/src/schemas/v2/overlays/ta10.json +540 -1755
  18. package/src/schemas/v2/overlays/ta6.json +241 -1193
  19. package/src/schemas/v2/overlays/ta7.json +106 -440
  20. package/src/schemas/v2/pdtf-transaction.json +13656 -12911
  21. package/src/schemas/v2/skeleton.json +1342 -1155
  22. package/src/schemas/v3/combined.json +38477 -0
  23. package/src/schemas/v3/overlays/baspi.json +8022 -0
  24. package/src/schemas/v3/overlays/con29DW.json +705 -0
  25. package/src/schemas/v3/overlays/con29R.json +2956 -0
  26. package/src/schemas/v3/overlays/fme1.json +1264 -0
  27. package/src/schemas/v3/overlays/llc1.json +25 -0
  28. package/src/schemas/v3/overlays/lpe1.json +2181 -0
  29. package/src/schemas/v3/overlays/nts.json +1937 -0
  30. package/src/schemas/v3/overlays/oc1.json +2799 -0
  31. package/src/schemas/v3/overlays/piq.json +3391 -0
  32. package/src/schemas/v3/overlays/rds.json +3818 -0
  33. package/src/schemas/v3/overlays/ta10.json +5306 -0
  34. package/src/schemas/v3/overlays/ta6.json +4410 -0
  35. package/src/schemas/v3/overlays/ta7.json +1157 -0
  36. package/src/schemas/v3/pdtf-transaction.json +34858 -0
  37. package/src/schemas/v3/skeleton.json +4018 -0
  38. package/src/tests/{v2 → v3}/transactionSchema.test.js +46 -36
  39. package/src/tests/{v2 → v3}/verifiedClaimsValidator.test.js +11 -11
  40. package/src/utils/extractOverlay.js +12 -34
  41. package/src/utils/hmlrLLC1.json +0 -275
package/index.js CHANGED
@@ -11,79 +11,50 @@ const ajv = new Ajv({
11
11
  // Adds date formats among other types to the validator.
12
12
  addFormats(ajv);
13
13
 
14
- // v1, deprecated direct access
15
- const pdtfTransaction = require("./src/schemas/v1/pdtf-transaction.json");
16
- const materialFacts = require("./src/schemas/v1/material-facts.json");
17
- const legalInformation = require("./src/schemas/v1/legal-information.json");
18
- const energyPerformanceCertificate = require("./src/schemas/v1/energy-performance-certificate.json");
19
- const titleDeed = require("./src/schemas/v1/title-deed.json");
20
- const searches = require("./src/schemas/v1/searches.json");
21
- const localLandCharges = require("./src/schemas/v1/searches/local-land-charges.json");
22
- const localSearchesRequired = require("./src/schemas/v1/searches/local-searches-required.json");
23
- const drainageAndWater = require("./src/schemas/v1/searches/drainage-and-water.json");
24
- const geoJson = require("./src/schemas/v1/GeoJSON.json");
25
14
  const verifiedClaimsSchema = require("./src/schemas/v1/pdtf-verified-claims.json");
26
-
27
- const subSchemas = {
28
- "https://trust.propdata.org.uk/schemas/v1/material-facts.json": materialFacts,
29
- "https://trust.propdata.org.uk/schemas/v1/legal-information.json":
30
- legalInformation,
31
- "https://trust.propdata.org.uk/schemas/v1/energy-performance-certificate.json":
32
- energyPerformanceCertificate,
33
- "https://geojson.org/schema/GeoJSON.json": geoJson,
34
- "https://trust.propdata.org.uk/schemas/v1/title-deed.json": titleDeed,
35
- "https://trust.propdata.org.uk/schemas/v1/searches.json": searches,
36
- "https://trust.propdata.org.uk/schemas/v1/searches/local-land-charges.json":
37
- localLandCharges,
38
- "https://trust.propdata.org.uk/schemas/v1/searches/local-searches-required.json":
39
- localSearchesRequired,
40
- "https://trust.propdata.org.uk/schemas/v1/searches/drainage-and-water.json":
41
- drainageAndWater,
42
- };
43
- const transactionSchema = dereference(pdtfTransaction, (id) => subSchemas[id]);
44
- const validator = ajv.compile(transactionSchema);
45
-
46
- // v2, via accessor functions and overlays
47
- const combinedSchema = require("./src/schemas/v2/combined.json");
48
15
  const v2CoreSchema = require("./src/schemas/v2/pdtf-transaction.json");
49
-
50
- const baspiOverlay = require("./src/schemas/v2/overlays/baspi.json");
51
- const ta6Overlay = require("./src/schemas/v2/overlays/ta6.json");
52
- const ta7Overlay = require("./src/schemas/v2/overlays/ta7.json");
53
- const ta10Overlay = require("./src/schemas/v2/overlays/ta10.json");
54
- const lpe1Overlay = require("./src/schemas/v2/overlays/lpe1.json");
55
- const fme1Overlay = require("./src/schemas/v2/overlays/fme1.json");
56
- const llc1Overlay = require("./src/schemas/v2/overlays/llc1.json");
57
- const ntsOverlay = require("./src/schemas/v2/overlays/nts.json");
58
- const con29ROverlay = require("./src/schemas/v2/overlays/con29R.json");
59
- const con29DWOverlay = require("./src/schemas/v2/overlays/con29DW.json");
60
- const rdsOverlay = require("./src/schemas/v2/overlays/rds.json");
61
- const oc1Overlay = require("./src/schemas/v2/overlays/oc1.json");
62
- const piqOverlay = require("./src/schemas/v2/overlays/piq.json");
16
+ const v3CoreSchema = require("./src/schemas/v3/pdtf-transaction.json");
63
17
 
64
18
  const overlaysMap = {
65
- // either the version or the edition is added to the key for future proofing
66
- baspiV4: baspiOverlay,
67
- ta6ed4: ta6Overlay,
68
- ta7ed3: ta7Overlay,
69
- ta10ed3: ta10Overlay,
70
- lpe1ed4: lpe1Overlay,
71
- fme1ed2: fme1Overlay,
72
- llc1v2: llc1Overlay,
73
- nts2023: ntsOverlay,
74
- con29R2019: con29ROverlay,
75
- con29DW: con29DWOverlay,
76
- rdsV333: rdsOverlay,
77
- oc1v21: oc1Overlay,
78
- piqV3: piqOverlay,
79
- null: {},
19
+ "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json": {
20
+ baspiV4: require("./src/schemas/v2/overlays/baspi.json"),
21
+ ta6ed4: require("./src/schemas/v2/overlays/ta6.json"),
22
+ ta7ed3: require("./src/schemas/v2/overlays/ta7.json"),
23
+ ta10ed3: require("./src/schemas/v2/overlays/ta10.json"),
24
+ lpe1ed4: require("./src/schemas/v2/overlays/lpe1.json"),
25
+ fme1ed2: require("./src/schemas/v2/overlays/fme1.json"),
26
+ llc1v2: require("./src/schemas/v2/overlays/llc1.json"),
27
+ nts2023: require("./src/schemas/v2/overlays/nts.json"),
28
+ con29R2019: require("./src/schemas/v2/overlays/con29R.json"),
29
+ con29DW: require("./src/schemas/v2/overlays/con29DW.json"),
30
+ rdsV333: require("./src/schemas/v2/overlays/rds.json"),
31
+ oc1v21: require("./src/schemas/v2/overlays/oc1.json"),
32
+ piqV3: require("./src/schemas/v2/overlays/piq.json"),
33
+ null: {},
34
+ },
35
+ "https://trust.propdata.org.uk/schemas/v3/pdtf-transaction.json": {
36
+ baspiV4: require("./src/schemas/v3/overlays/baspi.json"),
37
+ ta6ed4: require("./src/schemas/v3/overlays/ta6.json"),
38
+ ta7ed3: require("./src/schemas/v3/overlays/ta7.json"),
39
+ ta10ed3: require("./src/schemas/v3/overlays/ta10.json"),
40
+ lpe1ed4: require("./src/schemas/v3/overlays/lpe1.json"),
41
+ fme1ed2: require("./src/schemas/v3/overlays/fme1.json"),
42
+ llc1v2: require("./src/schemas/v3/overlays/llc1.json"),
43
+ nts2023: require("./src/schemas/v3/overlays/nts.json"),
44
+ con29R2019: require("./src/schemas/v3/overlays/con29R.json"),
45
+ con29DW: require("./src/schemas/v3/overlays/con29DW.json"),
46
+ rdsV333: require("./src/schemas/v3/overlays/rds.json"),
47
+ oc1v21: require("./src/schemas/v3/overlays/oc1.json"),
48
+ piqV3: require("./src/schemas/v3/overlays/piq.json"),
49
+ null: {},
50
+ },
80
51
  };
81
52
 
82
53
  const transactionSchemas = {
83
- "https://trust.propdata.org.uk/schemas/v1/pdtf-transaction.json":
84
- transactionSchema,
85
54
  "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json":
86
55
  v2CoreSchema,
56
+ "https://trust.propdata.org.uk/schemas/v3/pdtf-transaction.json":
57
+ v3CoreSchema,
87
58
  };
88
59
 
89
60
  const combineMerge = (target, source, options) => {
@@ -100,31 +71,31 @@ const combineMerge = (target, source, options) => {
100
71
  return destination;
101
72
  };
102
73
 
74
+ const mergeEnums = (target, source) => source;
75
+
103
76
  const getTransactionSchema = (
104
- schemaId = "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json",
105
- overlays = ["baspiV4"]
77
+ schemaId = "https://trust.propdata.org.uk/schemas/v3/pdtf-transaction.json",
78
+ overlays // = ["baspiV4"]
106
79
  ) => {
107
80
  const sourceSchema = transactionSchemas[schemaId];
108
81
  if (!overlays || overlays.length < 1) return sourceSchema;
109
82
  let mergedSchema = sourceSchema;
110
83
  overlays.forEach((overlay) => {
111
- const overlaySchema = overlaysMap[overlay] || {};
112
- mergedSchema = merge(overlaySchema, mergedSchema, {
84
+ const overlaySchema = overlaysMap[schemaId][overlay] || {};
85
+ mergedSchema = merge(mergedSchema, overlaySchema, {
86
+ customMerge: (key) => {
87
+ if (key === "enum") {
88
+ return mergeEnums;
89
+ }
90
+ },
113
91
  arrayMerge: combineMerge,
114
92
  });
115
93
  });
116
- // console.log("mergedSchema", mergedSchema);
117
94
  return mergedSchema;
118
95
  };
119
96
 
120
97
  const getValidator = (schemaId, overlays) => {
121
- let validator = ajv.getSchema(schemaId);
122
- if (!validator) {
123
- const schema = getTransactionSchema(schemaId, overlays);
124
- ajv.addSchema(schema, schemaId);
125
- validator = ajv.getSchema(schemaId);
126
- }
127
- return validator;
98
+ return getSubschemaValidator("", schemaId, overlays);
128
99
  };
129
100
 
130
101
  // common functions for v1 and v2
@@ -159,7 +130,7 @@ const isPathValid = (path, schemaId, overlays) => {
159
130
  }
160
131
  };
161
132
 
162
- const getSubschemaValidator = (path, schemaId, overlays = ["baspiV4"]) => {
133
+ const getSubschemaValidator = (path, schemaId, overlays) => {
163
134
  const subSchema = getSubschema(path, schemaId, overlays);
164
135
  const overlayKey = (overlays || []).join(".");
165
136
  // see if we can retrieve the schema by path, schemaId and overlays
@@ -192,6 +163,7 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
192
163
  }
193
164
  const propertyName = pathArray.shift();
194
165
  const subPath = "/" + pathArray.join("/");
166
+
195
167
  let subSchema = schema.properties
196
168
  ? schema.properties[propertyName]
197
169
  : undefined;
@@ -202,10 +174,9 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
202
174
  subSchema = schema.items;
203
175
  return getTitleAtPath(subSchema, subPath, rootPath);
204
176
  }
205
- const discriminator = schema.discriminator?.propertyName;
206
- if (discriminator) {
177
+ const oneOfs = schema.oneOf;
178
+ if (oneOfs) {
207
179
  // only single dependency discriminator, oneOf keyword is supported
208
- const oneOfs = schema.oneOf;
209
180
  const matchingOneOf = oneOfs.find(
210
181
  (oneOf) => oneOf["properties"][propertyName]
211
182
  );
@@ -257,8 +228,6 @@ const validateVerifiedClaims = (verifiedClaims, schemaId, overlays) => {
257
228
 
258
229
  module.exports = {
259
230
  ajv,
260
- transactionSchema, // v1 deprecated
261
- validator, // v1 deprecated
262
231
  getTransactionSchema,
263
232
  getValidator,
264
233
  getSubschema,
@@ -267,16 +236,5 @@ module.exports = {
267
236
  getTitleAtPath,
268
237
  verifiedClaimsSchema,
269
238
  validateVerifiedClaims,
270
- baspiOverlay,
271
- ta6Overlay,
272
- ta7Overlay,
273
- ta10Overlay,
274
- lpe1Overlay,
275
- fme1Overlay,
276
- llc1Overlay,
277
- ntsOverlay,
278
- con29ROverlay,
279
- con29DWOverlay,
280
- rdsOverlay,
281
- oc1Overlay,
239
+ overlaysMap,
282
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "2.3.0",
3
+ "version": "3.0.0-10",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -478,6 +478,11 @@
478
478
  "radonTest": { "yesNo": "No" },
479
479
  "remedialMeasuresOnConstruction": { "yesNo": "No" }
480
480
  },
481
+ "groundStability": {
482
+ "groundStabilityRiskReport": {
483
+ "recommendedActionIndicator": "Yes"
484
+ }
485
+ },
481
486
  "otherEnvironmental": {
482
487
  "yesNo": "No"
483
488
  }
@@ -889,26 +894,7 @@
889
894
  "providerName": "TM Group",
890
895
  "status": "Delivered",
891
896
  "reportDate": "2022-10-13T08:55:49",
892
- "contentTypes": ["Environmental Risks"],
893
- "results": [
894
- {
895
- "contentType": "Environmental Risks",
896
- "riskResults": [
897
- {
898
- "riskCategory": "Flood",
899
- "recommendedActionIndicator": "Yes"
900
- },
901
- {
902
- "riskCategory": "Ground Stability",
903
- "recommendedActionIndicator": "Yes"
904
- },
905
- {
906
- "riskCategory": "Mining",
907
- "recommendedActionIndicator": "No"
908
- }
909
- ]
910
- }
911
- ]
897
+ "contentTypes": ["Environmental Risks"]
912
898
  }
913
899
  ]
914
900
  }