@hestia-earth/schema-validation 9.3.0 → 9.6.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/validate-jsonld.js +49 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-validation",
3
- "version": "9.3.0",
3
+ "version": "9.6.0",
4
4
  "description": "Hestia Schema Validation",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -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, e_1_1;
87
- var e_1, _a;
88
- return __generator(this, function (_b) {
89
- switch (_b.label) {
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
- _b.label = 1;
94
+ _c.label = 1;
95
95
  case 1:
96
- _b.trys.push([1, 6, 7, 8]);
96
+ _c.trys.push([1, 13, 14, 15]);
97
97
  jsonldFiles_1 = __values(jsonldFiles), jsonldFiles_1_1 = jsonldFiles_1.next();
98
- _b.label = 2;
98
+ _c.label = 2;
99
99
  case 2:
100
- if (!!jsonldFiles_1_1.done) return [3 /*break*/, 5];
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
- return [4 /*yield*/, Promise.all(nodes
106
- .map(function (node) { return node['@type'] || node.type ? node : null; })
107
- .filter(Boolean)
108
- .map(function (content) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
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
- allErrors = (_b.sent())
116
- .map(function (_a) {
117
- var errors = _a.errors;
118
- return errors;
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
- _b.label = 4;
129
- case 4:
144
+ _c.label = 11;
145
+ case 11:
130
146
  jsonldFiles_1_1 = jsonldFiles_1.next();
131
147
  return [3 /*break*/, 2];
132
- case 5: return [3 /*break*/, 8];
133
- case 6:
134
- e_1_1 = _b.sent();
135
- e_1 = { error: e_1_1 };
136
- return [3 /*break*/, 8];
137
- case 7:
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 (e_1) throw e_1.error; }
157
+ finally { if (e_2) throw e_2.error; }
142
158
  return [7 /*endfinally*/];
143
- case 8:
159
+ case 15:
144
160
  if (results.length) {
145
161
  throw new Error("Validation errors: " + JSON.stringify(results, null, 2));
146
162
  }