schema-markdown 1.1.5 → 1.2.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/lib/schema.js CHANGED
@@ -4,23 +4,22 @@
4
4
  /** @module lib/schema */
5
5
 
6
6
  import {typeModel} from './typeModel.js';
7
- import {validateTypeModelTypesErrors} from './schemaUtil.js';
7
+ import {validateTypeModelErrors} from './schemaUtil.js';
8
8
 
9
9
 
10
10
  /**
11
11
  * Get a user type's referenced type model
12
12
  *
13
- * @param {Object} types - The map of user type name to user type model
13
+ * @param {Object} types - The [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
14
14
  * @param {string} typeName - The type name
15
15
  * @param {Object} [referencedTypes=null] - Optional map of referenced user type name to user type model
16
- * @returns {Object}
16
+ * @returns {Object} The referenced [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
17
17
  */
18
18
  export function getReferencedTypes(types, typeName, referencedTypes = {}) {
19
19
  return getReferencedTypesHelper(types, {'user': 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) {
@@ -105,7 +104,7 @@ export class ValidationError extends Error {
105
104
  /**
106
105
  * Schema Markdown type model validation error constructor
107
106
  *
108
- * @param {string} [memberFqn=null] - Optional fully-qualified member name
107
+ * @param {string} [memberFqn=null] - The fully-qualified member name
109
108
  */
110
109
  constructor(message, memberFqn = null) {
111
110
  super(message);
@@ -118,12 +117,12 @@ export class ValidationError extends Error {
118
117
  * Type-validate a value using a user type model. Container values are duplicated since some member types are
119
118
  * transformed during validation.
120
119
  *
121
- * @param {Object} types - The map of user type name to user type model
120
+ * @param {Object} types - The [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
122
121
  * @param {string} typeName - The type name
123
122
  * @param {Object} value - The value object to validate
124
- * @param {string} [memberFqn=null] - Optional fully-qualified member name
123
+ * @param {?string} [memberFqn=null] - The fully-qualified member name
125
124
  * @returns {Object} The validated, transformed value object
126
- * @throws {ValidationError} A validation error occurred
125
+ * @throws [ValidationError]{@link module:lib/schema.ValidationError}
127
126
  */
128
127
  export function validateType(types, typeName, value, memberFqn = null) {
129
128
  if (!(typeName in types)) {
@@ -449,9 +448,10 @@ function validateAttr(type, attr, value, memberFqn) {
449
448
  /**
450
449
  * Get the struct's members (inherited members first)
451
450
  *
452
- * @param {Object} types - The map of user type name to user type model
453
- * @param {Object} struct - The struct model
454
- * @returns {Array<Object>} The array of struct member models
451
+ * @param {Object} types - The [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
452
+ * @param {Object} struct - The [struct model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Struct'}
453
+ * @returns {Array<Object>} The array of
454
+ * [struct member models]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='StructMember'}
455
455
  */
456
456
  export function getStructMembers(types, struct) {
457
457
  // No base structs?
@@ -481,9 +481,10 @@ export function getStructMembers(types, struct) {
481
481
  /**
482
482
  * Get the enum's values (inherited values first)
483
483
  *
484
- * @param {Object} types - The map of user type name to user type model
485
- * @param {Object} enum_ - The enum model
486
- * @returns {Array<Object>} The array of enum value models
484
+ * @param {Object} types - The [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
485
+ * @param {Object} enum_ - The [enum model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Enum'}
486
+ * @returns {Array<Object>} The array of
487
+ * [enum value models]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='EnumValue'}
487
488
  */
488
489
  export function getEnumValues(types, enum_) {
489
490
  // No base enums?
@@ -513,40 +514,19 @@ export function getEnumValues(types, enum_) {
513
514
  /**
514
515
  * Validate a type model's types object
515
516
  *
516
- * @param {Object} types - The map of user type name to user type model
517
- * @returns {Object} The validated, transformed types object
518
- * @throws {ValidationError} A validation error occurred
517
+ * @param {Object} types - The [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
518
+ * @returns {Object} The validated [type model]{@link https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types'}
519
+ * @throws [ValidationError]{@link module:lib/schema.ValidationError}
519
520
  */
520
- export function validateTypeModelTypes(types) {
521
+ export function validateTypeModel(types) {
521
522
  // Validate with the type model
522
- const validatedTypes = validateType(typeModel.types, 'Types', types);
523
+ const validatedTypes = validateType(typeModel, 'Types', types);
523
524
 
524
525
  // Do additional type model validation
525
- const errors = validateTypeModelTypesErrors(validatedTypes);
526
+ const errors = validateTypeModelErrors(validatedTypes);
526
527
  if (errors.length) {
527
528
  throw new ValidationError(errors.map(([,, message]) => message).join('\n'));
528
529
  }
529
530
 
530
531
  return validatedTypes;
531
532
  }
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
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * @ignore
12
12
  */
13
- export function validateTypeModelTypesErrors(types) {
13
+ export function validateTypeModelErrors(types) {
14
14
  const errors = [];
15
15
 
16
16
  // Check each user type
package/lib/typeModel.js CHANGED
@@ -3,21 +3,13 @@
3
3
 
4
4
  /** @module lib/typeModel */
5
5
 
6
- import {SchemaMarkdownParser} from './parser.js';
7
-
8
-
9
- // The Schema Markdown type model defined as Schema Markdown
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
6
+ import {parseSchemaMarkdown} from './parser.js';
19
7
 
20
8
 
9
+ /**
10
+ * The Schema Markdown type model
11
+ */
12
+ export const typeModel = parseSchemaMarkdown(`\
21
13
  # Map of user type name to user type model
22
14
  typedef UserType{len > 0} Types
23
15
 
@@ -250,13 +242,4 @@ struct ActionURL
250
242
 
251
243
  # The URL path. If not provided, uses the default URL path of "/<actionName>".
252
244
  optional string path
253
- `;
254
-
255
-
256
- /**
257
- * The Schema Markdown type model
258
- */
259
- export const typeModel = {
260
- 'title': 'The Schema Markdown Type Model',
261
- 'types': (new SchemaMarkdownParser(typeModelSmd)).types
262
- };
245
+ `);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "schema-markdown",
4
- "version": "1.1.5",
5
- "description": "Human-friendly schema definition language and schema validator",
4
+ "version": "1.2.1",
5
+ "description": "A schema definition and validation library",
6
6
  "keywords": [
7
7
  "schema",
8
8
  "definition",
@@ -24,10 +24,10 @@
24
24
  "test": "ava -v test/"
25
25
  },
26
26
  "devDependencies": {
27
- "ava": "^4.0.0-rc.1",
28
- "c8": "~7.10",
29
- "eslint": "~8.4",
27
+ "ava": "~4.3",
28
+ "c8": "~7.12",
29
+ "eslint": "~8.21",
30
30
  "jsdoc": "~3.6",
31
- "jsdom": "~19.0"
31
+ "jsdom": "~20.0"
32
32
  }
33
33
  }