tsondb 0.13.0 → 0.13.2

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.
@@ -9,7 +9,7 @@ import { createValidationContext } from "./schema/Node.js";
9
9
  import { getEntities } from "./schema/Schema.js";
10
10
  import { createServer } from "./server/index.js";
11
11
  import { asyncForEachInstanceInDatabaseInMemory, createDatabaseInMemory, getInstancesOfEntityFromDatabaseInMemory, } from "./utils/databaseInMemory.js";
12
- import { countErrors, getErrorMessageForDisplay, wrapErrorsIfAny } from "./utils/error.js";
12
+ import { countError, countErrors, getErrorMessageForDisplay, wrapErrorsIfAny, } from "./utils/error.js";
13
13
  import { getFileNameForId, writeInstance } from "./utils/files.js";
14
14
  import { checkUniqueConstraintsForAllEntities } from "./utils/unique.js";
15
15
  const debug = Debug("tsondb:jsapi");
@@ -40,7 +40,8 @@ const _validate = (dataRootPath, entities, databaseInMemory, options = {}) => {
40
40
  .flatMap(entity => parallelizeErrors(getInstancesOfEntityFromDatabaseInMemory(databaseInMemory, entity.name).map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateEntityDecl(validationContext, [], entity, instance.content)))))
41
41
  .toSorted((a, b) => a.message.localeCompare(b.message));
42
42
  if (errors.length > 0) {
43
- debug(`${errors.length.toString()} structural integrity violation${errors.length === 1 ? "" : "s"} found`);
43
+ const errorCount = countErrors(errors);
44
+ debug(`${errorCount.toString()} structural integrity violation${errorCount === 1 ? "" : "s"} found`);
44
45
  }
45
46
  else {
46
47
  debug("No structural integrity violations found");
@@ -49,7 +50,8 @@ const _validate = (dataRootPath, entities, databaseInMemory, options = {}) => {
49
50
  debug("Checking unique constraints ...");
50
51
  const constraintResult = checkUniqueConstraintsForAllEntities(databaseInMemory, entities);
51
52
  if (isError(constraintResult)) {
52
- debug(`${constraintResult.error.errors.length.toString()} unique constraint violation${constraintResult.error.errors.length === 1 ? "" : "s"} found`);
53
+ const errorCount = countError(constraintResult.error);
54
+ debug(`${errorCount.toString()} unique constraint violation${errorCount === 1 ? "" : "s"} found`);
53
55
  errors.push(constraintResult.error);
54
56
  }
55
57
  else {
@@ -60,11 +62,14 @@ const _validate = (dataRootPath, entities, databaseInMemory, options = {}) => {
60
62
  debug("Skipping unique constraint checks due to previous structural integrity errors");
61
63
  }
62
64
  if (errors.length === 0) {
63
- debug("All entities are valid");
65
+ console.log("All entities are valid");
66
+ return true;
64
67
  }
65
68
  else {
66
- console.error(styleText("red", "\n" + errors.map(err => getErrorMessageForDisplay(err)).join("\n\n")));
67
- throw new Error(`Validation failed with ${countErrors(errors).toString()} errors`);
69
+ const errorCount = countErrors(errors);
70
+ console.error(`${errorCount.toString()} validation error${errorCount === 1 ? "" : "s"} found\n\n${errors.map(err => getErrorMessageForDisplay(err)).join("\n\n")}`);
71
+ process.exitCode = 1;
72
+ return false;
68
73
  }
69
74
  };
70
75
  export const validate = async (schema, dataRootPath, options) => {
@@ -96,8 +101,13 @@ export const generateValidateAndServe = async (schema, outputs, dataRootPath, de
96
101
  const entities = getEntities(schema);
97
102
  await prepareFolders(dataRootPath, entities);
98
103
  const databaseInMemory = await createDatabaseInMemory(dataRootPath, entities);
99
- _validate(dataRootPath, entities, databaseInMemory, validationOptions);
100
- await createServer(schema, dataRootPath, databaseInMemory, defaultLocales, homeLayoutSections, serverOptions, validationOptions, customStylesheetPath);
104
+ const isValid = _validate(dataRootPath, entities, databaseInMemory, validationOptions);
105
+ if (isValid) {
106
+ await createServer(schema, dataRootPath, databaseInMemory, defaultLocales, homeLayoutSections, serverOptions, validationOptions, customStylesheetPath);
107
+ }
108
+ else {
109
+ console.error("Not starting server due to invalid database");
110
+ }
101
111
  };
102
112
  export const format = async (schema, dataRootPath) => {
103
113
  const entities = getEntities(schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",