@pdtf/schemas 2.0.0-4 → 2.0.0-6
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 +9 -9
- package/package.json +1 -1
- package/src/examples/v2/exampleTransaction.json +1 -1
- package/src/schemas/v2/combined.json +7093 -2058
- package/src/schemas/v2/overlays/baspi.json +9 -1
- package/src/tests/v2/verifiedClaimsValidator.test.js +128 -0
- package/src/utils/extractOverlay.js +2 -12
- package/src/utils/extractProperties.js +44 -0
- package/src/schemas/v2/merged.json +0 -28667
- /package/src/schemas/v2/{core.json → pdtf-transaction.json} +0 -0
package/index.js
CHANGED
|
@@ -45,7 +45,7 @@ const validator = ajv.compile(transactionSchema);
|
|
|
45
45
|
|
|
46
46
|
// v2, via accessor functions and overlays
|
|
47
47
|
const combinedSchema = require("./src/schemas/v2/combined.json");
|
|
48
|
-
const
|
|
48
|
+
const v2CoreSchema = require("./src/schemas/v2/pdtf-transaction.json");
|
|
49
49
|
|
|
50
50
|
const baspiOverlay = require("./src/schemas/v2/overlays/baspi.json");
|
|
51
51
|
// const ta6Overlay = require("./src/schemas/v2/overlays/ta6.json");
|
|
@@ -58,12 +58,13 @@ const baspiOverlay = require("./src/schemas/v2/overlays/baspi.json");
|
|
|
58
58
|
// const rdsOverlay = require("./src/schemas/v2/overlays/rds.json");
|
|
59
59
|
// const oc1Overlay = require("./src/schemas/v2/overlays/oc1.json");
|
|
60
60
|
|
|
61
|
-
const overlays = { baspiV4: baspiOverlay };
|
|
61
|
+
const overlays = { baspiV4: baspiOverlay, null: {} };
|
|
62
62
|
|
|
63
63
|
const transactionSchemas = {
|
|
64
64
|
"https://trust.propdata.org.uk/schemas/v1/pdtf-transaction.json":
|
|
65
65
|
transactionSchema,
|
|
66
|
-
"https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json":
|
|
66
|
+
"https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json":
|
|
67
|
+
v2CoreSchema,
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
const combineMerge = (target, source, options) => {
|
|
@@ -139,8 +140,8 @@ const isPathValid = (path, schemaId, overlay) => {
|
|
|
139
140
|
|
|
140
141
|
const getSubschemaValidator = (path, schemaId, overlay) => {
|
|
141
142
|
const subSchema = getSubschema(path, schemaId, overlay);
|
|
142
|
-
// see if we can retrieve the schema by path
|
|
143
|
-
const cacheKey = `${path}-${schemaId}`;
|
|
143
|
+
// see if we can retrieve the schema by path, schemaId and overlay
|
|
144
|
+
const cacheKey = `${path}-${schemaId}-${overlay}`;
|
|
144
145
|
let validator = ajv.getSchema(cacheKey);
|
|
145
146
|
// retrieve whole schema by $id if available
|
|
146
147
|
if (!validator && subSchema.$id) validator = ajv.getSchema(cacheKey);
|
|
@@ -195,7 +196,7 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
|
|
|
195
196
|
}
|
|
196
197
|
};
|
|
197
198
|
|
|
198
|
-
const validateVerifiedClaims = (verifiedClaims) => {
|
|
199
|
+
const validateVerifiedClaims = (verifiedClaims, schemaId, overlay) => {
|
|
199
200
|
const validatorVClaims = ajv.compile(verifiedClaimsSchema);
|
|
200
201
|
|
|
201
202
|
const validationErrorsArr = [];
|
|
@@ -213,11 +214,10 @@ const validateVerifiedClaims = (verifiedClaims) => {
|
|
|
213
214
|
|
|
214
215
|
verifiedClaimsArray.forEach((claim) => {
|
|
215
216
|
const paths = Object.keys(claim.claims);
|
|
216
|
-
|
|
217
217
|
for (const path of paths) {
|
|
218
|
-
const validPath = isPathValid(path);
|
|
218
|
+
const validPath = isPathValid(path, schemaId, overlay);
|
|
219
219
|
if (validPath) {
|
|
220
|
-
const subValidator = getSubschemaValidator(path);
|
|
220
|
+
const subValidator = getSubschemaValidator(path, schemaId, overlay);
|
|
221
221
|
const isValid = subValidator(claim.claims[path]);
|
|
222
222
|
if (!isValid) {
|
|
223
223
|
validationErrorsArr.push(...subValidator.errors);
|
package/package.json
CHANGED