optolith-database-schema 0.5.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.5.1](https://github.com/elyukai/optolith-database-schema/compare/v0.5.0...v0.5.1) (2022-12-02)
6
+
7
+
8
+ ### Features
9
+
10
+ * explicit verbose error-printing option ([ebf055c](https://github.com/elyukai/optolith-database-schema/commit/ebf055c92302c5cfd80493dff1fd38276d05aa30))
11
+
5
12
  ## [0.5.0](https://github.com/elyukai/optolith-database-schema/compare/v0.4.1...v0.5.0) (2022-12-01)
6
13
 
7
14
 
package/lib/main.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DefinedError } from "ajv";
2
2
  import { TypeMap } from "./config.js";
3
- import { TypeValidationError } from "./validation/schema.js";
3
+ import { TypeValidationResultErrors } from "./validation/schema.js";
4
4
  declare type Result = {
5
5
  tag: "Ok";
6
6
  value: {
@@ -14,5 +14,8 @@ export declare type EntityDirectoryPaths = {
14
14
  [K in keyof TypeMap]: string;
15
15
  };
16
16
  export declare const validate: (entityDirPaths: EntityDirectoryPaths, checkIntegrity: boolean) => Promise<Result>;
17
- export declare const printErrors: (errorsByFile: Record<string, TypeValidationError[]>) => string;
17
+ export declare const printErrors: (errorsByFile: Record<string, TypeValidationResultErrors>, printOptions?: PrintOptions) => string;
18
+ export declare type PrintOptions = {
19
+ verbose?: boolean;
20
+ };
18
21
  export {};
package/lib/main.js CHANGED
@@ -108,12 +108,30 @@ export const validate = async (entityDirPaths, checkIntegrity) => {
108
108
  ]))));
109
109
  return rawResultMapToResult(rawResultMap);
110
110
  };
111
- export const printErrors = (errorsByFile) => Object.entries(errorsByFile)
112
- .flatMap(([filePath, errors]) => errors.map(error => {
113
- const pathSegments = [filePath, ...error.instancePath.split("/").slice(1)];
114
- return [
115
- ...pathSegments.map((segment, i) => `${" ".repeat(i * 2)}in "${segment}":`),
116
- `${" ".repeat(pathSegments.length * 2)}${error.message ?? ""}`
117
- ].join("\n");
118
- }))
119
- .join("\n\n");
111
+ export const printErrors = (errorsByFile, printOptions = {}) => {
112
+ const { verbose = false } = printOptions;
113
+ return Object.entries(errorsByFile)
114
+ .flatMap(([filePath, errors]) => {
115
+ if (verbose) {
116
+ return filterNullable([
117
+ errors.fileNameError ? errorMessageBlock([filePath], errors.fileNameError.message) : undefined,
118
+ ...errors.schemaErrors.map(error => {
119
+ const pathSegments = [filePath, ...error.instancePath.split("/").slice(1)];
120
+ return errorMessageBlock(pathSegments, error.message ?? "");
121
+ })
122
+ ]);
123
+ }
124
+ else {
125
+ return filterNullable([
126
+ errors.fileNameError ? errorMessageBlock([filePath], errors.fileNameError.message) : undefined,
127
+ errors.schemaErrors.length > 0 ? errorMessageBlock([filePath], "does not match schema") : undefined
128
+ ]);
129
+ }
130
+ })
131
+ .join("\n\n");
132
+ };
133
+ const errorMessageBlock = (path, message) => [
134
+ ...path.map((segment, i) => `${" ".repeat(i * 2)}in "${segment}":`),
135
+ `${" ".repeat(path.length * 2)}${message}`
136
+ ].join("\n");
137
+ const filterNullable = (arr) => arr.filter((x) => x != null);
@@ -4,13 +4,16 @@ export declare type FileNameError = {
4
4
  instancePath: string;
5
5
  message: string;
6
6
  };
7
- export declare type TypeValidationError = DefinedError | FileNameError;
8
7
  export declare type TypeValidationResult<T> = {
9
8
  tag: "Ok";
10
9
  value: T;
11
10
  } | {
12
11
  tag: "Error";
13
- errors: TypeValidationError[];
12
+ errors: TypeValidationResultErrors;
13
+ };
14
+ export declare type TypeValidationResultErrors = {
15
+ fileNameError?: FileNameError;
16
+ schemaErrors: DefinedError[];
14
17
  };
15
18
  export declare type TypeValidator<T> = (validator: Ajv, data: unknown, filePath: string) => TypeValidationResult<T>;
16
19
  export declare type TypeValidatorOptions = {
@@ -22,11 +22,13 @@ export const validateSchemaCreator = (importMetaUrl, { ignoreFileNamePattern = f
22
22
  return { tag: "Ok", value: data };
23
23
  }
24
24
  else {
25
- const errors = [
26
- ...(validator.errors ?? []),
27
- ...(!correctFileName ? [fileNameError(fileName)] : [])
28
- ];
29
- return { tag: "Error", errors };
25
+ return {
26
+ tag: "Error",
27
+ errors: {
28
+ fileNameError: correctFileName ? undefined : fileNameError(fileName),
29
+ schemaErrors: validator.errors ?? [],
30
+ }
31
+ };
30
32
  }
31
33
  };
32
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "optolith-database-schema",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Definitions and utilities for the flat-file database of Optolith, a character creation tool for the Pen and Paper RPG “The Dark Eye 5”, and its external integrations into other software.",
5
5
  "keywords": [
6
6
  "tde",