@pdtf/schemas 1.1.1 → 2.0.0-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 +99 -29
- package/package.json +5 -3
- package/src/examples/v2/exampleTransaction.json +899 -0
- package/src/schemas/v1/freehold-information.json +2051 -0
- package/src/schemas/v1/material-facts.json +3 -3
- package/src/schemas/v1/pdtf-transaction.json +3 -0
- package/src/schemas/v2/baspiNotes.html +102 -0
- package/src/schemas/v2/combined.json +27796 -0
- package/src/schemas/v2/core.json +26224 -0
- package/src/schemas/v2/overlays/baspi.json +8857 -0
- package/src/schemas/v2/overlays/con29DW.json +656 -0
- package/src/schemas/v2/overlays/con29R.json +3115 -0
- package/src/schemas/v2/overlays/fme1.json +1610 -0
- package/src/schemas/v2/overlays/llc1.json +46 -0
- package/src/schemas/v2/overlays/lpe1.json +2424 -0
- package/src/schemas/v2/overlays/nts.json +162 -0
- package/src/schemas/v2/overlays/oc1.json +2799 -0
- package/src/schemas/v2/overlays/rds.json +3746 -0
- package/src/schemas/v2/overlays/ta10.json +4 -0
- package/src/schemas/v2/overlays/ta6.json +2311 -0
- package/src/schemas/v2/overlays/ta7.json +901 -0
- package/src/tests/{pdtfVerifiedClaims.test.js → v1/pdtfVerifiedClaims.test.js} +4 -4
- package/src/tests/{transactionSchema.test.js → v1/transactionSchema.test.js} +24 -3
- package/src/tests/{verifiedClaimsValidator.test.js → v1/verifiedClaimsValidator.test.js} +3 -3
- package/src/tests/v2/transactionSchema.test.js +255 -0
- package/src/utils/extractOverlay.js +100 -0
- /package/src/examples/{exampleAddParticipantVouch.json → v1/exampleAddParticipantVouch.json} +0 -0
- /package/src/examples/{exampleDocumentedVouch.json → v1/exampleDocumentedVouch.json} +0 -0
- /package/src/examples/{exampleElectronicRecord.json → v1/exampleElectronicRecord.json} +0 -0
- /package/src/examples/{exampleTransaction.json → v1/exampleTransaction.json} +0 -0
- /package/src/examples/{exampleVouch.json → v1/exampleVouch.json} +0 -0
package/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
const { dereference } = require("@jdw/jst");
|
|
2
|
+
const merge = require("deepmerge");
|
|
2
3
|
const Ajv = require("ajv");
|
|
3
4
|
const addFormats = require("ajv-formats");
|
|
5
|
+
const ajv = new Ajv({
|
|
6
|
+
allErrors: true,
|
|
7
|
+
// schema contains additional baspiRef and RDSRef metadata which is not strictly valid
|
|
8
|
+
strictSchema: false,
|
|
9
|
+
discriminator: true,
|
|
10
|
+
});
|
|
11
|
+
// Adds date formats among other types to the validator.
|
|
12
|
+
addFormats(ajv);
|
|
4
13
|
|
|
14
|
+
// v1, deprecated direct access
|
|
5
15
|
const pdtfTransaction = require("./src/schemas/v1/pdtf-transaction.json");
|
|
6
16
|
const materialFacts = require("./src/schemas/v1/material-facts.json");
|
|
7
17
|
const legalInformation = require("./src/schemas/v1/legal-information.json");
|
|
@@ -30,50 +40,106 @@ const subSchemas = {
|
|
|
30
40
|
"https://trust.propdata.org.uk/schemas/v1/searches/drainage-and-water.json":
|
|
31
41
|
drainageAndWater,
|
|
32
42
|
};
|
|
33
|
-
|
|
34
43
|
const transactionSchema = dereference(pdtfTransaction, (id) => subSchemas[id]);
|
|
44
|
+
const validator = ajv.compile(transactionSchema);
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
46
|
+
// v2, via accessor functions and overlays
|
|
47
|
+
const combinedSchema = require("./src/schemas/v2/combined.json");
|
|
48
|
+
const coreSchema = require("./src/schemas/v2/core.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 lpe1Overlay = require("./src/schemas/v2/overlays/lpe1.json");
|
|
54
|
+
// const fme1Overlay = require("./src/schemas/v2/overlays/fme1.json");
|
|
55
|
+
// const llc1Overlay = require("./src/schemas/v2/overlays/llc1.json");
|
|
56
|
+
// const con29ROverlay = require("./src/schemas/v2/overlays/con29R.json");
|
|
57
|
+
// const con29DWOverlay = require("./src/schemas/v2/overlays/con29DW.json");
|
|
58
|
+
// const rdsOverlay = require("./src/schemas/v2/overlays/rds.json");
|
|
59
|
+
// const oc1Overlay = require("./src/schemas/v2/overlays/oc1.json");
|
|
60
|
+
|
|
61
|
+
const overlays = { baspiV4: baspiOverlay };
|
|
62
|
+
|
|
63
|
+
const transactionSchemas = {
|
|
64
|
+
"https://trust.propdata.org.uk/schemas/v1/pdtf-transaction.json":
|
|
65
|
+
transactionSchema,
|
|
66
|
+
"https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json": coreSchema,
|
|
67
|
+
};
|
|
44
68
|
|
|
45
|
-
const
|
|
69
|
+
const combineMerge = (target, source, options) => {
|
|
70
|
+
const destination = target.slice();
|
|
71
|
+
source.forEach((item, index) => {
|
|
72
|
+
if (typeof destination[index] === "undefined") {
|
|
73
|
+
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
74
|
+
} else if (options.isMergeableObject(item)) {
|
|
75
|
+
destination[index] = merge(target[index], item, options);
|
|
76
|
+
} else if (target.indexOf(item) === -1) {
|
|
77
|
+
destination.push(item);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return destination;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const getTransactionSchema = (
|
|
84
|
+
schemaId = "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json",
|
|
85
|
+
overlay = "baspiV4"
|
|
86
|
+
) => {
|
|
87
|
+
const sourceSchema = transactionSchemas[schemaId];
|
|
88
|
+
const overlaySchema = overlays[overlay];
|
|
89
|
+
if (!overlaySchema) return sourceSchema;
|
|
90
|
+
const mergedSchema = merge(overlaySchema, sourceSchema, {
|
|
91
|
+
arrayMerge: combineMerge,
|
|
92
|
+
});
|
|
93
|
+
// console.log("mergedSchema", mergedSchema);
|
|
94
|
+
return mergedSchema;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const getValidator = (schemaId, overlay = "baspiV4") => {
|
|
98
|
+
let validator = ajv.getSchema(schemaId);
|
|
99
|
+
if (!validator) {
|
|
100
|
+
const schema = getTransactionSchema(schemaId, overlay);
|
|
101
|
+
ajv.addSchema(schema, schemaId);
|
|
102
|
+
validator = ajv.getSchema(schemaId);
|
|
103
|
+
}
|
|
104
|
+
return validator;
|
|
105
|
+
};
|
|
46
106
|
|
|
47
|
-
|
|
107
|
+
// common functions for v1 and v2
|
|
108
|
+
const getSubschema = (path, sourceSchema = transactionSchema) => {
|
|
48
109
|
const pathArray = path.split("/").slice(1);
|
|
49
|
-
if (pathArray.length < 1) return
|
|
110
|
+
if (pathArray.length < 1) return sourceSchema;
|
|
50
111
|
return pathArray.reduce((schema, pathElement) => {
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
112
|
+
const { type, items, properties, oneOf } = schema;
|
|
113
|
+
if (type === "array") return items;
|
|
114
|
+
if (properties?.[pathElement]) return properties[pathElement];
|
|
115
|
+
if (oneOf) {
|
|
116
|
+
let matchingProperty;
|
|
117
|
+
oneOf.forEach((aOneOf) => {
|
|
118
|
+
if (aOneOf.type === "array" && !Number.isNaN(pathElement)) {
|
|
119
|
+
matchingProperty = aOneOf.items;
|
|
120
|
+
} else if (aOneOf.properties?.[pathElement]) {
|
|
121
|
+
matchingProperty = aOneOf.properties?.[pathElement];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (matchingProperty) return matchingProperty;
|
|
61
125
|
}
|
|
62
126
|
return undefined;
|
|
63
|
-
},
|
|
127
|
+
}, sourceSchema);
|
|
64
128
|
};
|
|
65
129
|
|
|
66
|
-
const isPathValid = (path) => {
|
|
130
|
+
const isPathValid = (path, schema = transactionSchema) => {
|
|
67
131
|
try {
|
|
68
|
-
return getSubschema(path) !== undefined;
|
|
132
|
+
return getSubschema(path, schema) !== undefined;
|
|
69
133
|
} catch (err) {
|
|
70
134
|
return false;
|
|
71
135
|
}
|
|
72
136
|
};
|
|
73
137
|
|
|
74
|
-
const getSubschemaValidator = (path) => {
|
|
75
|
-
const subSchema = getSubschema(path);
|
|
138
|
+
const getSubschemaValidator = (path, schema = transactionSchema) => {
|
|
139
|
+
const subSchema = getSubschema(path, schema);
|
|
140
|
+
// see if we can retrieve the schema by path
|
|
76
141
|
let validator = ajv.getSchema(path);
|
|
142
|
+
// retrieve whole schema by $id if available
|
|
77
143
|
if (!validator && subSchema.$id) validator = ajv.getSchema(subSchema.$id);
|
|
78
144
|
if (!validator) {
|
|
79
145
|
ajv.addSchema(subSchema, path);
|
|
@@ -82,6 +148,7 @@ const getSubschemaValidator = (path) => {
|
|
|
82
148
|
return validator;
|
|
83
149
|
};
|
|
84
150
|
|
|
151
|
+
// v1, deprecated
|
|
85
152
|
const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
86
153
|
if (path === "") path = "/";
|
|
87
154
|
let pathArray = path.split("/").slice(1);
|
|
@@ -164,8 +231,11 @@ const validateVerifiedClaims = (verifiedClaims) => {
|
|
|
164
231
|
};
|
|
165
232
|
|
|
166
233
|
module.exports = {
|
|
167
|
-
|
|
168
|
-
|
|
234
|
+
ajv,
|
|
235
|
+
transactionSchema, // v1 deprecated
|
|
236
|
+
validator, // v1 deprecated
|
|
237
|
+
getTransactionSchema,
|
|
238
|
+
getValidator,
|
|
169
239
|
getSubschema,
|
|
170
240
|
isPathValid,
|
|
171
241
|
getSubschemaValidator,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdtf/schemas",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-0",
|
|
4
4
|
"description": "Property Data Trust Framework Schemas and Utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
"homepage": "https://github.com/Property-Data-Trust-Framework/schemas#readme",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@jdw/jst": "^2.0.0-beta.15",
|
|
29
|
-
"ajv": "^8.
|
|
29
|
+
"ajv": "^8.12.0",
|
|
30
30
|
"ajv-formats": "^2.1.1",
|
|
31
|
-
"
|
|
31
|
+
"deepmerge": "^4.3.1",
|
|
32
|
+
"jsonpointer": "^5.0.0",
|
|
33
|
+
"traverse": "^0.6.7"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"jest": "^27.5.1"
|