@stxt-lang/core 0.5.2 → 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 (109) hide show
  1. package/README.md +1 -0
  2. package/out/all.js +3 -3
  3. package/out/core/Constants.d.ts +8 -0
  4. package/out/core/Constants.js +8 -0
  5. package/out/core/Line.d.ts +20 -0
  6. package/out/core/Line.js +15 -0
  7. package/out/core/LineParser.d.ts +17 -0
  8. package/out/core/LineParser.js +27 -10
  9. package/out/core/NameNamespace.d.ts +9 -0
  10. package/out/core/NameNamespace.js +9 -0
  11. package/out/core/NameNamespaceParser.d.ts +11 -0
  12. package/out/core/NameNamespaceParser.js +16 -5
  13. package/out/core/NamespaceValidator.d.ts +18 -0
  14. package/out/core/NamespaceValidator.js +18 -0
  15. package/out/core/Node.d.ts +55 -0
  16. package/out/core/Node.js +56 -1
  17. package/out/core/NodeCreator.d.ts +11 -0
  18. package/out/core/NodeCreator.js +14 -3
  19. package/out/core/ParseResult.d.ts +26 -0
  20. package/out/core/ParseResult.js +26 -0
  21. package/out/core/Parser.d.ts +31 -0
  22. package/out/core/Parser.js +50 -19
  23. package/out/core/StringUtils.d.ts +31 -0
  24. package/out/core/StringUtils.js +40 -9
  25. package/out/exceptions/ParseException.d.ts +14 -0
  26. package/out/exceptions/ParseException.js +12 -0
  27. package/out/exceptions/RuntimeException.d.ts +14 -0
  28. package/out/exceptions/RuntimeException.js +13 -0
  29. package/out/exceptions/ValidationException.d.ts +8 -0
  30. package/out/exceptions/ValidationException.js +8 -0
  31. package/out/processors/Observer.d.ts +29 -0
  32. package/out/processors/Validator.d.ts +9 -0
  33. package/out/runtime/ConditionalValidator.d.ts +15 -0
  34. package/out/runtime/ConditionalValidator.js +16 -2
  35. package/out/runtime/NodeWriter.d.ts +18 -0
  36. package/out/runtime/NodeWriter.js +18 -0
  37. package/out/runtime/UnifiedSchemaProvider.d.ts +23 -5
  38. package/out/runtime/UnifiedSchemaProvider.js +28 -10
  39. package/out/schema/ChildDefinition.d.ts +18 -0
  40. package/out/schema/ChildDefinition.js +18 -0
  41. package/out/schema/NodeDefinition.d.ts +44 -0
  42. package/out/schema/NodeDefinition.js +47 -3
  43. package/out/schema/Schema.d.ts +26 -0
  44. package/out/schema/Schema.js +26 -1
  45. package/out/schema/SchemaParser.d.ts +7 -0
  46. package/out/schema/SchemaParser.js +26 -16
  47. package/out/schema/SchemaProvider.d.ts +7 -0
  48. package/out/schema/SchemaProviderMemory.d.ts +27 -0
  49. package/out/schema/SchemaProviderMemory.js +27 -0
  50. package/out/schema/SchemaProviderMeta.d.ts +16 -0
  51. package/out/schema/SchemaProviderMeta.js +16 -0
  52. package/out/schema/SchemaValidator.d.ts +20 -0
  53. package/out/schema/SchemaValidator.js +27 -7
  54. package/out/schema/Type.d.ts +9 -0
  55. package/out/schema/TypeRegistry.d.ts +13 -0
  56. package/out/schema/TypeRegistry.js +18 -5
  57. package/out/schema/type/BASE64.d.ts +1 -0
  58. package/out/schema/type/BASE64.js +5 -4
  59. package/out/schema/type/BINARY.d.ts +1 -0
  60. package/out/schema/type/BINARY.js +2 -1
  61. package/out/schema/type/BLOCK.d.ts +1 -0
  62. package/out/schema/type/BLOCK.js +2 -1
  63. package/out/schema/type/BOOLEAN.d.ts +1 -0
  64. package/out/schema/type/BOOLEAN.js +1 -0
  65. package/out/schema/type/DATE.d.ts +1 -0
  66. package/out/schema/type/DATE.js +1 -0
  67. package/out/schema/type/EMAIL.d.ts +1 -0
  68. package/out/schema/type/EMAIL.js +1 -0
  69. package/out/schema/type/ENUM.d.ts +1 -0
  70. package/out/schema/type/ENUM.js +2 -1
  71. package/out/schema/type/GROUP.d.ts +1 -0
  72. package/out/schema/type/GROUP.js +2 -1
  73. package/out/schema/type/HEXADECIMAL.d.ts +1 -0
  74. package/out/schema/type/HEXADECIMAL.js +2 -1
  75. package/out/schema/type/INLINE.d.ts +1 -0
  76. package/out/schema/type/INLINE.js +2 -1
  77. package/out/schema/type/INTEGER.d.ts +1 -0
  78. package/out/schema/type/INTEGER.js +1 -0
  79. package/out/schema/type/MARKDOWN.d.ts +4 -0
  80. package/out/schema/type/MARKDOWN.js +4 -2
  81. package/out/schema/type/NATURAL.d.ts +1 -0
  82. package/out/schema/type/NATURAL.js +1 -0
  83. package/out/schema/type/NUMBER.d.ts +1 -0
  84. package/out/schema/type/NUMBER.js +1 -0
  85. package/out/schema/type/TEXT.d.ts +1 -0
  86. package/out/schema/type/TEXT.js +1 -0
  87. package/out/schema/type/TIME.d.ts +1 -0
  88. package/out/schema/type/TIME.js +1 -0
  89. package/out/schema/type/TIMESTAMP.d.ts +1 -0
  90. package/out/schema/type/TIMESTAMP.js +1 -0
  91. package/out/schema/type/URL.d.ts +1 -0
  92. package/out/schema/type/URL.js +2 -1
  93. package/out/schema/type/UUID.d.ts +1 -0
  94. package/out/schema/type/UUID.js +1 -0
  95. package/out/schema/type/binaryValue.d.ts +9 -0
  96. package/out/schema/type/binaryValue.js +9 -3
  97. package/out/schema/type/regexType.d.ts +8 -0
  98. package/out/schema/type/regexType.js +9 -1
  99. package/out/template/ChildLine.d.ts +14 -0
  100. package/out/template/ChildLine.js +14 -0
  101. package/out/template/ChildLineParser.d.ts +10 -0
  102. package/out/template/ChildLineParser.js +17 -8
  103. package/out/template/MetaTemplateSchemaProvider.d.ts +16 -0
  104. package/out/template/MetaTemplateSchemaProvider.js +17 -1
  105. package/out/template/TemplateParser.d.ts +8 -0
  106. package/out/template/TemplateParser.js +49 -39
  107. package/out/template/TemplateSchemaProviderMemory.d.ts +18 -0
  108. package/out/template/TemplateSchemaProviderMemory.js +21 -3
  109. package/package.json +1 -1
@@ -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;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TIMESTAMP = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `TIMESTAMP` type: checks an ISO-8601 timestamp. */
5
6
  exports.TIMESTAMP = (0, regexType_1.regexType)("TIMESTAMP", /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[+-]\d{2}:\d{2})?$/, "Invalid timestamp");
6
7
  //# sourceMappingURL=TIMESTAMP.js.map
@@ -1,2 +1,3 @@
1
1
  import { Type } from "../Type";
2
+ /** `URL` type: checks that the value is a syntactically valid URI/URL. */
2
3
  export declare const URL: Type;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.URL = void 0;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /** `URL` type: checks that the value is a syntactically valid URI/URL. */
5
6
  exports.URL = {
6
7
  getName() {
7
8
  return "URL";
8
9
  },
9
10
  validate(ndef, n) {
10
- // Forma del valor INLINE (STXT-SCHEMA-SPEC 9.4): no admite bloque '>>'
11
+ // INLINE value form (STXT-SCHEMA-SPEC 9.4): the block '>>' form is not allowed
11
12
  if (n.isTextNode()) {
12
13
  throw new ValidationException_1.ValidationException(n.getLine(), "NOT_ALLOWED_TEXT", `Not allowed text in node ${n.getQualifiedName()}`);
13
14
  }
@@ -1 +1,2 @@
1
+ /** `UUID` type: checks the standard UUID format (`8-4-4-4-12` hexadecimal). */
1
2
  export declare const UUID: import("../Type").Type;
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UUID = void 0;
4
4
  const regexType_1 = require("./regexType");
5
+ /** `UUID` type: checks the standard UUID format (`8-4-4-4-12` hexadecimal). */
5
6
  exports.UUID = (0, regexType_1.regexType)("UUID", /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/, "Invalid UUID");
6
7
  //# sourceMappingURL=UUID.js.map
@@ -1,2 +1,11 @@
1
1
  import { Node } from "../../core/Node";
2
+ /**
3
+ * STXT-SCHEMA-SPEC 9.5: effective value for the INLINE/BLOCK binary types
4
+ * (HEXADECIMAL, BINARY, BASE64). In BLOCK form, validation applies to the
5
+ * concatenation of the lines of the block, ignoring line breaks, empty lines
6
+ * and the leading and trailing spaces or tabs of each line.
7
+ *
8
+ * @param node node whose value is wanted.
9
+ * @returns the inline value, or the lines of the block already concatenated.
10
+ */
2
11
  export declare function binaryValue(node: Node): string;
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.binaryValue = binaryValue;
4
- // STXT-SCHEMA-SPEC 9.5: en la forma BLOCK la validación se aplica sobre la
5
- // concatenación de las líneas del bloque, ignorando saltos de línea, líneas
6
- // vacías y espacios o tabuladores iniciales y finales de cada línea.
4
+ /**
5
+ * STXT-SCHEMA-SPEC 9.5: effective value for the INLINE/BLOCK binary types
6
+ * (HEXADECIMAL, BINARY, BASE64). In BLOCK form, validation applies to the
7
+ * concatenation of the lines of the block, ignoring line breaks, empty lines
8
+ * and the leading and trailing spaces or tabs of each line.
9
+ *
10
+ * @param node node whose value is wanted.
11
+ * @returns the inline value, or the lines of the block already concatenated.
12
+ */
7
13
  function binaryValue(node) {
8
14
  if (!node.isTextNode()) {
9
15
  return node.getValue();
@@ -1,2 +1,10 @@
1
1
  import { Type } from "../Type";
2
+ /**
3
+ * Base builder for the simple value types, those checked with a regular expression.
4
+ *
5
+ * @param name name of the type, as used in the schemas (e.g. `"DATE"`).
6
+ * @param pattern regular expression the value has to match.
7
+ * @param error message of the error thrown when the value does not match.
8
+ * @returns the {@link Type} that validates the value against that pattern.
9
+ */
2
10
  export declare function regexType(name: string, pattern: RegExp, error: string): Type;
@@ -2,11 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.regexType = regexType;
4
4
  const ValidationException_1 = require("../../exceptions/ValidationException");
5
+ /**
6
+ * Base builder for the simple value types, those checked with a regular expression.
7
+ *
8
+ * @param name name of the type, as used in the schemas (e.g. `"DATE"`).
9
+ * @param pattern regular expression the value has to match.
10
+ * @param error message of the error thrown when the value does not match.
11
+ * @returns the {@link Type} that validates the value against that pattern.
12
+ */
5
13
  function regexType(name, pattern, error) {
6
14
  return {
7
15
  getName: () => name,
8
16
  validate(nodeDef, node) {
9
- // Forma del valor INLINE (STXT-SCHEMA-SPEC 9.3/9.4): no admite bloque '>>'
17
+ // INLINE value form (STXT-SCHEMA-SPEC 9.3/9.4): the block '>>' form is not allowed
10
18
  if (node.isTextNode()) {
11
19
  throw new ValidationException_1.ValidationException(node.getLine(), "NOT_ALLOWED_TEXT", `Not allowed text in node ${node.getQualifiedName()}`);
12
20
  }
@@ -1,12 +1,26 @@
1
+ /** A child definition line inside an `@stxt.template`: type, cardinality and allowed values. */
1
2
  export declare class ChildLine {
2
3
  private readonly min;
3
4
  private readonly max;
4
5
  private readonly values;
5
6
  private readonly type;
7
+ /**
8
+ * Creates the already parsed content of a definition line.
9
+ *
10
+ * @param type declared type, or null if the line declares none.
11
+ * @param min minimum cardinality, or null if there is no minimum.
12
+ * @param max maximum cardinality, or null if there is no maximum.
13
+ * @param values values declared between brackets, or null if the line has no brackets at all.
14
+ */
6
15
  constructor(type: string | null, min: number | null, max: number | null, values: string[] | null);
16
+ /** @returns the declared type, or null if the line declares none. */
7
17
  getType(): string | null;
18
+ /** @returns the minimum cardinality, or null if there is no minimum. */
8
19
  getMin(): number | null;
20
+ /** @returns the maximum cardinality, or null if there is no maximum. */
9
21
  getMax(): number | null;
22
+ /** @returns the values declared between brackets, or null if the line has no brackets at all. */
10
23
  getValues(): string[] | null;
24
+ /** @returns a readable representation of the line, for debugging. */
11
25
  toString(): string;
12
26
  }
@@ -1,25 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChildLine = void 0;
4
+ /** A child definition line inside an `@stxt.template`: type, cardinality and allowed values. */
4
5
  class ChildLine {
6
+ /**
7
+ * Creates the already parsed content of a definition line.
8
+ *
9
+ * @param type declared type, or null if the line declares none.
10
+ * @param min minimum cardinality, or null if there is no minimum.
11
+ * @param max maximum cardinality, or null if there is no maximum.
12
+ * @param values values declared between brackets, or null if the line has no brackets at all.
13
+ */
5
14
  constructor(type, min, max, values) {
6
15
  this.type = type;
7
16
  this.min = min;
8
17
  this.max = max;
9
18
  this.values = values;
10
19
  }
20
+ /** @returns the declared type, or null if the line declares none. */
11
21
  getType() {
12
22
  return this.type;
13
23
  }
24
+ /** @returns the minimum cardinality, or null if there is no minimum. */
14
25
  getMin() {
15
26
  return this.min;
16
27
  }
28
+ /** @returns the maximum cardinality, or null if there is no maximum. */
17
29
  getMax() {
18
30
  return this.max;
19
31
  }
32
+ /** @returns the values declared between brackets, or null if the line has no brackets at all. */
20
33
  getValues() {
21
34
  return this.values;
22
35
  }
36
+ /** @returns a readable representation of the line, for debugging. */
23
37
  toString() {
24
38
  return `ChildLine [type=${this.type}, min=${this.min}, max=${this.max}, values=${this.values ? `[${this.values.join(", ")}]` : "null"}]`;
25
39
  }
@@ -1,7 +1,17 @@
1
1
  import { ChildLine } from "./ChildLine";
2
+ /** Parses the inline value of a child node inside an `@stxt.template`, shaped as `(min,max) TYPE [values]`. */
2
3
  export declare class ChildLineParser {
3
4
  private constructor();
4
5
  private static readonly CHILD_LINE_PATTERN;
6
+ /**
7
+ * Parses a definition line into its type, its cardinality and its allowed values.
8
+ *
9
+ * @param rawLine inline value of the node, `(min,max) TYPE [values]`.
10
+ * @param lineNumber line number, for the error messages.
11
+ * @returns the line already split into type, cardinality and values.
12
+ * @throws ValidationException with code `INVALID_CHILD_LINE`, `INVALID_CHILD_COUNT`,
13
+ * `MIN_GREATER_THAN_MAX` or `VALUE_DUPLICATED` if the line is not valid.
14
+ */
5
15
  static parse(rawLine: string, lineNumber: number): ChildLine;
6
16
  private static parseCount;
7
17
  }
@@ -3,8 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChildLineParser = void 0;
4
4
  const ValidationException_1 = require("../exceptions/ValidationException");
5
5
  const ChildLine_1 = require("./ChildLine");
6
+ /** Parses the inline value of a child node inside an `@stxt.template`, shaped as `(min,max) TYPE [values]`. */
6
7
  class ChildLineParser {
7
8
  constructor() { }
9
+ /**
10
+ * Parses a definition line into its type, its cardinality and its allowed values.
11
+ *
12
+ * @param rawLine inline value of the node, `(min,max) TYPE [values]`.
13
+ * @param lineNumber line number, for the error messages.
14
+ * @returns the line already split into type, cardinality and values.
15
+ * @throws ValidationException with code `INVALID_CHILD_LINE`, `INVALID_CHILD_COUNT`,
16
+ * `MIN_GREATER_THAN_MAX` or `VALUE_DUPLICATED` if the line is not valid.
17
+ */
8
18
  static parse(rawLine, lineNumber) {
9
19
  if (rawLine.trim().length === 0) {
10
20
  return new ChildLine_1.ChildLine(null, null, null, null);
@@ -48,7 +58,7 @@ class ChildLineParser {
48
58
  }
49
59
  const aNum = ChildLineParser.parseCount(parts[0].trim(), count, rawLine, lineNumber);
50
60
  const bNum = ChildLineParser.parseCount(parts[1].trim(), count, rawLine, lineNumber);
51
- // Cardinalidad inválida si min > max (STXT-TEMPLATE-SPEC 7.1)
61
+ // Invalid cardinality when min > max (STXT-TEMPLATE-SPEC 7.1)
52
62
  if (aNum > bNum) {
53
63
  throw new ValidationException_1.ValidationException(lineNumber, "MIN_GREATER_THAN_MAX", `Min ${aNum} greater than Max ${bNum} in line: ${rawLine}`);
54
64
  }
@@ -75,17 +85,16 @@ class ChildLineParser {
75
85
  }
76
86
  list.push(part);
77
87
  }
78
- // Los corchetes presentes (aunque vengan vacíos, "[]") cuentan como una definición
79
- // explícita de valores: se devuelve un array no-nulo (posiblemente vacío) para
80
- // distinguirlo de la ausencia total de corchetes (valuesStr null/undefined, values
81
- // permanece null). Así "[]" se trata como redefinición/definición real (ported
82
- // from stxt-java).
88
+ // Brackets being there (even empty ones, "[]") count as an explicit definition of
89
+ // values: a non-null array is returned (possibly empty) to tell it apart from having
90
+ // no brackets at all (valuesStr null/undefined, values stays null). That way "[]" is
91
+ // treated as a real definition/redefinition (ported from stxt-java).
83
92
  values = list;
84
93
  }
85
- // type es string|null en nuestra clase
94
+ // type is string|null in our class
86
95
  return new ChildLine_1.ChildLine(type ?? null, min, max, values);
87
96
  }
88
- // num, min y max deben ser enteros no negativos, sin texto sobrante (STXT-TEMPLATE-SPEC 7.1)
97
+ // num, min and max must be non-negative integers, with no trailing text (STXT-TEMPLATE-SPEC 7.1)
89
98
  static parseCount(num, count, rawLine, lineNumber) {
90
99
  if (!/^\d+$/.test(num)) {
91
100
  throw new ValidationException_1.ValidationException(lineNumber, "INVALID_CHILD_COUNT", `Invalid count ${count} in line: ${rawLine}`);
@@ -1,8 +1,24 @@
1
1
  import { Schema } from "../schema/Schema";
2
2
  import { SchemaProvider } from "../schema/SchemaProvider";
3
+ /**
4
+ * {@link SchemaProvider} that defines in code the meta-schema of the template language itself
5
+ * (`@stxt.template`), so that a loaded template can validate itself.
6
+ */
3
7
  export declare class MetaTemplateSchemaProvider implements SchemaProvider {
4
8
  private static readonly META_TEXT;
5
9
  private readonly meta;
10
+ /**
11
+ * Parses the meta-template and keeps the schema it produces ready to be served.
12
+ *
13
+ * @throws ValidationException with code `META_SCHEMA_INVALID` if the meta-template does not produce exactly one document.
14
+ */
6
15
  constructor();
16
+ /**
17
+ * Serves the meta-schema of the template language.
18
+ *
19
+ * @param namespace namespace whose schema is wanted; only `@stxt.template` is served.
20
+ * @returns the meta-schema of the template language.
21
+ * @throws RuntimeException with code `RESOURCE_NOT_FOUND` if any other namespace is asked for.
22
+ */
7
23
  getSchema(namespace: string): Schema;
8
24
  }
@@ -5,7 +5,16 @@ const Parser_1 = require("../core/Parser");
5
5
  const ValidationException_1 = require("../exceptions/ValidationException");
6
6
  const RuntimeException_1 = require("../exceptions/RuntimeException");
7
7
  const TemplateParser_1 = require("./TemplateParser");
8
+ /**
9
+ * {@link SchemaProvider} that defines in code the meta-schema of the template language itself
10
+ * (`@stxt.template`), so that a loaded template can validate itself.
11
+ */
8
12
  class MetaTemplateSchemaProvider {
13
+ /**
14
+ * Parses the meta-template and keeps the schema it produces ready to be served.
15
+ *
16
+ * @throws ValidationException with code `META_SCHEMA_INVALID` if the meta-template does not produce exactly one document.
17
+ */
9
18
  constructor() {
10
19
  const parser = new Parser_1.Parser();
11
20
  const nodes = parser.parse(MetaTemplateSchemaProvider.META_TEXT);
@@ -14,11 +23,18 @@ class MetaTemplateSchemaProvider {
14
23
  }
15
24
  this.meta = (0, TemplateParser_1.transformTemplateNodeToSchema)(nodes[0]);
16
25
  }
26
+ /**
27
+ * Serves the meta-schema of the template language.
28
+ *
29
+ * @param namespace namespace whose schema is wanted; only `@stxt.template` is served.
30
+ * @returns the meta-schema of the template language.
31
+ * @throws RuntimeException with code `RESOURCE_NOT_FOUND` if any other namespace is asked for.
32
+ */
17
33
  getSchema(namespace) {
18
34
  if (namespace !== "@stxt.template") {
19
35
  throw new RuntimeException_1.RuntimeException("RESOURCE_NOT_FOUND", `Not found '${namespace}' in namespace: @stxt.template`);
20
36
  }
21
- // meta siempre existe si el constructor terminó, pero lo dejamos equivalente al Java
37
+ // meta always exists once the constructor finished, but this mirrors the Java version
22
38
  if (!this.meta) {
23
39
  throw new ValidationException_1.ValidationException(0, "META_SCHEMA_NOT_AVAILABLE", "Meta schema not available");
24
40
  }
@@ -1,3 +1,11 @@
1
1
  import { Node } from "../core/Node";
2
2
  import { Schema } from "../schema/Schema";
3
+ /**
4
+ * Turns the tree of an already parsed `@stxt.template` document into an equivalent {@link Schema}.
5
+ *
6
+ * @param node root of the already parsed `@stxt.template` document.
7
+ * @returns the resulting {@link Schema}.
8
+ * @throws ValidationException if the template is not valid, with the line already shifted to the
9
+ * one of the original document.
10
+ */
3
11
  export declare function transformTemplateNodeToSchema(node: Node): Schema;