@hestia-earth/schema-validation 9.4.0 → 9.7.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/package.json +1 -1
- package/validate-jsonld.js +49 -33
package/package.json
CHANGED
package/validate-jsonld.js
CHANGED
|
@@ -83,40 +83,56 @@ var findFiles = function (directory) { return fs_1.readdirSync(directory)
|
|
|
83
83
|
.flat()
|
|
84
84
|
.filter(Boolean); };
|
|
85
85
|
exports.run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
-
var contentValidator, jsonldFiles, results, jsonldFiles_1, jsonldFiles_1_1, filepath, content, nodes, allErrors, success,
|
|
87
|
-
var e_1,
|
|
88
|
-
return __generator(this, function (
|
|
89
|
-
switch (
|
|
86
|
+
var contentValidator, jsonldFiles, results, jsonldFiles_1, jsonldFiles_1_1, filepath, content, nodes, allErrors, nodes_1, nodes_1_1, node, errors, e_1_1, success, e_2_1;
|
|
87
|
+
var e_2, _a, e_1, _b;
|
|
88
|
+
return __generator(this, function (_c) {
|
|
89
|
+
switch (_c.label) {
|
|
90
90
|
case 0:
|
|
91
91
|
contentValidator = validate_1.validator(domain, strictMode === 'true');
|
|
92
92
|
jsonldFiles = findFiles(folder);
|
|
93
93
|
results = [];
|
|
94
|
-
|
|
94
|
+
_c.label = 1;
|
|
95
95
|
case 1:
|
|
96
|
-
|
|
96
|
+
_c.trys.push([1, 13, 14, 15]);
|
|
97
97
|
jsonldFiles_1 = __values(jsonldFiles), jsonldFiles_1_1 = jsonldFiles_1.next();
|
|
98
|
-
|
|
98
|
+
_c.label = 2;
|
|
99
99
|
case 2:
|
|
100
|
-
if (!!jsonldFiles_1_1.done) return [3 /*break*/,
|
|
100
|
+
if (!!jsonldFiles_1_1.done) return [3 /*break*/, 12];
|
|
101
101
|
filepath = jsonldFiles_1_1.value;
|
|
102
102
|
console.log('Validating', filepath);
|
|
103
103
|
content = loadFile(filepath);
|
|
104
|
-
nodes = Array.isArray(content) ? content : ('nodes' in content ? content.nodes : [content])
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0: return [4 /*yield*/, contentValidator(content)];
|
|
111
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
112
|
-
}
|
|
113
|
-
}); }); }))];
|
|
104
|
+
nodes = (Array.isArray(content) ? content : ('nodes' in content ? content.nodes : [content]))
|
|
105
|
+
.map(function (node) { return node['@type'] || node.type ? node : null; })
|
|
106
|
+
.filter(Boolean);
|
|
107
|
+
allErrors = [];
|
|
108
|
+
_c.label = 3;
|
|
114
109
|
case 3:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
_c.trys.push([3, 8, 9, 10]);
|
|
111
|
+
nodes_1 = (e_1 = void 0, __values(nodes)), nodes_1_1 = nodes_1.next();
|
|
112
|
+
_c.label = 4;
|
|
113
|
+
case 4:
|
|
114
|
+
if (!!nodes_1_1.done) return [3 /*break*/, 7];
|
|
115
|
+
node = nodes_1_1.value;
|
|
116
|
+
return [4 /*yield*/, contentValidator(node)];
|
|
117
|
+
case 5:
|
|
118
|
+
errors = (_c.sent()).errors;
|
|
119
|
+
allErrors.push(errors);
|
|
120
|
+
_c.label = 6;
|
|
121
|
+
case 6:
|
|
122
|
+
nodes_1_1 = nodes_1.next();
|
|
123
|
+
return [3 /*break*/, 4];
|
|
124
|
+
case 7: return [3 /*break*/, 10];
|
|
125
|
+
case 8:
|
|
126
|
+
e_1_1 = _c.sent();
|
|
127
|
+
e_1 = { error: e_1_1 };
|
|
128
|
+
return [3 /*break*/, 10];
|
|
129
|
+
case 9:
|
|
130
|
+
try {
|
|
131
|
+
if (nodes_1_1 && !nodes_1_1.done && (_b = nodes_1.return)) _b.call(nodes_1);
|
|
132
|
+
}
|
|
133
|
+
finally { if (e_1) throw e_1.error; }
|
|
134
|
+
return [7 /*endfinally*/];
|
|
135
|
+
case 10:
|
|
120
136
|
success = !allErrors.some(function (v) { return v.length; });
|
|
121
137
|
if (!success) {
|
|
122
138
|
results.push({
|
|
@@ -125,22 +141,22 @@ exports.run = function () { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
125
141
|
errors: allErrors
|
|
126
142
|
});
|
|
127
143
|
}
|
|
128
|
-
|
|
129
|
-
case
|
|
144
|
+
_c.label = 11;
|
|
145
|
+
case 11:
|
|
130
146
|
jsonldFiles_1_1 = jsonldFiles_1.next();
|
|
131
147
|
return [3 /*break*/, 2];
|
|
132
|
-
case
|
|
133
|
-
case
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return [3 /*break*/,
|
|
137
|
-
case
|
|
148
|
+
case 12: return [3 /*break*/, 15];
|
|
149
|
+
case 13:
|
|
150
|
+
e_2_1 = _c.sent();
|
|
151
|
+
e_2 = { error: e_2_1 };
|
|
152
|
+
return [3 /*break*/, 15];
|
|
153
|
+
case 14:
|
|
138
154
|
try {
|
|
139
155
|
if (jsonldFiles_1_1 && !jsonldFiles_1_1.done && (_a = jsonldFiles_1.return)) _a.call(jsonldFiles_1);
|
|
140
156
|
}
|
|
141
|
-
finally { if (
|
|
157
|
+
finally { if (e_2) throw e_2.error; }
|
|
142
158
|
return [7 /*endfinally*/];
|
|
143
|
-
case
|
|
159
|
+
case 15:
|
|
144
160
|
if (results.length) {
|
|
145
161
|
throw new Error("Validation errors: " + JSON.stringify(results, null, 2));
|
|
146
162
|
}
|