@stxt-lang/core 0.5.1 → 0.5.3

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.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/out/all.d.ts +1 -0
  4. package/out/all.js +6 -4
  5. package/out/core/Constants.d.ts +8 -0
  6. package/out/core/Constants.js +8 -0
  7. package/out/core/Line.d.ts +20 -0
  8. package/out/core/Line.js +15 -0
  9. package/out/core/LineParser.d.ts +17 -0
  10. package/out/core/LineParser.js +27 -10
  11. package/out/core/NameNamespace.d.ts +9 -0
  12. package/out/core/NameNamespace.js +9 -0
  13. package/out/core/NameNamespaceParser.d.ts +11 -0
  14. package/out/core/NameNamespaceParser.js +16 -5
  15. package/out/core/NamespaceValidator.d.ts +18 -0
  16. package/out/core/NamespaceValidator.js +18 -0
  17. package/out/core/Node.d.ts +55 -0
  18. package/out/core/Node.js +56 -1
  19. package/out/core/NodeCreator.d.ts +11 -0
  20. package/out/core/NodeCreator.js +14 -3
  21. package/out/core/ParseResult.d.ts +26 -0
  22. package/out/core/ParseResult.js +26 -0
  23. package/out/core/Parser.d.ts +31 -0
  24. package/out/core/Parser.js +50 -19
  25. package/out/core/StringUtils.d.ts +31 -0
  26. package/out/core/StringUtils.js +40 -9
  27. package/out/exceptions/ParseException.d.ts +14 -0
  28. package/out/exceptions/ParseException.js +12 -0
  29. package/out/exceptions/RuntimeException.d.ts +14 -0
  30. package/out/exceptions/RuntimeException.js +13 -0
  31. package/out/exceptions/ValidationException.d.ts +8 -0
  32. package/out/exceptions/ValidationException.js +8 -0
  33. package/out/processors/Observer.d.ts +29 -0
  34. package/out/processors/Validator.d.ts +9 -0
  35. package/out/runtime/ConditionalValidator.d.ts +15 -0
  36. package/out/runtime/ConditionalValidator.js +16 -2
  37. package/out/runtime/NodeWriter.d.ts +18 -0
  38. package/out/runtime/NodeWriter.js +18 -0
  39. package/out/runtime/UnifiedSchemaProvider.d.ts +23 -5
  40. package/out/runtime/UnifiedSchemaProvider.js +28 -10
  41. package/out/schema/ChildDefinition.d.ts +18 -0
  42. package/out/schema/ChildDefinition.js +18 -0
  43. package/out/schema/NodeDefinition.d.ts +44 -0
  44. package/out/schema/NodeDefinition.js +47 -3
  45. package/out/schema/Schema.d.ts +26 -0
  46. package/out/schema/Schema.js +26 -1
  47. package/out/schema/SchemaParser.d.ts +7 -0
  48. package/out/schema/SchemaParser.js +26 -16
  49. package/out/schema/SchemaProvider.d.ts +7 -0
  50. package/out/schema/SchemaProviderMemory.d.ts +27 -0
  51. package/out/schema/SchemaProviderMemory.js +27 -0
  52. package/out/schema/SchemaProviderMeta.d.ts +16 -0
  53. package/out/schema/SchemaProviderMeta.js +78 -62
  54. package/out/schema/SchemaValidator.d.ts +20 -0
  55. package/out/schema/SchemaValidator.js +27 -7
  56. package/out/schema/Type.d.ts +9 -0
  57. package/out/schema/TypeRegistry.d.ts +13 -0
  58. package/out/schema/TypeRegistry.js +18 -5
  59. package/out/schema/type/BASE64.d.ts +1 -0
  60. package/out/schema/type/BASE64.js +5 -4
  61. package/out/schema/type/BINARY.d.ts +1 -0
  62. package/out/schema/type/BINARY.js +2 -1
  63. package/out/schema/type/BLOCK.d.ts +1 -0
  64. package/out/schema/type/BLOCK.js +2 -1
  65. package/out/schema/type/BOOLEAN.d.ts +1 -0
  66. package/out/schema/type/BOOLEAN.js +1 -0
  67. package/out/schema/type/DATE.d.ts +1 -0
  68. package/out/schema/type/DATE.js +1 -0
  69. package/out/schema/type/EMAIL.d.ts +1 -0
  70. package/out/schema/type/EMAIL.js +1 -0
  71. package/out/schema/type/ENUM.d.ts +1 -0
  72. package/out/schema/type/ENUM.js +2 -1
  73. package/out/schema/type/GROUP.d.ts +1 -0
  74. package/out/schema/type/GROUP.js +2 -1
  75. package/out/schema/type/HEXADECIMAL.d.ts +1 -0
  76. package/out/schema/type/HEXADECIMAL.js +2 -1
  77. package/out/schema/type/INLINE.d.ts +1 -0
  78. package/out/schema/type/INLINE.js +2 -1
  79. package/out/schema/type/INTEGER.d.ts +1 -0
  80. package/out/schema/type/INTEGER.js +1 -0
  81. package/out/schema/type/MARKDOWN.d.ts +4 -0
  82. package/out/schema/type/MARKDOWN.js +4 -2
  83. package/out/schema/type/NATURAL.d.ts +1 -0
  84. package/out/schema/type/NATURAL.js +1 -0
  85. package/out/schema/type/NUMBER.d.ts +1 -0
  86. package/out/schema/type/NUMBER.js +1 -0
  87. package/out/schema/type/TEXT.d.ts +1 -0
  88. package/out/schema/type/TEXT.js +1 -0
  89. package/out/schema/type/TIME.d.ts +1 -0
  90. package/out/schema/type/TIME.js +1 -0
  91. package/out/schema/type/TIMESTAMP.d.ts +1 -0
  92. package/out/schema/type/TIMESTAMP.js +1 -0
  93. package/out/schema/type/URL.d.ts +1 -0
  94. package/out/schema/type/URL.js +2 -1
  95. package/out/schema/type/UUID.d.ts +1 -0
  96. package/out/schema/type/UUID.js +1 -0
  97. package/out/schema/type/binaryValue.d.ts +9 -0
  98. package/out/schema/type/binaryValue.js +9 -3
  99. package/out/schema/type/regexType.d.ts +8 -0
  100. package/out/schema/type/regexType.js +9 -1
  101. package/out/template/ChildLine.d.ts +14 -0
  102. package/out/template/ChildLine.js +14 -0
  103. package/out/template/ChildLineParser.d.ts +10 -0
  104. package/out/template/ChildLineParser.js +17 -8
  105. package/out/template/MetaTemplateSchemaProvider.d.ts +16 -0
  106. package/out/template/MetaTemplateSchemaProvider.js +22 -6
  107. package/out/template/TemplateParser.d.ts +8 -0
  108. package/out/template/TemplateParser.js +49 -39
  109. package/out/template/TemplateSchemaProviderMemory.d.ts +18 -0
  110. package/out/template/TemplateSchemaProviderMemory.js +21 -3
  111. package/package.json +60 -45
  112. package/out/all.js.map +0 -1
  113. package/out/core/Constants.js.map +0 -1
  114. package/out/core/Line.js.map +0 -1
  115. package/out/core/LineParser.js.map +0 -1
  116. package/out/core/NameNamespace.js.map +0 -1
  117. package/out/core/NameNamespaceParser.js.map +0 -1
  118. package/out/core/NamespaceValidator.js.map +0 -1
  119. package/out/core/Node.js.map +0 -1
  120. package/out/core/NodeCreator.js.map +0 -1
  121. package/out/core/ParseResult.js.map +0 -1
  122. package/out/core/Parser.js.map +0 -1
  123. package/out/core/StringUtils.js.map +0 -1
  124. package/out/exceptions/ParseException.js.map +0 -1
  125. package/out/exceptions/RuntimeException.js.map +0 -1
  126. package/out/exceptions/ValidationException.js.map +0 -1
  127. package/out/processors/Observer.js.map +0 -1
  128. package/out/processors/Validator.js.map +0 -1
  129. package/out/runtime/ConditionalValidator.js.map +0 -1
  130. package/out/runtime/NodeWriter.js.map +0 -1
  131. package/out/runtime/UnifiedSchemaProvider.js.map +0 -1
  132. package/out/schema/ChildDefinition.js.map +0 -1
  133. package/out/schema/NodeDefinition.js.map +0 -1
  134. package/out/schema/Schema.js.map +0 -1
  135. package/out/schema/SchemaParser.js.map +0 -1
  136. package/out/schema/SchemaProvider.js.map +0 -1
  137. package/out/schema/SchemaProviderMemory.js.map +0 -1
  138. package/out/schema/SchemaProviderMeta.js.map +0 -1
  139. package/out/schema/SchemaValidator.js.map +0 -1
  140. package/out/schema/Type.js.map +0 -1
  141. package/out/schema/TypeRegistry.js.map +0 -1
  142. package/out/schema/type/BASE64.js.map +0 -1
  143. package/out/schema/type/BINARY.js.map +0 -1
  144. package/out/schema/type/BLOCK.js.map +0 -1
  145. package/out/schema/type/BOOLEAN.js.map +0 -1
  146. package/out/schema/type/DATE.js.map +0 -1
  147. package/out/schema/type/EMAIL.js.map +0 -1
  148. package/out/schema/type/ENUM.js.map +0 -1
  149. package/out/schema/type/GROUP.js.map +0 -1
  150. package/out/schema/type/HEXADECIMAL.js.map +0 -1
  151. package/out/schema/type/INLINE.js.map +0 -1
  152. package/out/schema/type/INTEGER.js.map +0 -1
  153. package/out/schema/type/MARKDOWN.js.map +0 -1
  154. package/out/schema/type/NATURAL.js.map +0 -1
  155. package/out/schema/type/NUMBER.js.map +0 -1
  156. package/out/schema/type/TEXT.js.map +0 -1
  157. package/out/schema/type/TIME.js.map +0 -1
  158. package/out/schema/type/TIMESTAMP.js.map +0 -1
  159. package/out/schema/type/URL.js.map +0 -1
  160. package/out/schema/type/UUID.js.map +0 -1
  161. package/out/schema/type/binaryValue.js.map +0 -1
  162. package/out/schema/type/regexType.js.map +0 -1
  163. package/out/template/ChildLine.js.map +0 -1
  164. package/out/template/ChildLineParser.js.map +0 -1
  165. package/out/template/MetaTemplateSchemaProvider.js.map +0 -1
  166. package/out/template/TemplateParser.js.map +0 -1
  167. package/out/template/TemplateSchemaProviderMemory.js.map +0 -1
@@ -6,7 +6,16 @@ const Parser_1 = require("../core/Parser");
6
6
  const ValidationException_1 = require("../exceptions/ValidationException");
7
7
  const RuntimeException_1 = require("../exceptions/RuntimeException");
8
8
  const SchemaParser_1 = require("./SchemaParser");
9
+ /**
10
+ * {@link SchemaProvider} that defines in code the meta-schema of the schema language itself
11
+ * (`@stxt.schema`), so that a loaded schema can validate itself.
12
+ */
9
13
  class SchemaProviderMeta {
14
+ /**
15
+ * Parses the meta-schema and keeps it ready to be served.
16
+ *
17
+ * @throws ValidationException with code `META_SCHEMA_INVALID` if the meta-schema does not produce exactly one document.
18
+ */
10
19
  constructor() {
11
20
  const parser = new Parser_1.Parser();
12
21
  const nodes = parser.parse(SchemaProviderMeta.META_TEXT);
@@ -15,6 +24,13 @@ class SchemaProviderMeta {
15
24
  }
16
25
  this.meta = (0, SchemaParser_1.transformNodeToSchema)(nodes[0]);
17
26
  }
27
+ /**
28
+ * Serves the meta-schema of the schema language.
29
+ *
30
+ * @param namespace namespace whose schema is wanted; only `@stxt.schema` is served.
31
+ * @returns the meta-schema of the schema language.
32
+ * @throws RuntimeException with code `RESOURCE_NOT_FOUND` if any other namespace is asked for.
33
+ */
18
34
  getSchema(namespace) {
19
35
  if (namespace !== Schema_1.Schema.SCHEMA_NAMESPACE) {
20
36
  throw new RuntimeException_1.RuntimeException("RESOURCE_NOT_FOUND", `Not found '${namespace}' in namespace: ${Schema_1.Schema.SCHEMA_NAMESPACE}`);
@@ -26,67 +42,67 @@ class SchemaProviderMeta {
26
42
  }
27
43
  }
28
44
  exports.SchemaProviderMeta = SchemaProviderMeta;
29
- SchemaProviderMeta.META_TEXT = `Schema (@stxt.schema): @stxt.schema
30
- Node: Schema
31
- Children:
32
- Child: Description
33
- Max: 1
34
- Child: Node
35
- Min: 1
36
- Node: Node
37
- Children:
38
- Child: Type
39
- Max: 1
40
- Child: Children
41
- Max: 1
42
- Child: Description
43
- Max: 1
44
- Child: Values
45
- Max: 1
46
- Node: Children
47
- Type: GROUP
48
- Children:
49
- Child: Child
50
- Min: 1
51
- Node: Description
52
- Type: TEXT
53
- Node: Child
54
- Children:
55
- Child: Min
56
- Max: 1
57
- Child: Max
58
- Max: 1
59
- Node: Min
60
- Type: NATURAL
61
- Node: Max
62
- Type: NATURAL
63
- Node: Type
64
- Type: ENUM
65
- Values:
66
- Value: INLINE
67
- Value: BLOCK
68
- Value: TEXT
69
- Value: BOOLEAN
70
- Value: URL
71
- Value: INTEGER
72
- Value: NATURAL
73
- Value: NUMBER
74
- Value: DATE
75
- Value: TIME
76
- Value: TIMESTAMP
77
- Value: UUID
78
- Value: EMAIL
79
- Value: HEXADECIMAL
80
- Value: BINARY
81
- Value: BASE64
82
- Value: GROUP
83
- Value: ENUM
84
- Value: MARKDOWN
85
- Node: Values
86
- Type: GROUP
87
- Children:
88
- Child: Value
89
- Min: 1
90
- Node: Value
45
+ SchemaProviderMeta.META_TEXT = `Schema (@stxt.schema): @stxt.schema
46
+ Node: Schema
47
+ Children:
48
+ Child: Description
49
+ Max: 1
50
+ Child: Node
51
+ Min: 1
52
+ Node: Node
53
+ Children:
54
+ Child: Type
55
+ Max: 1
56
+ Child: Children
57
+ Max: 1
58
+ Child: Description
59
+ Max: 1
60
+ Child: Values
61
+ Max: 1
62
+ Node: Children
63
+ Type: GROUP
64
+ Children:
65
+ Child: Child
66
+ Min: 1
67
+ Node: Description
68
+ Type: TEXT
69
+ Node: Child
70
+ Children:
71
+ Child: Min
72
+ Max: 1
73
+ Child: Max
74
+ Max: 1
75
+ Node: Min
76
+ Type: NATURAL
77
+ Node: Max
78
+ Type: NATURAL
79
+ Node: Type
80
+ Type: ENUM
81
+ Values:
82
+ Value: INLINE
83
+ Value: BLOCK
84
+ Value: TEXT
85
+ Value: BOOLEAN
86
+ Value: URL
87
+ Value: INTEGER
88
+ Value: NATURAL
89
+ Value: NUMBER
90
+ Value: DATE
91
+ Value: TIME
92
+ Value: TIMESTAMP
93
+ Value: UUID
94
+ Value: EMAIL
95
+ Value: HEXADECIMAL
96
+ Value: BINARY
97
+ Value: BASE64
98
+ Value: GROUP
99
+ Value: ENUM
100
+ Value: MARKDOWN
101
+ Node: Values
102
+ Type: GROUP
103
+ Children:
104
+ Child: Value
105
+ Min: 1
106
+ Node: Value
91
107
  `;
92
108
  //# sourceMappingURL=SchemaProviderMeta.js.map
@@ -3,11 +3,31 @@ import { ValidationException } from "../exceptions/ValidationException";
3
3
  import { Validator } from "../processors/Validator";
4
4
  import { SchemaProvider } from "./SchemaProvider";
5
5
  import { Schema } from "./Schema";
6
+ /** {@link Validator} that, for each node, resolves its {@link Schema} through a {@link SchemaProvider} and validates type and cardinality. */
6
7
  export declare class SchemaValidator implements Validator {
7
8
  private readonly schemaProvider;
8
9
  private readonly recursiveValidation;
10
+ /**
11
+ * Creates a validator that resolves schemas through the given provider.
12
+ *
13
+ * @param schemaProvider where to resolve the schema of each namespace from.
14
+ * @param recursive whether the children of each node are validated recursively too.
15
+ */
9
16
  constructor(schemaProvider: SchemaProvider, recursive?: boolean);
17
+ /**
18
+ * Validates a node against the schema of its namespace.
19
+ *
20
+ * @param node already closed node to validate.
21
+ * @returns the validation errors found, or an empty array if the node is valid.
22
+ */
10
23
  validate(node: Node): ValidationException[];
24
+ /**
25
+ * Validates a node against an already resolved schema: existence, value type and cardinalities of its children.
26
+ *
27
+ * @param node node to validate.
28
+ * @param schema schema to validate against.
29
+ * @returns the validation errors found, empty if the node is valid.
30
+ */
11
31
  validateAgainstSchema(node: Node, schema: Schema): ValidationException[];
12
32
  private static validateChildrenDeclared;
13
33
  private static validateValue;
@@ -3,23 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaValidator = void 0;
4
4
  const ValidationException_1 = require("../exceptions/ValidationException");
5
5
  const TypeRegistry_1 = require("./TypeRegistry");
6
+ /** {@link Validator} that, for each node, resolves its {@link Schema} through a {@link SchemaProvider} and validates type and cardinality. */
6
7
  class SchemaValidator {
8
+ /**
9
+ * Creates a validator that resolves schemas through the given provider.
10
+ *
11
+ * @param schemaProvider where to resolve the schema of each namespace from.
12
+ * @param recursive whether the children of each node are validated recursively too.
13
+ */
7
14
  constructor(schemaProvider, recursive = false) {
8
15
  this.schemaProvider = schemaProvider;
9
16
  this.recursiveValidation = recursive;
10
17
  }
18
+ /**
19
+ * Validates a node against the schema of its namespace.
20
+ *
21
+ * @param node already closed node to validate.
22
+ * @returns the validation errors found, or an empty array if the node is valid.
23
+ */
11
24
  validate(node) {
12
25
  const errors = [];
13
- // Obtenemos namespace
26
+ // Get the namespace
14
27
  const namespace = node.getNamespace();
15
28
  const schema = this.schemaProvider.getSchema(namespace);
16
29
  if (!schema) {
17
30
  errors.push(new ValidationException_1.ValidationException(node.getLine(), "SCHEMA_NOT_FOUND", `Not found schema: ${namespace}`));
18
31
  return errors;
19
32
  }
20
- // Validamos nodo
33
+ // Validate the node
21
34
  errors.push(...this.validateAgainstSchema(node, schema));
22
- // Validamos children
35
+ // Validate the children
23
36
  if (this.recursiveValidation) {
24
37
  for (const childNode of node.getChildren()) {
25
38
  errors.push(...this.validate(childNode));
@@ -27,6 +40,13 @@ class SchemaValidator {
27
40
  }
28
41
  return errors;
29
42
  }
43
+ /**
44
+ * Validates a node against an already resolved schema: existence, value type and cardinalities of its children.
45
+ *
46
+ * @param node node to validate.
47
+ * @param schema schema to validate against.
48
+ * @returns the validation errors found, empty if the node is valid.
49
+ */
30
50
  validateAgainstSchema(node, schema) {
31
51
  const errors = [];
32
52
  const schemaNode = schema.getNodeDefinition(node.getNormalizedName());
@@ -40,8 +60,8 @@ class SchemaValidator {
40
60
  errors.push(...SchemaValidator.validateCount(schemaNode, node));
41
61
  return errors;
42
62
  }
43
- // Modelo de contenido cerrado (STXT-SCHEMA-SPEC, sección 6): solo se permiten
44
- // los hijos directos declarados en la definición del padre; sin Children, cierre total
63
+ // Closed content model (STXT-SCHEMA-SPEC, section 6): only the direct children declared
64
+ // in the definition of the parent are allowed; with no Children, nothing is
45
65
  static validateChildrenDeclared(nodeDef, node) {
46
66
  const errors = [];
47
67
  for (const child of node.getChildren()) {
@@ -101,9 +121,9 @@ class SchemaValidator {
101
121
  errors.push(new ValidationException_1.ValidationException(node.getLine(), "INVALID_NUMBER", `${childCount} nodes of '${childDef.getQualifiedName()}' and min is ${min}`));
102
122
  }
103
123
  if (max !== null && childCount > max) {
104
- // Error en el parent
124
+ // Error on the parent
105
125
  errors.push(new ValidationException_1.ValidationException(node.getLine(), "INVALID_NUMBER", `${childCount} nodes of '${childDef.getQualifiedName()}' and max is ${max}`));
106
- // Error en cada nodo hijo que excede el máximo permitido
126
+ // Error on each child node beyond the allowed maximum
107
127
  for (const child of children) {
108
128
  errors.push(new ValidationException_1.ValidationException(child.getLine(), "INVALID_NUMBER", `Too many '${childDef.getQualifiedName()}' nodes: found ${childCount}, max is ${max}`));
109
129
  }
@@ -1,6 +1,15 @@
1
1
  import { Node } from "../core/Node";
2
2
  import { NodeDefinition } from "./NodeDefinition";
3
+ /** Value type of a node (TEXT, INTEGER, URL...). Each type lives in `src/schema/type` as a singleton. */
3
4
  export interface Type {
5
+ /**
6
+ * Validates the value of a node against this type.
7
+ *
8
+ * @param nodeDef definition of the node in the schema.
9
+ * @param node node to validate.
10
+ * @throws ValidationException if the value of the node does not match the type.
11
+ */
4
12
  validate(nodeDef: NodeDefinition, node: Node): void;
13
+ /** @returns the name of the type, as used in the schemas (e.g. `"TEXT"`). */
5
14
  getName(): string;
6
15
  }
@@ -1,8 +1,21 @@
1
1
  import { Type } from "./Type";
2
+ /** Static registry of the STXT value types, indexed by name. Adding a new type: a new {@link Type} + `register(...)` here. */
2
3
  export declare class TypeRegistry {
3
4
  private static readonly REGISTRY;
4
5
  private static readonly _init;
6
+ /**
7
+ * Tells whether nodes of a type may have children.
8
+ *
9
+ * @param nodeType name of the type.
10
+ * @returns true if nodes of this type may have children (only INLINE and GROUP).
11
+ */
5
12
  static admitsChildren(nodeType: string): boolean;
13
+ /**
14
+ * Looks up a registered type by name.
15
+ *
16
+ * @param nodeType name of the type to look for.
17
+ * @returns the {@link Type} registered under that name, or undefined if it does not exist.
18
+ */
6
19
  static get(nodeType: string): Type | undefined;
7
20
  private static register;
8
21
  }
@@ -21,13 +21,26 @@ const BASE64_1 = require("./type/BASE64");
21
21
  const GROUP_1 = require("./type/GROUP");
22
22
  const ENUM_1 = require("./type/ENUM");
23
23
  const MARKDOWN_1 = require("./type/MARKDOWN");
24
+ /** Static registry of the STXT value types, indexed by name. Adding a new type: a new {@link Type} + `register(...)` here. */
24
25
  class TypeRegistry {
25
- // STXT-SCHEMA-SPEC 9 / STXT-TEMPLATE-SPEC 15: sólo INLINE y GROUP admiten hijos
26
+ // STXT-SCHEMA-SPEC 9 / STXT-TEMPLATE-SPEC 15: only INLINE and GROUP admit children
27
+ /**
28
+ * Tells whether nodes of a type may have children.
29
+ *
30
+ * @param nodeType name of the type.
31
+ * @returns true if nodes of this type may have children (only INLINE and GROUP).
32
+ */
26
33
  static admitsChildren(nodeType) {
27
34
  return nodeType === "INLINE" || nodeType === "GROUP";
28
35
  }
36
+ /**
37
+ * Looks up a registered type by name.
38
+ *
39
+ * @param nodeType name of the type to look for.
40
+ * @returns the {@link Type} registered under that name, or undefined if it does not exist.
41
+ */
29
42
  static get(nodeType) {
30
- // fuerza que se ejecute _init al cargar la clase (por si el bundler hiciera cosas raras)
43
+ // force _init to run when the class is loaded (in case a bundler does something odd)
31
44
  void this._init;
32
45
  return this.REGISTRY.get(nodeType);
33
46
  }
@@ -41,12 +54,12 @@ class TypeRegistry {
41
54
  }
42
55
  exports.TypeRegistry = TypeRegistry;
43
56
  TypeRegistry.REGISTRY = new Map();
44
- // Inicialización estática (sin INSTANCE)
57
+ // Static initialization (no INSTANCE)
45
58
  TypeRegistry._init = (() => {
46
- // Tipos principales
59
+ // Main types
47
60
  TypeRegistry.register(INLINE_1.INLINE);
48
61
  TypeRegistry.register(BLOCK_1.BLOCK);
49
- // Subtipos
62
+ // Subtypes
50
63
  TypeRegistry.register(TEXT_1.TEXT);
51
64
  TypeRegistry.register(BOOLEAN_1.BOOLEAN);
52
65
  TypeRegistry.register(URL_1.URL);
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `BASE64` type: checks that the content is valid Base64. */
2
3
  export declare const BASE64: Type;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BASE64 = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
5
  const binaryValue_1 = require("./binaryValue");
6
+ /** `BASE64` type: checks that the content is valid Base64. */
6
7
  exports.BASE64 = {
7
8
  getName() {
8
9
  return "BASE64";
@@ -10,12 +11,12 @@ exports.BASE64 = {
10
11
  validate(ndef, n) {
11
12
  const raw = (0, binaryValue_1.binaryValue)(n);
12
13
  try {
13
- // Intentamos decodificar
14
+ // Try to decode it
14
15
  const buf = Buffer.from(raw, "base64");
15
- // Re-encode para verificar consistencia
16
- // (evita aceptar cadenas parcialmente válidas)
16
+ // Re-encode to check consistency
17
+ // (this keeps partially valid strings out)
17
18
  const reencoded = buf.toString("base64");
18
- // Normalizamos padding para comparar
19
+ // Normalize the padding before comparing
19
20
  const normalizedInput = raw.replace(/=+$/, "");
20
21
  const normalizedReencoded = reencoded.replace(/=+$/, "");
21
22
  if (normalizedInput !== normalizedReencoded) {
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `BINARY` type: checks that the content is a string of zeros and ones (`[01]+`). */
2
3
  export declare const BINARY: Type;
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BINARY = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
5
  const binaryValue_1 = require("./binaryValue");
6
+ /** `BINARY` type: checks that the content is a string of zeros and ones (`[01]+`). */
6
7
  exports.BINARY = {
7
8
  getName() {
8
9
  return "BINARY";
9
10
  },
10
- // STXT-SCHEMA-SPEC 9.5: cadena [01]+
11
+ // STXT-SCHEMA-SPEC 9.5: [01]+ string
11
12
  validate(ndef, n) {
12
13
  const value = (0, binaryValue_1.binaryValue)(n);
13
14
  if (!/^[01]+$/.test(value)) {
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `BLOCK` type: text block node (`>>`), with no further restriction on the content. */
2
3
  export declare const BLOCK: Type;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BLOCK = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `BLOCK` type: text block node (`>>`), with no further restriction on the content. */
5
6
  exports.BLOCK = {
6
7
  getName() {
7
8
  return "BLOCK";
8
9
  },
9
10
  validate(nodeDef, node) {
10
- // Forma del valor BLOCK (STXT-SCHEMA-SPEC 9.2): sólo bloque '>>', no forma inline
11
+ // BLOCK value form (STXT-SCHEMA-SPEC 9.2): block '>>' only, no inline form
11
12
  if (!node.isTextNode()) {
12
13
  throw new ValidationException_1.ValidationException(node.getLine(), "BLOCK_FORM_REQUIRED", `Node ${node.getQualifiedName()} requires block form '>>'`);
13
14
  }
@@ -1 +1,2 @@
1
+ /** `BOOLEAN` type: checks that the value is `true` or `false`. */
1
2
  export declare const BOOLEAN: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BOOLEAN = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `BOOLEAN` type: checks that the value is `true` or `false`. */
5
6
  exports.BOOLEAN = (0, regexType_1.regexType)("BOOLEAN", /^(true|false)$/, "Invalid boolean");
6
7
  //# sourceMappingURL=BOOLEAN.js.map
@@ -1 +1,2 @@
1
+ /** `DATE` type: checks the `YYYY-MM-DD` format. */
1
2
  export declare const DATE: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DATE = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `DATE` type: checks the `YYYY-MM-DD` format. */
5
6
  exports.DATE = (0, regexType_1.regexType)("DATE", /^\d{4}-\d{2}-\d{2}$/, "Invalid date");
6
7
  //# sourceMappingURL=DATE.js.map
@@ -1 +1,2 @@
1
+ /** `EMAIL` type: checks that the value looks like an e-mail address. */
1
2
  export declare const EMAIL: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EMAIL = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `EMAIL` type: checks that the value looks like an e-mail address. */
5
6
  exports.EMAIL = (0, regexType_1.regexType)("EMAIL", /^(?=.{1,256}$)(?=.{1,64}@.{1,255}$)(?=.{1,64}@.{1,63}\..{1,63}$)[A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, "Invalid email");
6
7
  //# sourceMappingURL=EMAIL.js.map
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `ENUM` type: checks that the value is one of those declared in {@link NodeDefinition.getValues}. */
2
3
  export declare const ENUM: Type;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ENUM = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `ENUM` type: checks that the value is one of those declared in {@link NodeDefinition.getValues}. */
5
6
  exports.ENUM = {
6
7
  getName() {
7
8
  return "ENUM";
8
9
  },
9
10
  validate(nodeDef, node) {
10
- // Forma del valor INLINE (STXT-SCHEMA-SPEC 9.3): no admite bloque '>>'
11
+ // INLINE value form (STXT-SCHEMA-SPEC 9.3): the block '>>' form is not allowed
11
12
  if (node.isTextNode()) {
12
13
  throw new ValidationException_1.ValidationException(node.getLine(), "NOT_ALLOWED_TEXT", `Not allowed text in node ${node.getQualifiedName()}`);
13
14
  }
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `GROUP` type: container node with no value of its own, accepting children just like INLINE. */
2
3
  export declare const GROUP: Type;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GROUP = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `GROUP` type: container node with no value of its own, accepting children just like INLINE. */
5
6
  exports.GROUP = {
6
7
  getName() {
7
8
  return "GROUP";
8
9
  },
9
10
  validate(nodeDef, node) {
10
- // Forma del valor NONE (STXT-SCHEMA-SPEC 9.2): ni valor inline ni bloque '>>'
11
+ // NONE value form (STXT-SCHEMA-SPEC 9.2): neither an inline value nor a '>>' block
11
12
  if (node.getValue().length > 0 || node.isTextNode()) {
12
13
  throw new ValidationException_1.ValidationException(node.getLine(), "INVALID_VALUE", `Node '${node.getName()}' has to be empty`);
13
14
  }
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `HEXADECIMAL` type: checks a hexadecimal string (`[0-9A-Fa-f]+`), with no prefix and no mandatory even length. */
2
3
  export declare const HEXADECIMAL: Type;
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HEXADECIMAL = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
5
  const binaryValue_1 = require("./binaryValue");
6
+ /** `HEXADECIMAL` type: checks a hexadecimal string (`[0-9A-Fa-f]+`), with no prefix and no mandatory even length. */
6
7
  exports.HEXADECIMAL = {
7
8
  getName() {
8
9
  return "HEXADECIMAL";
9
10
  },
10
- // STXT-SCHEMA-SPEC 9.5: cadena [0-9A-Fa-f]+ (sin prefijo '#' ni longitud par)
11
+ // STXT-SCHEMA-SPEC 9.5: [0-9A-Fa-f]+ string, with no '#' prefix and no even-length requirement
11
12
  validate(ndef, n) {
12
13
  const value = (0, binaryValue_1.binaryValue)(n);
13
14
  if (!/^[0-9A-Fa-f]+$/.test(value)) {
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `INLINE` type: node with an inline value (after `:`), accepting children. */
2
3
  export declare const INLINE: Type;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INLINE = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `INLINE` type: node with an inline value (after `:`), accepting children. */
5
6
  exports.INLINE = {
6
7
  getName() {
7
8
  return "INLINE";
8
9
  },
9
10
  validate(nodeDef, node) {
10
- // Forma del valor INLINE (STXT-SCHEMA-SPEC 9.2): no admite bloque '>>'
11
+ // INLINE value form (STXT-SCHEMA-SPEC 9.2): the block '>>' form is not allowed
11
12
  if (node.isTextNode()) {
12
13
  throw new ValidationException_1.ValidationException(node.getLine(), "NOT_ALLOWED_TEXT", `Not allowed text in node ${node.getQualifiedName()}`);
13
14
  }
@@ -1 +1,2 @@
1
+ /** `INTEGER` type: checks an integer with an optional sign. */
1
2
  export declare const INTEGER: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INTEGER = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `INTEGER` type: checks an integer with an optional sign. */
5
6
  exports.INTEGER = (0, regexType_1.regexType)("INTEGER", /^[-+]?\d+$/, "Invalid integer");
6
7
  //# sourceMappingURL=INTEGER.js.map
@@ -1,2 +1,6 @@
1
1
  import { Type } from "../Type";
2
+ /**
3
+ * `MARKDOWN` type. STXT-SCHEMA-SPEC 9.7: for validation purposes it is equivalent to TEXT
4
+ * (any content is valid Markdown); only children are forbidden.
5
+ */
2
6
  export declare const MARKDOWN: Type;
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MARKDOWN = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
- // STXT-SCHEMA-SPEC 9.7: a efectos de validación equivale a TEXT
6
- // (cualquier contenido es válido; solo se prohíben hijos)
5
+ /**
6
+ * `MARKDOWN` type. STXT-SCHEMA-SPEC 9.7: for validation purposes it is equivalent to TEXT
7
+ * (any content is valid Markdown); only children are forbidden.
8
+ */
7
9
  exports.MARKDOWN = {
8
10
  getName() {
9
11
  return "MARKDOWN";
@@ -1 +1,2 @@
1
+ /** `NATURAL` type: checks an unsigned integer. */
1
2
  export declare const NATURAL: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NATURAL = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `NATURAL` type: checks an unsigned integer. */
5
6
  exports.NATURAL = (0, regexType_1.regexType)("NATURAL", /^\d+$/, "Invalid natural");
6
7
  //# sourceMappingURL=NATURAL.js.map
@@ -1 +1,2 @@
1
+ /** `NUMBER` type: checks a decimal number, with optional sign and exponent notation. */
1
2
  export declare const NUMBER: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NUMBER = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `NUMBER` type: checks a decimal number, with optional sign and exponent notation. */
5
6
  exports.NUMBER = (0, regexType_1.regexType)("NUMBER", /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/, "Invalid number");
6
7
  //# sourceMappingURL=NUMBER.js.map
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `TEXT` type: free text node, with no children allowed. */
2
3
  export declare const TEXT: Type;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TEXT = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `TEXT` type: free text node, with no children allowed. */
5
6
  exports.TEXT = {
6
7
  getName() {
7
8
  return "TEXT";
@@ -1 +1,2 @@
1
+ /** `TIME` type: checks the `HH:MM:SS` format. */
1
2
  export declare const TIME: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TIME = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `TIME` type: checks the `HH:MM:SS` format. */
5
6
  exports.TIME = (0, regexType_1.regexType)("TIME", /^\d{2}:\d{2}:\d{2}$/, "Invalid time");
6
7
  //# sourceMappingURL=TIME.js.map
@@ -1 +1,2 @@
1
+ /** `TIMESTAMP` type: checks an ISO-8601 timestamp. */
1
2
  export declare const TIMESTAMP: import("../Type").Type;