schema-markdown 1.1.3 → 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 +25 -17
- 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
|
|
|
@@ -43,7 +43,7 @@ const RE_PART_TYPEDEF =
|
|
|
43
43
|
const RE_TYPEDEF = new RegExp('^typedef\\s+' + RE_PART_TYPEDEF + '\\s*$');
|
|
44
44
|
const RE_MEMBER = new RegExp('^\\s+(?<optional>optional\\s+)?' + RE_PART_TYPEDEF + '\\s*$');
|
|
45
45
|
const RE_VALUE = new RegExp('^\\s+(?<id>' + RE_PART_ID + ')\\s*$');
|
|
46
|
-
const RE_VALUE_QUOTED =
|
|
46
|
+
const RE_VALUE_QUOTED = /^\s+"(?<id>.*?)"\s*$/;
|
|
47
47
|
const RE_URL = /^\s+(?<method>[A-Za-z]+|\*)(?:\s+(?<path>\/[^\s]*))?/;
|
|
48
48
|
|
|
49
49
|
|
|
@@ -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
|
|
|
@@ -321,38 +321,46 @@ export class SchemaMarkdownParser {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
// Match syntax
|
|
324
|
-
let
|
|
324
|
+
let matchName = 'comment';
|
|
325
|
+
let match = line.match(RE_COMMENT);
|
|
325
326
|
if (match === null) {
|
|
326
|
-
|
|
327
|
+
matchName = 'group';
|
|
328
|
+
match = line.match(RE_GROUP);
|
|
327
329
|
}
|
|
328
330
|
if (match === null) {
|
|
329
|
-
|
|
331
|
+
matchName = 'action';
|
|
332
|
+
match = line.match(RE_ACTION);
|
|
330
333
|
}
|
|
331
334
|
if (match === null) {
|
|
332
|
-
|
|
335
|
+
matchName = 'definition';
|
|
336
|
+
match = line.match(RE_DEFINITION);
|
|
333
337
|
}
|
|
334
338
|
if (match === null && action !== null) {
|
|
335
|
-
|
|
339
|
+
matchName = 'section';
|
|
340
|
+
match = line.match(RE_SECTION);
|
|
336
341
|
}
|
|
337
342
|
if (match === null && action !== null) {
|
|
338
|
-
|
|
343
|
+
matchName = 'section_plain';
|
|
344
|
+
match = line.match(RE_SECTION_PLAIN);
|
|
339
345
|
}
|
|
340
346
|
if (match === null && userType !== null && 'enum' in userType) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
[matchName, match] = ['value', line.match(RE_VALUE_QUOTED)];
|
|
347
|
+
matchName = 'value';
|
|
348
|
+
match = line.match(RE_VALUE);
|
|
349
|
+
if (match === null) {
|
|
350
|
+
match = line.match(RE_VALUE_QUOTED);
|
|
346
351
|
}
|
|
347
352
|
}
|
|
348
353
|
if (match === null && userType !== null && 'struct' in userType) {
|
|
349
|
-
|
|
354
|
+
matchName = 'member';
|
|
355
|
+
match = line.match(RE_MEMBER);
|
|
350
356
|
}
|
|
351
357
|
if (match === null && urls !== null) {
|
|
352
|
-
|
|
358
|
+
matchName = 'urls';
|
|
359
|
+
match = line.match(RE_URL);
|
|
353
360
|
}
|
|
354
361
|
if (match === null) {
|
|
355
|
-
|
|
362
|
+
matchName = 'typedef';
|
|
363
|
+
match = line.match(RE_TYPEDEF);
|
|
356
364
|
}
|
|
357
365
|
if (match === null) {
|
|
358
366
|
matchName = null;
|
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
|
}
|