schema-markdown 1.1.5 → 1.1.6
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/lib/parser.js +2 -2
- package/lib/schema.js +4 -26
- package/lib/schemaUtil.js +1 -1
- package/lib/typeModel.js +1 -14
- package/package.json +4 -4
package/lib/parser.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
/** @module lib/parser */
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {validateTypeModelErrors} from './schemaUtil.js';
|
|
7
7
|
|
|
8
8
|
/* eslint-disable prefer-template */
|
|
9
9
|
|
|
@@ -244,7 +244,7 @@ export class SchemaMarkdownParser {
|
|
|
244
244
|
*/
|
|
245
245
|
finalize() {
|
|
246
246
|
// Do the finalization
|
|
247
|
-
for (const [typeName, memberName, errorMsg] of
|
|
247
|
+
for (const [typeName, memberName, errorMsg] of validateTypeModelErrors(this.types)) {
|
|
248
248
|
this.addError(errorMsg, ...this.getFilepos(typeName, memberName));
|
|
249
249
|
}
|
|
250
250
|
|
package/lib/schema.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/** @module lib/schema */
|
|
5
5
|
|
|
6
6
|
import {typeModel} from './typeModel.js';
|
|
7
|
-
import {
|
|
7
|
+
import {validateTypeModelErrors} from './schemaUtil.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -20,7 +20,6 @@ export function getReferencedTypes(types, typeName, referencedTypes = {}) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
// eslint-disable-next-line no-unused-vars
|
|
24
23
|
function getReferencedTypesHelper(types, type, referencedTypes) {
|
|
25
24
|
// Array?
|
|
26
25
|
if ('array' in type) {
|
|
@@ -517,36 +516,15 @@ export function getEnumValues(types, enum_) {
|
|
|
517
516
|
* @returns {Object} The validated, transformed types object
|
|
518
517
|
* @throws {ValidationError} A validation error occurred
|
|
519
518
|
*/
|
|
520
|
-
export function
|
|
519
|
+
export function validateTypeModel(types) {
|
|
521
520
|
// Validate with the type model
|
|
522
|
-
const validatedTypes = validateType(typeModel
|
|
521
|
+
const validatedTypes = validateType(typeModel, 'Types', types);
|
|
523
522
|
|
|
524
523
|
// Do additional type model validation
|
|
525
|
-
const errors =
|
|
524
|
+
const errors = validateTypeModelErrors(validatedTypes);
|
|
526
525
|
if (errors.length) {
|
|
527
526
|
throw new ValidationError(errors.map(([,, message]) => message).join('\n'));
|
|
528
527
|
}
|
|
529
528
|
|
|
530
529
|
return validatedTypes;
|
|
531
530
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* Validate a user type model
|
|
536
|
-
*
|
|
537
|
-
* @param {Object} userTypeModel - The user type model
|
|
538
|
-
* @returns {Object} The validated, transformed type model
|
|
539
|
-
* @throws {ValidationError} A validation error occurred
|
|
540
|
-
*/
|
|
541
|
-
export function validateTypeModel(userTypeModel) {
|
|
542
|
-
// Validate with the type model
|
|
543
|
-
const validatedUserTypeModel = validateType(typeModel.types, 'TypeModel', userTypeModel);
|
|
544
|
-
|
|
545
|
-
// Do additional type model validation
|
|
546
|
-
const errors = validateTypeModelTypesErrors(validatedUserTypeModel.types);
|
|
547
|
-
if (errors.length) {
|
|
548
|
-
throw new ValidationError(errors.map(([,, message]) => message).join('\n'));
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
return validatedUserTypeModel;
|
|
552
|
-
}
|
package/lib/schemaUtil.js
CHANGED
package/lib/typeModel.js
CHANGED
|
@@ -8,16 +8,6 @@ import {SchemaMarkdownParser} from './parser.js';
|
|
|
8
8
|
|
|
9
9
|
// The Schema Markdown type model defined as Schema Markdown
|
|
10
10
|
const typeModelSmd = `\
|
|
11
|
-
# A type model with a title
|
|
12
|
-
struct TypeModel
|
|
13
|
-
|
|
14
|
-
# The type model's title
|
|
15
|
-
string title
|
|
16
|
-
|
|
17
|
-
# The type model
|
|
18
|
-
Types types
|
|
19
|
-
|
|
20
|
-
|
|
21
11
|
# Map of user type name to user type model
|
|
22
12
|
typedef UserType{len > 0} Types
|
|
23
13
|
|
|
@@ -256,7 +246,4 @@ struct ActionURL
|
|
|
256
246
|
/**
|
|
257
247
|
* The Schema Markdown type model
|
|
258
248
|
*/
|
|
259
|
-
export const typeModel =
|
|
260
|
-
'title': 'The Schema Markdown Type Model',
|
|
261
|
-
'types': (new SchemaMarkdownParser(typeModelSmd)).types
|
|
262
|
-
};
|
|
249
|
+
export const typeModel = (new SchemaMarkdownParser(typeModelSmd)).types;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "schema-markdown",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.6",
|
|
5
5
|
"description": "Human-friendly schema definition language and schema validator",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"schema",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"test": "ava -v test/"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"ava": "
|
|
28
|
-
"c8": "~7.
|
|
29
|
-
"eslint": "~8.
|
|
27
|
+
"ava": "~4.2",
|
|
28
|
+
"c8": "~7.11",
|
|
29
|
+
"eslint": "~8.14",
|
|
30
30
|
"jsdoc": "~3.6",
|
|
31
31
|
"jsdom": "~19.0"
|
|
32
32
|
}
|