tsondb 0.21.8 → 0.21.10
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/dist/src/node/index.js
CHANGED
|
@@ -186,6 +186,11 @@ export class TSONDB {
|
|
|
186
186
|
useStyling: true,
|
|
187
187
|
};
|
|
188
188
|
const errors = [];
|
|
189
|
+
const summary = [];
|
|
190
|
+
const debugAndAddToSummary = (message) => {
|
|
191
|
+
debug(message);
|
|
192
|
+
summary.push(message);
|
|
193
|
+
};
|
|
189
194
|
if (!skipStructuralValidation) {
|
|
190
195
|
debug("Checking structural integrity ...");
|
|
191
196
|
const structureErrors = onlyEntities
|
|
@@ -209,7 +214,7 @@ export class TSONDB {
|
|
|
209
214
|
.toSorted((a, b) => a.message.localeCompare(b.message));
|
|
210
215
|
if (structureErrors.length > 0) {
|
|
211
216
|
const errorCount = countErrors(structureErrors);
|
|
212
|
-
|
|
217
|
+
debugAndAddToSummary(`${errorCount.toString()} structural integrity violation${errorCount === 1 ? "" : "s"} found`);
|
|
213
218
|
errors.push(...structureErrors);
|
|
214
219
|
}
|
|
215
220
|
else {
|
|
@@ -243,7 +248,7 @@ export class TSONDB {
|
|
|
243
248
|
.toSorted((a, b) => a.message.localeCompare(b.message));
|
|
244
249
|
if (referenceErrors.length > 0) {
|
|
245
250
|
const errorCount = countErrors(referenceErrors);
|
|
246
|
-
|
|
251
|
+
debugAndAddToSummary(`${errorCount.toString()} referential integrity violation${errorCount === 1 ? "" : "s"} found`);
|
|
247
252
|
errors.push(...referenceErrors);
|
|
248
253
|
}
|
|
249
254
|
else {
|
|
@@ -259,7 +264,7 @@ export class TSONDB {
|
|
|
259
264
|
const uniqueConstraintResult = checkUniqueConstraintsForAllEntities(data, (changedEntities ?? onlyEntities).filter(e => isEntityDecl(e)), instanceOverviewsByEntityName);
|
|
260
265
|
if (isError(uniqueConstraintResult)) {
|
|
261
266
|
const errorCount = countError(uniqueConstraintResult.error);
|
|
262
|
-
|
|
267
|
+
debugAndAddToSummary(`${errorCount.toString()} unique constraint violation${errorCount === 1 ? "" : "s"} found`);
|
|
263
268
|
errors.push(uniqueConstraintResult.error);
|
|
264
269
|
}
|
|
265
270
|
else {
|
|
@@ -269,7 +274,7 @@ export class TSONDB {
|
|
|
269
274
|
const customConstraintResult = checkCustomConstraintsForAllEntities((...args) => getDisplayName(getEntity, this.#locales, data, ...args), (...args) => getDisplayNameWithId(getEntity, this.#locales, data, ...args), (...args) => getInstanceOverview(data.getInstanceContainerOfEntityById.bind(data), data.getAllChildInstanceContainersForParent.bind(data, getEntity), getEntity, this.#locales, args), getEntity, data, entities);
|
|
270
275
|
if (isError(customConstraintResult)) {
|
|
271
276
|
const errorCount = countError(customConstraintResult.error);
|
|
272
|
-
|
|
277
|
+
debugAndAddToSummary(`${errorCount.toString()} custom constraint violation${errorCount === 1 ? "" : "s"} found`);
|
|
273
278
|
errors.push(customConstraintResult.error);
|
|
274
279
|
}
|
|
275
280
|
else {
|
|
@@ -277,7 +282,7 @@ export class TSONDB {
|
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
284
|
else {
|
|
280
|
-
|
|
285
|
+
debugAndAddToSummary("Skipping further checks due to previous structural integrity errors");
|
|
281
286
|
}
|
|
282
287
|
if (logToConsole) {
|
|
283
288
|
console.log(`${data.totalSize.toString()} instance${data.totalSize === 1 ? "" : "s"} checked`);
|
|
@@ -286,7 +291,14 @@ export class TSONDB {
|
|
|
286
291
|
}
|
|
287
292
|
else {
|
|
288
293
|
const errorCount = countErrors(errors);
|
|
289
|
-
console.error(styleText("red", `${
|
|
294
|
+
console.error(styleText("red", `${errors.map(err => getErrorMessageForDisplay(err)).join("\n\n")}\n`, {
|
|
295
|
+
stream: stderr,
|
|
296
|
+
}));
|
|
297
|
+
console.error(styleText(["red", "bold"], "Summary", { stream: stderr }));
|
|
298
|
+
console.error(styleText("red", [
|
|
299
|
+
`${errorCount.toString()} validation error${errorCount === 1 ? "" : "s"} found`,
|
|
300
|
+
...summary,
|
|
301
|
+
].join("\n"), { stream: stderr }));
|
|
290
302
|
}
|
|
291
303
|
}
|
|
292
304
|
return errors;
|
|
@@ -35,6 +35,8 @@ export const reduceNodes = (reducer, nodes, options = {}) => {
|
|
|
35
35
|
else {
|
|
36
36
|
return { results: reducer(parentNodes, node, collectedResults), reducedDecls };
|
|
37
37
|
}
|
|
38
|
+
case NodeKind.NestedEntityMapType:
|
|
39
|
+
return reduceNodeTree([...parentNodes, node], node.type.value, reducer(parentNodes, node, collectedResults), reducedDecls);
|
|
38
40
|
case NodeKind.BooleanType:
|
|
39
41
|
case NodeKind.DateType:
|
|
40
42
|
case NodeKind.FloatType:
|
|
@@ -42,7 +44,6 @@ export const reduceNodes = (reducer, nodes, options = {}) => {
|
|
|
42
44
|
case NodeKind.StringType:
|
|
43
45
|
case NodeKind.TypeArgumentType:
|
|
44
46
|
case NodeKind.ReferenceIdentifierType:
|
|
45
|
-
case NodeKind.NestedEntityMapType:
|
|
46
47
|
case NodeKind.TypeParameter:
|
|
47
48
|
case NodeKind.TranslationObjectType:
|
|
48
49
|
return { results: reducer(parentNodes, node, collectedResults), reducedDecls };
|