@pdtf/schemas 3.5.1-7 → 3.5.1-9

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
@@ -104,7 +104,7 @@ const transactionSchemas = {
104
104
  };
105
105
 
106
106
  // Custom array merge function for oneOf arrays
107
- const arrayMerge = (target, source) => {
107
+ const arrayMerge = (target, source, options) => {
108
108
  // For string arrays (enum, required, etc.)
109
109
  if (
110
110
  target.length > 0 &&
@@ -114,16 +114,23 @@ const arrayMerge = (target, source) => {
114
114
  source[0] &&
115
115
  typeof source[0] === "string"
116
116
  ) {
117
- // For required arrays, combine them (remove duplicates)
118
- // Check if this looks like a required array (contains field names, not enum values)
119
- const isRequiredArray = target.some(
117
+ // Detect if this is a required array by checking the parent key
118
+ // Required arrays are property names (camelCase, no spaces)
119
+ // Enum arrays are values (can contain spaces, capitals, etc.)
120
+ const isRequiredArray = target.every(
120
121
  (item) =>
121
122
  typeof item === "string" &&
122
123
  item.length > 0 &&
123
- !item.includes("Yes") &&
124
- !item.includes("No") &&
125
- !item.includes("Not known") &&
126
- !item.includes("To be connected")
124
+ // Required field names are typically camelCase without spaces
125
+ !item.includes(" ") &&
126
+ // First character is usually lowercase for field names
127
+ (item[0] === item[0].toLowerCase() || item.startsWith("is") || item.startsWith("has"))
128
+ ) && source.every(
129
+ (item) =>
130
+ typeof item === "string" &&
131
+ item.length > 0 &&
132
+ !item.includes(" ") &&
133
+ (item[0] === item[0].toLowerCase() || item.startsWith("is") || item.startsWith("has"))
127
134
  );
128
135
 
129
136
  if (isRequiredArray) {
@@ -137,7 +144,7 @@ const arrayMerge = (target, source) => {
137
144
  return combined;
138
145
  }
139
146
 
140
- // For other string arrays (like enum), use source if it exists, otherwise use target
147
+ // For other string arrays (like enum), replace with source
141
148
  return source.length > 0 ? source : target;
142
149
  }
143
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "3.5.1-7",
3
+ "version": "3.5.1-9",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -4246,14 +4246,22 @@
4246
4246
  "properties": {
4247
4247
  "typeOfLeasehold": {
4248
4248
  "ta7Ref": "1.1",
4249
- "title": "What type of leasehold property does the seller own?",
4250
- "description": "'Flat'includes maisonette and apartment.",
4251
- "type": "string",
4252
- "enum": [
4253
- "Flat",
4254
- "Shared ownership",
4255
- "Long leasehold house"
4256
- ]
4249
+ "title": "Type of leasehold property",
4250
+ "type": "object",
4251
+ "ta7Required": ["leaseholdType"],
4252
+ "properties": {
4253
+ "leaseholdType": {
4254
+ "ta7Ref": "1.1.1",
4255
+ "title": "What type of leasehold property does the seller own?",
4256
+ "description": "'Flat'includes maisonette and apartment.",
4257
+ "type": "string",
4258
+ "enum": [
4259
+ "Flat",
4260
+ "Shared ownership",
4261
+ "Long leasehold house"
4262
+ ]
4263
+ }
4264
+ }
4257
4265
  },
4258
4266
  "sharedOwnership": {
4259
4267
  "baspi4Ref": "A1.3.1",
@@ -424,6 +424,7 @@
424
424
  capacity
425
425
  leaseholdInformation
426
426
  typeOfLeasehold
427
+ leaseholdType
427
428
  sharedOwnership
428
429
  isSharedOwnership
429
430
  sharedOwnershipPercentage
@@ -86,7 +86,15 @@
86
86
  ],
87
87
  "properties": {
88
88
  "typeOfLeasehold": {
89
- "ta7Ref": "1.1"
89
+ "ta7Ref": "1.1",
90
+ "required": [
91
+ "leaseholdType"
92
+ ],
93
+ "properties": {
94
+ "leaseholdType": {
95
+ "ta7Ref": "1.1.1"
96
+ }
97
+ }
90
98
  },
91
99
  "sharedOwnership": {
92
100
  "required": [
@@ -3517,14 +3517,20 @@
3517
3517
  "type": "object",
3518
3518
  "properties": {
3519
3519
  "typeOfLeasehold": {
3520
- "title": "What type of leasehold property does the seller own?",
3521
- "description": "'Flat'includes maisonette and apartment.",
3522
- "type": "string",
3523
- "enum": [
3524
- "Flat",
3525
- "Shared ownership",
3526
- "Long leasehold house"
3527
- ]
3520
+ "title": "Type of leasehold property",
3521
+ "type": "object",
3522
+ "properties": {
3523
+ "leaseholdType": {
3524
+ "title": "What type of leasehold property does the seller own?",
3525
+ "description": "'Flat'includes maisonette and apartment.",
3526
+ "type": "string",
3527
+ "enum": [
3528
+ "Flat",
3529
+ "Shared ownership",
3530
+ "Long leasehold house"
3531
+ ]
3532
+ }
3533
+ }
3528
3534
  },
3529
3535
  "sharedOwnership": {
3530
3536
  "type": "object",
@@ -538,7 +538,9 @@
538
538
  }
539
539
  },
540
540
  "leaseholdInformation": {
541
- "typeOfLeasehold": "string",
541
+ "typeOfLeasehold": {
542
+ "leaseholdType": "string"
543
+ },
542
544
  "sharedOwnership": {
543
545
  "isSharedOwnership": "variant",
544
546
  "sharedOwnershipPercentage": "number",
@@ -591,3 +591,25 @@ test("waterAndDrainage state with mainsFoulDrainage No missing offMainsDrainageS
591
591
  );
592
592
  expect(relevantError).toBeDefined();
593
593
  });
594
+
595
+ test("TA7 overlay organisesBuildingInsurance enum has exactly three items", () => {
596
+ const schema = getTransactionSchema(schemaId, ["ta7ed3"]);
597
+
598
+ // Navigate to the organisesBuildingInsurance property in the merged schema
599
+ const organisesBuildingInsurance =
600
+ schema.properties?.propertyPack?.properties?.ownership?.properties
601
+ ?.ownershipsToBeTransferred?.items?.oneOf?.[2]?.properties
602
+ ?.leaseholdInformation?.properties?.contactDetails?.properties
603
+ ?.serviceContactAssignments?.properties?.organisesBuildingInsurance;
604
+
605
+ expect(organisesBuildingInsurance).toBeDefined();
606
+ expect(organisesBuildingInsurance.enum).toBeDefined();
607
+
608
+ // The TA7 overlay defines exactly 3 enum values, which should replace the base schema's 6 values
609
+ expect(organisesBuildingInsurance.enum).toHaveLength(3);
610
+ expect(organisesBuildingInsurance.enum).toEqual([
611
+ "the Lessees",
612
+ "Management Company",
613
+ "Landlord",
614
+ ]);
615
+ });