@stxt-lang/core 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -1
- package/out/all.d.ts +5 -0
- package/out/all.js +10 -4
- package/out/core/Constants.d.ts +8 -0
- package/out/core/Constants.js +8 -0
- package/out/core/Line.d.ts +20 -0
- package/out/core/Line.js +15 -0
- package/out/core/LineParser.d.ts +17 -0
- package/out/core/LineParser.js +27 -10
- package/out/core/NameNamespace.d.ts +9 -0
- package/out/core/NameNamespace.js +9 -0
- package/out/core/NameNamespaceParser.d.ts +11 -0
- package/out/core/NameNamespaceParser.js +16 -5
- package/out/core/NamespaceValidator.d.ts +18 -0
- package/out/core/NamespaceValidator.js +18 -0
- package/out/core/Node.d.ts +55 -0
- package/out/core/Node.js +56 -1
- package/out/core/NodeCreator.d.ts +11 -0
- package/out/core/NodeCreator.js +14 -3
- package/out/core/ParseResult.d.ts +26 -0
- package/out/core/ParseResult.js +26 -0
- package/out/core/Parser.d.ts +31 -0
- package/out/core/Parser.js +50 -19
- package/out/core/StringUtils.d.ts +31 -0
- package/out/core/StringUtils.js +40 -9
- package/out/discovery/DiscoveryEnvironment.d.ts +35 -0
- package/out/discovery/DiscoveryEnvironment.js +3 -0
- package/out/discovery/DiscoveryError.d.ts +30 -0
- package/out/discovery/DiscoveryError.js +36 -0
- package/out/discovery/DiscoveryFileSystem.d.ts +57 -0
- package/out/discovery/DiscoveryFileSystem.js +3 -0
- package/out/discovery/DiscoveryResolver.d.ts +74 -0
- package/out/discovery/DiscoveryResolver.js +232 -0
- package/out/discovery/DiscoveryResult.d.ts +94 -0
- package/out/discovery/DiscoveryResult.js +111 -0
- package/out/exceptions/ParseException.d.ts +14 -0
- package/out/exceptions/ParseException.js +12 -0
- package/out/exceptions/RuntimeException.d.ts +14 -0
- package/out/exceptions/RuntimeException.js +13 -0
- package/out/exceptions/ValidationException.d.ts +8 -0
- package/out/exceptions/ValidationException.js +8 -0
- package/out/processors/Observer.d.ts +29 -0
- package/out/processors/Validator.d.ts +9 -0
- package/out/runtime/ConditionalValidator.d.ts +15 -0
- package/out/runtime/ConditionalValidator.js +16 -2
- package/out/runtime/NodeWriter.d.ts +18 -0
- package/out/runtime/NodeWriter.js +18 -0
- package/out/runtime/UnifiedSchemaProvider.d.ts +23 -5
- package/out/runtime/UnifiedSchemaProvider.js +28 -10
- package/out/schema/ChildDefinition.d.ts +18 -0
- package/out/schema/ChildDefinition.js +18 -0
- package/out/schema/NodeDefinition.d.ts +44 -0
- package/out/schema/NodeDefinition.js +47 -3
- package/out/schema/Schema.d.ts +26 -0
- package/out/schema/Schema.js +26 -1
- package/out/schema/SchemaParser.d.ts +7 -0
- package/out/schema/SchemaParser.js +26 -16
- package/out/schema/SchemaProvider.d.ts +7 -0
- package/out/schema/SchemaProviderMemory.d.ts +27 -0
- package/out/schema/SchemaProviderMemory.js +27 -0
- package/out/schema/SchemaProviderMeta.d.ts +16 -0
- package/out/schema/SchemaProviderMeta.js +16 -0
- package/out/schema/SchemaValidator.d.ts +20 -0
- package/out/schema/SchemaValidator.js +27 -7
- package/out/schema/Type.d.ts +9 -0
- package/out/schema/TypeRegistry.d.ts +13 -0
- package/out/schema/TypeRegistry.js +18 -5
- package/out/schema/type/BASE64.d.ts +1 -0
- package/out/schema/type/BASE64.js +5 -4
- package/out/schema/type/BINARY.d.ts +1 -0
- package/out/schema/type/BINARY.js +2 -1
- package/out/schema/type/BLOCK.d.ts +1 -0
- package/out/schema/type/BLOCK.js +2 -1
- package/out/schema/type/BOOLEAN.d.ts +1 -0
- package/out/schema/type/BOOLEAN.js +1 -0
- package/out/schema/type/DATE.d.ts +1 -0
- package/out/schema/type/DATE.js +1 -0
- package/out/schema/type/EMAIL.d.ts +1 -0
- package/out/schema/type/EMAIL.js +1 -0
- package/out/schema/type/ENUM.d.ts +1 -0
- package/out/schema/type/ENUM.js +2 -1
- package/out/schema/type/GROUP.d.ts +1 -0
- package/out/schema/type/GROUP.js +2 -1
- package/out/schema/type/HEXADECIMAL.d.ts +1 -0
- package/out/schema/type/HEXADECIMAL.js +2 -1
- package/out/schema/type/INLINE.d.ts +1 -0
- package/out/schema/type/INLINE.js +2 -1
- package/out/schema/type/INTEGER.d.ts +1 -0
- package/out/schema/type/INTEGER.js +1 -0
- package/out/schema/type/MARKDOWN.d.ts +4 -0
- package/out/schema/type/MARKDOWN.js +4 -2
- package/out/schema/type/NATURAL.d.ts +1 -0
- package/out/schema/type/NATURAL.js +1 -0
- package/out/schema/type/NUMBER.d.ts +1 -0
- package/out/schema/type/NUMBER.js +1 -0
- package/out/schema/type/TEXT.d.ts +1 -0
- package/out/schema/type/TEXT.js +1 -0
- package/out/schema/type/TIME.d.ts +1 -0
- package/out/schema/type/TIME.js +1 -0
- package/out/schema/type/TIMESTAMP.d.ts +1 -0
- package/out/schema/type/TIMESTAMP.js +1 -0
- package/out/schema/type/URL.d.ts +1 -0
- package/out/schema/type/URL.js +2 -1
- package/out/schema/type/UUID.d.ts +1 -0
- package/out/schema/type/UUID.js +1 -0
- package/out/schema/type/binaryValue.d.ts +9 -0
- package/out/schema/type/binaryValue.js +9 -3
- package/out/schema/type/regexType.d.ts +8 -0
- package/out/schema/type/regexType.js +9 -1
- package/out/template/ChildLine.d.ts +14 -0
- package/out/template/ChildLine.js +14 -0
- package/out/template/ChildLineParser.d.ts +10 -0
- package/out/template/ChildLineParser.js +17 -8
- package/out/template/MetaTemplateSchemaProvider.d.ts +16 -0
- package/out/template/MetaTemplateSchemaProvider.js +17 -1
- package/out/template/TemplateParser.d.ts +8 -0
- package/out/template/TemplateParser.js +49 -39
- package/out/template/TemplateSchemaProviderMemory.d.ts +18 -0
- package/out/template/TemplateSchemaProviderMemory.js +21 -3
- package/package.json +2 -1
|
@@ -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:
|
|
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
|
-
//
|
|
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
|
-
//
|
|
57
|
+
// Static initialization (no INSTANCE)
|
|
45
58
|
TypeRegistry._init = (() => {
|
|
46
|
-
//
|
|
59
|
+
// Main types
|
|
47
60
|
TypeRegistry.register(INLINE_1.INLINE);
|
|
48
61
|
TypeRegistry.register(BLOCK_1.BLOCK);
|
|
49
|
-
//
|
|
62
|
+
// Subtypes
|
|
50
63
|
TypeRegistry.register(TEXT_1.TEXT);
|
|
51
64
|
TypeRegistry.register(BOOLEAN_1.BOOLEAN);
|
|
52
65
|
TypeRegistry.register(URL_1.URL);
|
|
@@ -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
|
-
//
|
|
14
|
+
// Try to decode it
|
|
14
15
|
const buf = Buffer.from(raw, "base64");
|
|
15
|
-
// Re-encode
|
|
16
|
-
// (
|
|
16
|
+
// Re-encode to check consistency
|
|
17
|
+
// (this keeps partially valid strings out)
|
|
17
18
|
const reencoded = buf.toString("base64");
|
|
18
|
-
//
|
|
19
|
+
// Normalize the padding before comparing
|
|
19
20
|
const normalizedInput = raw.replace(/=+$/, "");
|
|
20
21
|
const normalizedReencoded = reencoded.replace(/=+$/, "");
|
|
21
22
|
if (normalizedInput !== normalizedReencoded) {
|
|
@@ -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:
|
|
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)) {
|
package/out/schema/type/BLOCK.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
}
|
|
@@ -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
|
package/out/schema/type/DATE.js
CHANGED
|
@@ -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
|
package/out/schema/type/EMAIL.js
CHANGED
|
@@ -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
|
package/out/schema/type/ENUM.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
}
|
package/out/schema/type/GROUP.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
}
|
|
@@ -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:
|
|
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)) {
|
|
@@ -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
|
-
//
|
|
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
|
}
|
|
@@ -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
|
|
@@ -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
|
-
|
|
6
|
-
|
|
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";
|
|
@@ -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
|
|
@@ -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
|
package/out/schema/type/TEXT.js
CHANGED
|
@@ -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";
|
package/out/schema/type/TIME.js
CHANGED
|
@@ -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
|
|
@@ -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
|
package/out/schema/type/URL.d.ts
CHANGED
package/out/schema/type/URL.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
}
|
package/out/schema/type/UUID.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
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
|
|
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
|
|
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
|
}
|