@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
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringUtils = void 0;
4
+ /** String normalization helpers used for names, namespaces and values. */
4
5
  class StringUtils {
5
6
  constructor() {
6
7
  }
7
- // Usado para nodos name>>
8
+ // Used for name>> nodes
9
+ /**
10
+ * Removes the trailing whitespace of a string.
11
+ *
12
+ * @param s string to strip the trailing spaces from.
13
+ * @returns the string without trailing whitespace; null/undefined is treated as the empty string.
14
+ */
8
15
  static rightTrim(s) {
9
16
  const value = s ?? "";
10
17
  let i = value.length - 1;
@@ -13,21 +20,45 @@ class StringUtils {
13
20
  }
14
21
  return value.substring(0, i + 1);
15
22
  }
16
- // Usado para nodos tipo Base64 y Hex
23
+ // Used for BASE64 and HEXADECIMAL nodes
24
+ /**
25
+ * Removes every whitespace character of a string.
26
+ *
27
+ * @param input string to remove the spaces from.
28
+ * @returns the string without any whitespace at all.
29
+ */
17
30
  static cleanSpaces(input) {
18
31
  return input.replace(/\s+/g, "");
19
32
  }
20
- // Usado para normalizar namespace
33
+ // Used to normalize namespaces
34
+ /**
35
+ * Lower-cases a string.
36
+ *
37
+ * @param input string to lower-case.
38
+ * @returns the lower-cased string; null/undefined is treated as the empty string.
39
+ */
21
40
  static lowerCase(input) {
22
- // Equivalente práctico a Locale.ROOT en JS: evitar dependencias de locale del usuario
41
+ // Practical equivalent of Locale.ROOT in JS: keep the user's locale out of it
23
42
  return (input ?? "").toLowerCase();
24
43
  }
25
- // Usados para name de los nodos
44
+ // Used for the name of the nodes
45
+ /**
46
+ * Trims a string and collapses its inner whitespace.
47
+ *
48
+ * @param s string to compact.
49
+ * @returns the string with the outer spaces trimmed and the inner ones collapsed into a single one; null/undefined is treated as the empty string.
50
+ */
26
51
  static compactSpaces(s) {
27
52
  return (s ?? "").trim().replace(/\s+/g, " ");
28
53
  }
29
- // Usados para name normalizado de nodos (STXT-SPEC 4.3): NFC + minúsculas,
30
- // conservando diacríticos y alfabetos no latinos (modelo IDN)
54
+ // Used for the normalized name of the nodes (STXT-SPEC 4.3): NFC + lower case,
55
+ // keeping diacritics and non-Latin alphabets (IDN model)
56
+ /**
57
+ * Builds the canonical name of a node, as defined by STXT-SPEC 4.3.
58
+ *
59
+ * @param input string to normalize.
60
+ * @returns the canonical name of a node: NFC + lower case, with separators collapsed into '-'; null/undefined is treated as the empty string.
61
+ */
31
62
  static normalize(input) {
32
63
  let s = (input ?? "").trim();
33
64
  if (s.length === 0) {
@@ -35,9 +66,9 @@ class StringUtils {
35
66
  }
36
67
  s = s.normalize("NFC");
37
68
  s = s.toLowerCase();
38
- // toda secuencia de separadores ('-', '_', espacios) => un solo '-'
69
+ // every run of separators ('-', '_', spaces) => a single '-'
39
70
  s = s.replace(/[-_\s]+/g, "-");
40
- // trim de '-'
71
+ // trim the '-'
41
72
  s = s.replace(/^-+|-+$/g, "");
42
73
  return s;
43
74
  }
@@ -1,6 +1,20 @@
1
+ /**
2
+ * Syntax error detected while parsing (lexical/structural phase, not schema). Every exception
3
+ * carries an UPPERCASE code and the line of the document where it was detected.
4
+ */
1
5
  export declare class ParseException extends Error {
6
+ /** Line number of the document where the error was detected. */
2
7
  readonly line: number;
8
+ /** Error code in UPPERCASE (e.g. `INVALID_LINE`). */
3
9
  readonly code: string;
10
+ /**
11
+ * Creates a syntax error located at a line of the document.
12
+ *
13
+ * @param line line number where the error was detected.
14
+ * @param code error code in UPPERCASE.
15
+ * @param message descriptive message.
16
+ */
4
17
  constructor(line: number, code: string, message: string);
18
+ /** @returns a readable representation of the error, with its line and its code. */
5
19
  toString(): string;
6
20
  }
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParseException = void 0;
4
+ /**
5
+ * Syntax error detected while parsing (lexical/structural phase, not schema). Every exception
6
+ * carries an UPPERCASE code and the line of the document where it was detected.
7
+ */
4
8
  class ParseException extends Error {
9
+ /**
10
+ * Creates a syntax error located at a line of the document.
11
+ *
12
+ * @param line line number where the error was detected.
13
+ * @param code error code in UPPERCASE.
14
+ * @param message descriptive message.
15
+ */
5
16
  constructor(line, code, message) {
6
17
  super(message);
7
18
  this.name = "ParseException";
@@ -9,6 +20,7 @@ class ParseException extends Error {
9
20
  this.code = code;
10
21
  Object.setPrototypeOf(this, ParseException.prototype);
11
22
  }
23
+ /** @returns a readable representation of the error, with its line and its code. */
12
24
  toString() {
13
25
  return `${this.name} [line=${this.line}, code=${this.code}]: ${this.message}`;
14
26
  }
@@ -1,6 +1,20 @@
1
+ /**
2
+ * Error that is not tied to a line of the document: a wrong use of the API or an inconsistency
3
+ * found at runtime (e.g. an ambiguous child, a type registered twice). It carries an UPPERCASE
4
+ * code, like the rest of the STXT exceptions.
5
+ */
1
6
  export declare class RuntimeException extends Error {
7
+ /** Error code in UPPERCASE (e.g. `AMBIGUOUS_CHILD`). */
2
8
  readonly code: string;
9
+ /**
10
+ * Creates an error with an error code and a message.
11
+ *
12
+ * @param code error code in UPPERCASE.
13
+ * @param message descriptive message.
14
+ */
3
15
  constructor(code: string, message: string);
16
+ /** @returns the error code in UPPERCASE. */
4
17
  getCode(): string;
18
+ /** @returns a readable representation of the error, with its code. */
5
19
  toString(): string;
6
20
  }
@@ -1,16 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RuntimeException = void 0;
4
+ /**
5
+ * Error that is not tied to a line of the document: a wrong use of the API or an inconsistency
6
+ * found at runtime (e.g. an ambiguous child, a type registered twice). It carries an UPPERCASE
7
+ * code, like the rest of the STXT exceptions.
8
+ */
4
9
  class RuntimeException extends Error {
10
+ /**
11
+ * Creates an error with an error code and a message.
12
+ *
13
+ * @param code error code in UPPERCASE.
14
+ * @param message descriptive message.
15
+ */
5
16
  constructor(code, message) {
6
17
  super(message);
7
18
  this.name = "RuntimeException";
8
19
  this.code = code;
9
20
  Object.setPrototypeOf(this, RuntimeException.prototype);
10
21
  }
22
+ /** @returns the error code in UPPERCASE. */
11
23
  getCode() {
12
24
  return this.code;
13
25
  }
26
+ /** @returns a readable representation of the error, with its code. */
14
27
  toString() {
15
28
  const message = this.message;
16
29
  return `${this.name}[${this.code}]${message ? `: ${message}` : ""}`;
@@ -1,4 +1,12 @@
1
1
  import { ParseException } from "./ParseException";
2
+ /** Semantic validation error (schema, type or cardinality), detected when a node is closed. */
2
3
  export declare class ValidationException extends ParseException {
4
+ /**
5
+ * Creates a validation error located at a line of the document.
6
+ *
7
+ * @param line line number where the error was detected.
8
+ * @param code error code in UPPERCASE.
9
+ * @param message descriptive message.
10
+ */
3
11
  constructor(line: number, code: string, message: string);
4
12
  }
@@ -2,7 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ValidationException = void 0;
4
4
  const ParseException_1 = require("./ParseException");
5
+ /** Semantic validation error (schema, type or cardinality), detected when a node is closed. */
5
6
  class ValidationException extends ParseException_1.ParseException {
7
+ /**
8
+ * Creates a validation error located at a line of the document.
9
+ *
10
+ * @param line line number where the error was detected.
11
+ * @param code error code in UPPERCASE.
12
+ * @param message descriptive message.
13
+ */
6
14
  constructor(line, code, message) {
7
15
  super(line, code, message);
8
16
  this.name = "ValidationException";
@@ -1,8 +1,37 @@
1
1
  import { Line } from "../core/Line";
2
2
  import { Node } from "../core/Node";
3
+ /**
4
+ * Process hook notified by the {@link Parser} while parsing: when each node is opened and closed,
5
+ * and for every comment and text line it reads. Register it with {@link Parser.registerObserver}.
6
+ */
3
7
  export interface Observer {
8
+ /**
9
+ * Called when a node is opened.
10
+ *
11
+ * @param node node just opened (its children and its text lines are not complete yet).
12
+ * @param line source line that opened the node, as it appears in the document.
13
+ */
4
14
  onCreate(node: Node, line: string): void;
15
+ /**
16
+ * Called when a node is closed.
17
+ *
18
+ * @param node node just closed, with all its children and its value already complete.
19
+ */
5
20
  onFinish(node: Node): void;
21
+ /**
22
+ * Called for every comment line, which produces no node.
23
+ *
24
+ * @param lineNumber line number of the comment.
25
+ * @param line source line of the comment, as it appears in the document.
26
+ */
6
27
  onComment(lineNumber: number, line: string): void;
28
+ /**
29
+ * Called for every text line appended to an open BLOCK node.
30
+ *
31
+ * @param node BLOCK node the line was appended to.
32
+ * @param lineNumber line number of the text line.
33
+ * @param lineString source line, as it appears in the document.
34
+ * @param line the same line already split into indentation and content.
35
+ */
7
36
  onTextLine(node: Node, lineNumber: number, lineString: string, line: Line): void;
8
37
  }
@@ -1,5 +1,14 @@
1
1
  import { Node } from "../core/Node";
2
2
  import { ValidationException } from "../exceptions/ValidationException";
3
+ /** Process hook invoked by the {@link Parser} when each node is closed, to validate in streaming. */
3
4
  export interface Validator {
5
+ /**
6
+ * Validates a node and returns every error found (without throwing), letting the caller
7
+ * collect errors from several nodes instead of bailing out on the first one. An empty array
8
+ * means the node is valid.
9
+ *
10
+ * @param node already closed node to validate.
11
+ * @returns the validation errors found, or an empty array if the node is valid.
12
+ */
4
13
  validate(node: Node): ValidationException[];
5
14
  }
@@ -2,8 +2,23 @@ import { Node } from "../core/Node";
2
2
  import { Validator } from "../processors/Validator";
3
3
  import { SchemaValidator } from "../schema/SchemaValidator";
4
4
  import { ValidationException } from "../exceptions/ValidationException";
5
+ /**
6
+ * Wrapper around a {@link SchemaValidator} that only validates namespaced nodes, so that a
7
+ * document mixing schema-bound and free nodes does not report the free ones as unknown.
8
+ */
5
9
  export declare class ConditionalValidator implements Validator {
6
10
  private readonly schemaValidator;
11
+ /**
12
+ * Creates a validator that delegates to a schema validator.
13
+ *
14
+ * @param schemaValidator validator the namespaced nodes are handed over to.
15
+ */
7
16
  constructor(schemaValidator: SchemaValidator);
17
+ /**
18
+ * Validates a node when it has a namespace, and lets it through otherwise.
19
+ *
20
+ * @param node already closed node to validate.
21
+ * @returns the validation errors found, or an empty array if the node is valid or has no namespace.
22
+ */
8
23
  validate(node: Node): ValidationException[];
9
24
  }
@@ -1,13 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConditionalValidator = void 0;
4
- // Wrapper del validador que solo valida nodos con namespace
4
+ /**
5
+ * Wrapper around a {@link SchemaValidator} that only validates namespaced nodes, so that a
6
+ * document mixing schema-bound and free nodes does not report the free ones as unknown.
7
+ */
5
8
  class ConditionalValidator {
9
+ /**
10
+ * Creates a validator that delegates to a schema validator.
11
+ *
12
+ * @param schemaValidator validator the namespaced nodes are handed over to.
13
+ */
6
14
  constructor(schemaValidator) {
7
15
  this.schemaValidator = schemaValidator;
8
16
  }
17
+ /**
18
+ * Validates a node when it has a namespace, and lets it through otherwise.
19
+ *
20
+ * @param node already closed node to validate.
21
+ * @returns the validation errors found, or an empty array if the node is valid or has no namespace.
22
+ */
9
23
  validate(node) {
10
- // Solo validar si tiene namespace
24
+ // Only validate the node when it has a namespace
11
25
  if (node.getNamespace() !== "") {
12
26
  return this.schemaValidator.validate(node);
13
27
  }
@@ -1,11 +1,29 @@
1
1
  import { Node } from "../core/Node";
2
+ /** Indentation style to use when writing. */
2
3
  export declare enum IndentStyle {
4
+ /** One tab character per level. */
3
5
  TABS = "TABS",
6
+ /** Four spaces per level. */
4
7
  SPACES_4 = "SPACES_4"
5
8
  }
9
+ /** Serializes a {@link Node} (or a list of root nodes) back to STXT text. */
6
10
  export declare class NodeWriter {
7
11
  private constructor();
12
+ /**
13
+ * Serializes a node to STXT text.
14
+ *
15
+ * @param node node to serialize (along with its children).
16
+ * @param style indentation style to use; tabs by default.
17
+ * @returns the node serialized to STXT text.
18
+ */
8
19
  static toSTXT(node: Node, style?: IndentStyle): string;
20
+ /**
21
+ * Serializes a list of root nodes to STXT text, separated by a blank line.
22
+ *
23
+ * @param docs root nodes to serialize.
24
+ * @param style indentation style to use; tabs by default.
25
+ * @returns the documents serialized to STXT text.
26
+ */
9
27
  static toSTXTDocs(docs: ReadonlyArray<Node>, style?: IndentStyle): string;
10
28
  private static writeNode;
11
29
  private static indent;
@@ -1,18 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeWriter = exports.IndentStyle = void 0;
4
+ /** Indentation style to use when writing. */
4
5
  var IndentStyle;
5
6
  (function (IndentStyle) {
7
+ /** One tab character per level. */
6
8
  IndentStyle["TABS"] = "TABS";
9
+ /** Four spaces per level. */
7
10
  IndentStyle["SPACES_4"] = "SPACES_4";
8
11
  })(IndentStyle || (exports.IndentStyle = IndentStyle = {}));
12
+ /** Serializes a {@link Node} (or a list of root nodes) back to STXT text. */
9
13
  class NodeWriter {
10
14
  constructor() { }
15
+ /**
16
+ * Serializes a node to STXT text.
17
+ *
18
+ * @param node node to serialize (along with its children).
19
+ * @param style indentation style to use; tabs by default.
20
+ * @returns the node serialized to STXT text.
21
+ */
11
22
  static toSTXT(node, style = IndentStyle.TABS) {
12
23
  const out = [];
13
24
  NodeWriter.writeNode(out, node, 0, style, "");
14
25
  return out.join("");
15
26
  }
27
+ /**
28
+ * Serializes a list of root nodes to STXT text, separated by a blank line.
29
+ *
30
+ * @param docs root nodes to serialize.
31
+ * @param style indentation style to use; tabs by default.
32
+ * @returns the documents serialized to STXT text.
33
+ */
16
34
  static toSTXTDocs(docs, style = IndentStyle.TABS) {
17
35
  const out = [];
18
36
  for (let i = 0; i < docs.length; i++) {
@@ -1,22 +1,40 @@
1
1
  import { Schema } from "../schema/Schema";
2
2
  import { SchemaProvider } from "../schema/SchemaProvider";
3
3
  /**
4
- * Provider unificado que maneja tanto schemas como templates.
5
- * Detecta automáticamente el tipo según el namespace del nodo raíz:
6
- * - @stxt.template => procesa como template
7
- * - @stxt.schema => procesa como schema
8
- * - otros => no hace nada
4
+ * Unified provider that handles both schemas and templates.
5
+ * It detects which one it is from the namespace of the root node:
6
+ * - @stxt.template => processed as a template
7
+ * - @stxt.schema => processed as a schema
8
+ * - anything else => ignored
9
9
  */
10
10
  export declare class UnifiedSchemaProvider implements SchemaProvider {
11
11
  private readonly schemas;
12
12
  private readonly schemaMeta;
13
13
  private readonly templateMeta;
14
+ /** Creates an empty provider, with the two meta-schemas already loaded. */
14
15
  constructor();
16
+ /**
17
+ * Resolves the schema that applies to a namespace, serving the meta-schemas of the two
18
+ * reserved namespaces itself.
19
+ *
20
+ * @param namespace namespace whose schema is wanted.
21
+ * @returns the schema of the namespace, or null/undefined if none has been registered for it.
22
+ */
15
23
  getSchema(namespace: string): Schema | undefined | null;
24
+ /**
25
+ * Parses a document and registers every schema or template it defines, each one under its own
26
+ * namespace. Documents of any other namespace are ignored.
27
+ *
28
+ * @param text text of the document to load.
29
+ * @throws ParseException if the document cannot be parsed, or the first ValidationException if
30
+ * a schema or a template does not validate against its meta-schema.
31
+ */
16
32
  addFile(text: string): void;
17
33
  private addTemplateNode;
18
34
  private addSchemaNode;
19
35
  private static throwIfInvalid;
36
+ /** Removes every schema and template registered in this provider. */
20
37
  clear(): void;
38
+ /** @returns every schema registered in this provider, in registration order. */
21
39
  getAllSchemas(): ReadonlyArray<Schema>;
22
40
  }
@@ -9,18 +9,26 @@ const SchemaValidator_1 = require("../schema/SchemaValidator");
9
9
  const MetaTemplateSchemaProvider_1 = require("../template/MetaTemplateSchemaProvider");
10
10
  const TemplateParser_1 = require("../template/TemplateParser");
11
11
  /**
12
- * Provider unificado que maneja tanto schemas como templates.
13
- * Detecta automáticamente el tipo según el namespace del nodo raíz:
14
- * - @stxt.template => procesa como template
15
- * - @stxt.schema => procesa como schema
16
- * - otros => no hace nada
12
+ * Unified provider that handles both schemas and templates.
13
+ * It detects which one it is from the namespace of the root node:
14
+ * - @stxt.template => processed as a template
15
+ * - @stxt.schema => processed as a schema
16
+ * - anything else => ignored
17
17
  */
18
18
  class UnifiedSchemaProvider {
19
+ /** Creates an empty provider, with the two meta-schemas already loaded. */
19
20
  constructor() {
20
21
  this.schemas = new Map();
21
22
  this.schemaMeta = new SchemaProviderMeta_1.SchemaProviderMeta();
22
23
  this.templateMeta = new MetaTemplateSchemaProvider_1.MetaTemplateSchemaProvider();
23
24
  }
25
+ /**
26
+ * Resolves the schema that applies to a namespace, serving the meta-schemas of the two
27
+ * reserved namespaces itself.
28
+ *
29
+ * @param namespace namespace whose schema is wanted.
30
+ * @returns the schema of the namespace, or null/undefined if none has been registered for it.
31
+ */
24
32
  getSchema(namespace) {
25
33
  const key = StringUtils_1.StringUtils.lowerCase(namespace);
26
34
  if (namespace === "@stxt.template") {
@@ -32,6 +40,14 @@ class UnifiedSchemaProvider {
32
40
  let result = this.schemas.get(key);
33
41
  return result;
34
42
  }
43
+ /**
44
+ * Parses a document and registers every schema or template it defines, each one under its own
45
+ * namespace. Documents of any other namespace are ignored.
46
+ *
47
+ * @param text text of the document to load.
48
+ * @throws ParseException if the document cannot be parsed, or the first ValidationException if
49
+ * a schema or a template does not validate against its meta-schema.
50
+ */
35
51
  addFile(text) {
36
52
  const parser = new Parser_1.Parser();
37
53
  const nodes = parser.parse(text);
@@ -46,32 +62,34 @@ class UnifiedSchemaProvider {
46
62
  }
47
63
  }
48
64
  addTemplateNode(node) {
49
- // Validar contra el meta-schema de templates
65
+ // Validate against the meta-schema of templates
50
66
  const schemaValidator = new SchemaValidator_1.SchemaValidator(this.templateMeta, true);
51
67
  UnifiedSchemaProvider.throwIfInvalid(schemaValidator.validate(node));
52
- // Transformar el template a schema
68
+ // Transform the template into a schema
53
69
  const schema = (0, TemplateParser_1.transformTemplateNodeToSchema)(node);
54
70
  const key = StringUtils_1.StringUtils.lowerCase(schema.getNamespace());
55
71
  this.schemas.set(key, schema);
56
72
  }
57
73
  addSchemaNode(node) {
58
- // Validar contra el meta-schema de schemas
74
+ // Validate against the meta-schema of schemas
59
75
  const schemaValidator = new SchemaValidator_1.SchemaValidator(this.schemaMeta, true);
60
76
  UnifiedSchemaProvider.throwIfInvalid(schemaValidator.validate(node));
61
- // Transformar el nodo a schema
77
+ // Transform the node into a schema
62
78
  const schema = (0, SchemaParser_1.transformNodeToSchema)(node);
63
79
  const key = StringUtils_1.StringUtils.lowerCase(schema.getNamespace());
64
80
  this.schemas.set(key, schema);
65
81
  }
66
- // Un schema/template que no valida contra su meta-schema no debe cargarse
82
+ // A schema/template that does not validate against its meta-schema must not be loaded
67
83
  static throwIfInvalid(errors) {
68
84
  if (errors.length > 0) {
69
85
  throw errors[0];
70
86
  }
71
87
  }
88
+ /** Removes every schema and template registered in this provider. */
72
89
  clear() {
73
90
  this.schemas.clear();
74
91
  }
92
+ /** @returns every schema registered in this provider, in registration order. */
75
93
  getAllSchemas() {
76
94
  return Array.from(this.schemas.values());
77
95
  }
@@ -1,16 +1,34 @@
1
+ /** Definition of an expected child inside a {@link NodeDefinition}: name, namespace and min/max cardinality. */
1
2
  export declare class ChildDefinition {
2
3
  private readonly normalizedName;
3
4
  private readonly name;
4
5
  private readonly namespace;
5
6
  private readonly min;
6
7
  private readonly max;
8
+ /**
9
+ * Creates the definition of an expected child.
10
+ *
11
+ * @param name name of the expected child.
12
+ * @param namespace namespace of the expected child (may be null/undefined).
13
+ * @param min minimum cardinality, or null if there is no minimum.
14
+ * @param max maximum cardinality, or null if there is no maximum.
15
+ * @param numLine line number, for the error messages.
16
+ * @throws ValidationException with code `INVALID_NODE_NAME` if the name is not valid.
17
+ */
7
18
  constructor(name: string, namespace: string | null | undefined, min: number | null, max: number | null, numLine: number);
19
+ /** @returns the name of the expected child, as it appears in the schema. */
8
20
  getName(): string;
21
+ /** @returns the canonical name of the expected child. */
9
22
  getNormalizedName(): string;
23
+ /** @returns the namespace of the expected child, or the empty string if it has none. */
10
24
  getNamespace(): string;
25
+ /** @returns the minimum cardinality, or null if there is no minimum. */
11
26
  getMin(): number | null;
27
+ /** @returns the maximum cardinality, or null if there is no maximum. */
12
28
  getMax(): number | null;
29
+ /** @returns the canonical name prefixed by its namespace, used as the key in {@link NodeDefinition.getChildren}. */
13
30
  getQualifiedName(): string;
31
+ /** @returns a plain object with the definition, so that JSON.stringify serializes it. */
14
32
  toJSON(): {
15
33
  name: string;
16
34
  normalizedName: string;
@@ -4,7 +4,18 @@ exports.ChildDefinition = void 0;
4
4
  const NamespaceValidator_1 = require("../core/NamespaceValidator");
5
5
  const ValidationException_1 = require("../exceptions/ValidationException");
6
6
  const StringUtils_1 = require("../core/StringUtils");
7
+ /** Definition of an expected child inside a {@link NodeDefinition}: name, namespace and min/max cardinality. */
7
8
  class ChildDefinition {
9
+ /**
10
+ * Creates the definition of an expected child.
11
+ *
12
+ * @param name name of the expected child.
13
+ * @param namespace namespace of the expected child (may be null/undefined).
14
+ * @param min minimum cardinality, or null if there is no minimum.
15
+ * @param max maximum cardinality, or null if there is no maximum.
16
+ * @param numLine line number, for the error messages.
17
+ * @throws ValidationException with code `INVALID_NODE_NAME` if the name is not valid.
18
+ */
8
19
  constructor(name, namespace, min, max, numLine) {
9
20
  this.name = StringUtils_1.StringUtils.compactSpaces(name);
10
21
  this.normalizedName = StringUtils_1.StringUtils.normalize(name);
@@ -16,26 +27,33 @@ class ChildDefinition {
16
27
  throw new ValidationException_1.ValidationException(numLine, "INVALID_NODE_NAME", `Node name not valid: ${name}`);
17
28
  }
18
29
  }
30
+ /** @returns the name of the expected child, as it appears in the schema. */
19
31
  getName() {
20
32
  return this.name;
21
33
  }
34
+ /** @returns the canonical name of the expected child. */
22
35
  getNormalizedName() {
23
36
  return this.normalizedName;
24
37
  }
38
+ /** @returns the namespace of the expected child, or the empty string if it has none. */
25
39
  getNamespace() {
26
40
  return this.namespace;
27
41
  }
42
+ /** @returns the minimum cardinality, or null if there is no minimum. */
28
43
  getMin() {
29
44
  return this.min;
30
45
  }
46
+ /** @returns the maximum cardinality, or null if there is no maximum. */
31
47
  getMax() {
32
48
  return this.max;
33
49
  }
50
+ /** @returns the canonical name prefixed by its namespace, used as the key in {@link NodeDefinition.getChildren}. */
34
51
  getQualifiedName() {
35
52
  return this.namespace.length === 0
36
53
  ? this.normalizedName
37
54
  : `${this.namespace}:${this.normalizedName}`;
38
55
  }
56
+ /** @returns a plain object with the definition, so that JSON.stringify serializes it. */
39
57
  toJSON() {
40
58
  return {
41
59
  name: this.getName(),