optolith-database-schema 0.5.0 → 0.5.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.
- package/CHANGELOG.md +14 -0
- package/lib/main.d.ts +6 -4
- package/lib/main.js +28 -10
- package/lib/validation/schema.d.ts +5 -2
- package/lib/validation/schema.js +7 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.2](https://github.com/elyukai/optolith-database-schema/compare/v0.5.1...v0.5.2) (2022-12-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* validation error output type did not match type for error printing ([709f2f4](https://github.com/elyukai/optolith-database-schema/commit/709f2f46a68ff438cd158defddf93f508871eef9))
|
|
11
|
+
|
|
12
|
+
### [0.5.1](https://github.com/elyukai/optolith-database-schema/compare/v0.5.0...v0.5.1) (2022-12-02)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* explicit verbose error-printing option ([ebf055c](https://github.com/elyukai/optolith-database-schema/commit/ebf055c92302c5cfd80493dff1fd38276d05aa30))
|
|
18
|
+
|
|
5
19
|
## [0.5.0](https://github.com/elyukai/optolith-database-schema/compare/v0.4.1...v0.5.0) (2022-12-01)
|
|
6
20
|
|
|
7
21
|
|
package/lib/main.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DefinedError } from "ajv";
|
|
2
1
|
import { TypeMap } from "./config.js";
|
|
3
|
-
import {
|
|
2
|
+
import { TypeValidationResultErrors } from "./validation/schema.js";
|
|
4
3
|
declare type Result = {
|
|
5
4
|
tag: "Ok";
|
|
6
5
|
value: {
|
|
@@ -8,11 +7,14 @@ declare type Result = {
|
|
|
8
7
|
};
|
|
9
8
|
} | {
|
|
10
9
|
tag: "Error";
|
|
11
|
-
errors: Record<string,
|
|
10
|
+
errors: Record<string, TypeValidationResultErrors>;
|
|
12
11
|
};
|
|
13
12
|
export declare type EntityDirectoryPaths = {
|
|
14
13
|
[K in keyof TypeMap]: string;
|
|
15
14
|
};
|
|
16
15
|
export declare const validate: (entityDirPaths: EntityDirectoryPaths, checkIntegrity: boolean) => Promise<Result>;
|
|
17
|
-
export declare const printErrors: (errorsByFile: Record<string,
|
|
16
|
+
export declare const printErrors: (errorsByFile: Record<string, TypeValidationResultErrors>, printOptions?: PrintOptions) => string;
|
|
17
|
+
export declare type PrintOptions = {
|
|
18
|
+
verbose?: boolean;
|
|
19
|
+
};
|
|
18
20
|
export {};
|
package/lib/main.js
CHANGED
|
@@ -87,7 +87,7 @@ const rawResultMapToResult = (rawResultMap) => Object.entries(rawResultMap).redu
|
|
|
87
87
|
tag: "Error",
|
|
88
88
|
errors: {
|
|
89
89
|
...outerResult.errors,
|
|
90
|
-
[filePath]:
|
|
90
|
+
[filePath]: fileResult.errors
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
93
|
}
|
|
@@ -108,12 +108,30 @@ export const validate = async (entityDirPaths, checkIntegrity) => {
|
|
|
108
108
|
]))));
|
|
109
109
|
return rawResultMapToResult(rawResultMap);
|
|
110
110
|
};
|
|
111
|
-
export const printErrors = (errorsByFile) =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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:
|
|
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 = {
|
package/lib/validation/schema.js
CHANGED
|
@@ -22,11 +22,13 @@ export const validateSchemaCreator = (importMetaUrl, { ignoreFileNamePattern = f
|
|
|
22
22
|
return { tag: "Ok", value: data };
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|