@pdtf/schemas 0.6.8 → 0.6.11

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
@@ -41,7 +41,18 @@ const getSubschema = (path) => {
41
41
  }
42
42
  return pathArray.reduce((schema, pathElement) => {
43
43
  if (schema.type === "array") return schema.items;
44
- return schema.properties[pathElement];
44
+ if (schema.properties[pathElement]) return schema.properties[pathElement];
45
+ const dependencies = schema.dependencies;
46
+ if (dependencies) {
47
+ // only single dependency discriminator, oneOf keyword is supported
48
+ const dependencyDiscriminator = Object.keys(dependencies)[0];
49
+ const oneOfs = dependencies[dependencyDiscriminator].oneOf;
50
+ const matchingOneOf = oneOfs.find(
51
+ (oneOf) => oneOf["properties"][pathElement]
52
+ );
53
+ if (matchingOneOf) return matchingOneOf["properties"][pathElement];
54
+ }
55
+ return undefined;
45
56
  }, transactionSchema);
46
57
  };
47
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.6.8",
3
+ "version": "0.6.11",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -282,7 +282,8 @@
282
282
  }
283
283
  },
284
284
  "centralHeating": {
285
- "hasCentralHeating": {
285
+ "hasCentralHeating": "Yes",
286
+ "centralHeatingDetails": {
286
287
  "boilerInstallationCertificate": {
287
288
  "yesNo": "Yes",
288
289
  "details": "Certified installation"
@@ -290,10 +291,8 @@
290
291
  "heatingInGoodWorkingOrder": {
291
292
  "yesNo": "Yes"
292
293
  },
293
- "yesNo": "Yes",
294
294
  "centralHeatingFuel": "Gas boiler",
295
295
  "centralHeatingInstalled": "2016-04-20",
296
- "heatingServiceReport": "Full service history available from Whickham Plumbing & Heating ",
297
296
  "heatingLastServiced": "2021-03-26"
298
297
  }
299
298
  },
@@ -1005,90 +1005,89 @@
1005
1005
  "baspiRef": "A7.4",
1006
1006
  "RDSRef": "Buildings|BuildingSections/isUnheated=no|yes|true|false",
1007
1007
  "lawSocietyRef": "TA6/12.3",
1008
+ "title": "Central Heating",
1008
1009
  "type": "object",
1009
1010
  "required": ["hasCentralHeating"],
1010
1011
  "properties": {
1011
1012
  "hasCentralHeating": {
1012
1013
  "title": "Is there full/partial central heating in your property?",
1013
- "yesNoCentralHeatingDetailIfYes": {
1014
- "type": "object",
1015
- "properties": {
1016
- "yesNo": {
1017
- "type": "string",
1018
- "title": "",
1019
- "enum": ["Yes", "No"]
1020
- }
1014
+ "type": "string",
1015
+ "enum": ["Yes", "No"]
1016
+ }
1017
+ },
1018
+ "dependencies": {
1019
+ "hasCentralHeating": {
1020
+ "oneOf": [
1021
+ {
1022
+ "properties": {
1023
+ "hasCentralHeating": {
1024
+ "enum": ["No"]
1025
+ }
1026
+ },
1027
+ "additionalProperties": false
1021
1028
  },
1022
- "required": ["yesNo"],
1023
- "dependencies": {
1024
- "yesNo": {
1025
- "oneOf": [
1026
- {
1027
- "properties": {
1028
- "yesNo": {
1029
- "enum": ["No"]
1030
- }
1029
+ {
1030
+ "properties": {
1031
+ "hasCentralHeating": {
1032
+ "enum": ["Yes"]
1033
+ },
1034
+ "centralHeatingDetails": {
1035
+ "type": "object",
1036
+ "title": "Central Heating Details",
1037
+ "properties": {
1038
+ "centralHeatingFuel": {
1039
+ "baspiRef": "A7.5.1",
1040
+ "RDSRef": "Buildings|BuildingSections/Heating/isGas=no|yes|true|false",
1041
+ "lawSocietyRef": "TA6/12.3a",
1042
+ "title": "Please provide details of the type of fuel which the system and boiler runs on",
1043
+ "type": "string",
1044
+ "minLength": 1
1031
1045
  },
1032
- "additionalProperties": false
1033
- },
1034
- {
1035
- "properties": {
1036
- "yesNo": {
1037
- "enum": ["Yes"]
1038
- },
1039
- "centralHeatingFuel": {
1040
- "baspiRef": "A7.5.1",
1041
- "RDSRef": "Buildings|BuildingSections/Heating/isGas=no|yes|true|false",
1042
- "lawSocietyRef": "TA6/12.3a",
1043
- "title": "Please provide details of the type of fuel which the system and boiler runs on",
1044
- "type": "string",
1045
- "minLength": 1
1046
- },
1047
- "centralHeatingInstalled": {
1048
- "baspiRef": "A7.5.2",
1049
- "RDSRef": "Objects/Installed",
1050
- "lawSocietyRef": "TA6/12.3b",
1051
- "title": "When was the heating system and boiler installed?",
1052
- "type": "string",
1053
- "format": "date"
1054
- },
1055
- "boilerInstallationCertificate": {
1056
- "baspiRef": "A7.5.3",
1057
- "RDSRef": "Objects/Installation,Objects/Certificates",
1058
- "lawSocietyRef": "TA6/12.3b",
1059
- "title": "Was a gas boiler installed after 1st April 2005, or a solid fuel or oil boiler installed after 1 October 2010?",
1060
- "$ref": "#/$defs/yesNoDetailIfYes",
1061
- "description": "If yes, please supply a copy of the installation completion certificate from a competent person qualified under the relevant self-certification scheme e.g. HETAS etc"
1062
- },
1063
- "heatingLastServiced": {
1064
- "baspiRef": "A7.5.4",
1065
- "RDSRef": "Objects/Maintenance",
1066
- "lawSocietyRef": "TA6/12.3d",
1067
- "title": "When was the heating system and boiler last serviced or maintained?",
1068
- "type": "string",
1069
- "format": "date"
1070
- },
1071
- "heatingServiceReport": {
1072
- "baspiRef": "A7.5.5",
1073
- "RDSRef": "Objects/Servicing",
1074
- "lawSocietyRef": "TA6/12.3d",
1075
- "title": "Please provide a copy of the service or maintenance works report",
1076
- "type": "string"
1077
- },
1078
- "heatingInGoodWorkingOrder": {
1079
- "baspiRef": "A7.5.6",
1080
- "RDSRef": "Objects/Condition=?",
1081
- "lawSocietyRef": "TA6/12.3c",
1082
- "title": "Is the heating system in good working order to your satisfaction?",
1083
- "$ref": "#/$defs/yesNoDetailIfNo",
1084
- "description": "If 'No' please provide details"
1085
- }
1046
+ "centralHeatingInstalled": {
1047
+ "baspiRef": "A7.5.2",
1048
+ "RDSRef": "Objects/Installed",
1049
+ "lawSocietyRef": "TA6/12.3b",
1050
+ "title": "When was the heating system and boiler installed?",
1051
+ "type": "string",
1052
+ "format": "date"
1053
+ },
1054
+ "boilerInstallationCertificate": {
1055
+ "baspiRef": "A7.5.3",
1056
+ "RDSRef": "Objects/Installation,Objects/Certificates",
1057
+ "lawSocietyRef": "TA6/12.3b",
1058
+ "title": "Was a gas boiler installed after 1st April 2005, or a solid fuel or oil boiler installed after 1 October 2010?",
1059
+ "$ref": "#/$defs/yesNoDetailIfYes",
1060
+ "description": "If yes, please supply a copy of the installation completion certificate from a competent person qualified under the relevant self-certification scheme e.g. HETAS etc"
1061
+ },
1062
+ "heatingLastServiced": {
1063
+ "baspiRef": "A7.5.4",
1064
+ "RDSRef": "Objects/Maintenance",
1065
+ "lawSocietyRef": "TA6/12.3d",
1066
+ "title": "When was the heating system and boiler last serviced or maintained? Please provide a copy of the service or maintenance works report ",
1067
+ "type": "string",
1068
+ "format": "date"
1069
+ },
1070
+ "heatingInGoodWorkingOrder": {
1071
+ "baspiRef": "A7.5.6",
1072
+ "RDSRef": "Objects/Condition=?",
1073
+ "lawSocietyRef": "TA6/12.3c",
1074
+ "title": "Is the heating system in good working order to your satisfaction?",
1075
+ "$ref": "#/$defs/yesNoDetailIfNo",
1076
+ "description": "If 'No' please provide details"
1086
1077
  }
1087
- }
1088
- ]
1089
- }
1078
+ },
1079
+ "required": [
1080
+ "centralHeatingFuel",
1081
+ "centralHeatingInstalled",
1082
+ "boilerInstallationCertificate",
1083
+ "heatingLastServiced",
1084
+ "heatingInGoodWorkingOrder"
1085
+ ]
1086
+ }
1087
+ },
1088
+ "required": ["centralHeatingDetails"]
1090
1089
  }
1091
- }
1090
+ ]
1092
1091
  }
1093
1092
  }
1094
1093
  },
@@ -81,6 +81,35 @@ test("correctly gets another subschema through an arrays element", () => {
81
81
  expect(subschema.title).toBe("First name");
82
82
  });
83
83
 
84
+ test("correctly gets a subschema through a dependency", () => {
85
+ const subschema = getSubschema(
86
+ "/propertyPack/materialFacts/delayFactors/hasDelayFactors/details"
87
+ );
88
+ expect(subschema.title).toBe("Details");
89
+ });
90
+
91
+ test("correctly gets another subschema through a dependency", () => {
92
+ const subschema = getSubschema(
93
+ "/propertyPack/materialFacts/ownership/leaseholdDetails/lengthOfLeaseInYears"
94
+ );
95
+ expect(subschema.title).toBe("Length of lease (years)");
96
+ });
97
+
98
+ test("correctly gets yet another subschema through a dependency", () => {
99
+ const subschema = getSubschema(
100
+ "/propertyPack/materialFacts/ownership/leaseholdDetails/rentIncrease/details"
101
+ );
102
+ expect(subschema.title).toBe("Details");
103
+ });
104
+
105
+ test("correctly gets yet, yet another subschema through a dependency", () => {
106
+ const subschema = getSubschema(
107
+ "/propertyPack/materialFacts/listingAndConservation/isConservationArea/yesNo"
108
+ );
109
+ expect(subschema.type).toBe("string");
110
+ expect(subschema.enum).toStrictEqual(["Yes", "No"]);
111
+ });
112
+
84
113
  test("correctly gets a subschema validator which is already cached", () => {
85
114
  const validator = getSubschemaValidator(
86
115
  "/propertyPack/energyPerformanceCertificate"