@driftsys/markspec 0.2.0 → 0.4.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 +32 -8
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +19 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +139 -29
- package/esm/mod.d.ts +11 -7
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +6 -3
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +257 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +28 -1
- package/esm/model/palette.d.ts +18 -0
- package/esm/model/palette.d.ts.map +1 -0
- package/esm/model/palette.js +23 -0
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.js +11 -2
- package/esm/parser/markdown.d.ts +21 -7
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +101 -40
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +40 -10
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +21 -14
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/colors.d.ts +26 -0
- package/esm/profile/colors.d.ts.map +1 -0
- package/esm/profile/colors.js +46 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +815 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +24 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +15 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.js +14 -27
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +1 -1
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +19 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +140 -29
- package/script/mod.d.ts +11 -7
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +50 -19
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +257 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +37 -2
- package/script/model/palette.d.ts +18 -0
- package/script/model/palette.d.ts.map +1 -0
- package/script/model/palette.js +26 -0
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.js +11 -2
- package/script/parser/markdown.d.ts +21 -7
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +100 -39
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +42 -11
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +21 -14
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/colors.d.ts +26 -0
- package/script/profile/colors.d.ts.map +1 -0
- package/script/profile/colors.js +49 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +818 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +24 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +33 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.js +14 -27
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/types
|
|
4
|
+
*
|
|
5
|
+
* Validator Stage 2 — entry classification.
|
|
6
|
+
*
|
|
7
|
+
* Each entry is assigned a profile-declared type either by an explicit
|
|
8
|
+
* `Type:` trailer attribute or by display-ID pattern matching. Un-classified
|
|
9
|
+
* entries in a strict profile (types declared) produce MSL-T003.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.classifyEntry = classifyEntry;
|
|
13
|
+
exports.classifyEntriesStage = classifyEntriesStage;
|
|
14
|
+
const pattern_js_1 = require("./pattern.js");
|
|
15
|
+
/**
|
|
16
|
+
* Classify one {@linkcode Entry} against the profile's type vocabulary.
|
|
17
|
+
*
|
|
18
|
+
* Order of precedence:
|
|
19
|
+
* 1. Explicit `Type:` trailer attribute (if present).
|
|
20
|
+
* 2. Display-ID pattern match across types whose `shape` matches
|
|
21
|
+
* `entry.shape`.
|
|
22
|
+
*
|
|
23
|
+
* Emits:
|
|
24
|
+
* - `MSL-T001` when explicit `Type:` value is not in the profile's type
|
|
25
|
+
* vocabulary.
|
|
26
|
+
* - `MSL-T002` when the display ID matches more than one type's pattern.
|
|
27
|
+
* - `MSL-T003` when strict mode (types declared) and no classification
|
|
28
|
+
* could be assigned.
|
|
29
|
+
*/
|
|
30
|
+
function classifyEntry(entry, profile) {
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
// 1. Explicit Type: trailer?
|
|
33
|
+
const explicitType = findExplicitTypeAttribute(entry);
|
|
34
|
+
if (explicitType !== undefined) {
|
|
35
|
+
if (profile.types.has(explicitType)) {
|
|
36
|
+
return { type: explicitType, diagnostics };
|
|
37
|
+
}
|
|
38
|
+
diagnostics.push({
|
|
39
|
+
code: "MSL-T001",
|
|
40
|
+
severity: "error",
|
|
41
|
+
message: `${entry.displayId}: explicit Type: '${explicitType}' is not a declared type`,
|
|
42
|
+
location: entry.location,
|
|
43
|
+
});
|
|
44
|
+
return { type: undefined, diagnostics };
|
|
45
|
+
}
|
|
46
|
+
// 2. Display-ID pattern match across same-shape types.
|
|
47
|
+
const matches = [];
|
|
48
|
+
for (const [typeName, typeEntry] of profile.types) {
|
|
49
|
+
if (typeEntry.value.shape !== entry.shape)
|
|
50
|
+
continue;
|
|
51
|
+
const pattern = typeEntry.value.displayIdPattern.value;
|
|
52
|
+
if (pattern === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
const regex = (0, pattern_js_1.compileDisplayIdPattern)(pattern);
|
|
55
|
+
if (regex.test(entry.displayId)) {
|
|
56
|
+
matches.push(typeName);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (matches.length === 1) {
|
|
60
|
+
return { type: matches[0], diagnostics };
|
|
61
|
+
}
|
|
62
|
+
if (matches.length > 1) {
|
|
63
|
+
diagnostics.push({
|
|
64
|
+
code: "MSL-T002",
|
|
65
|
+
severity: "error",
|
|
66
|
+
message: `${entry.displayId}: display ID matches multiple type patterns ` +
|
|
67
|
+
`(${matches.join(", ")}); add an explicit 'Type:' trailer to disambiguate`,
|
|
68
|
+
location: entry.location,
|
|
69
|
+
});
|
|
70
|
+
return { type: undefined, diagnostics };
|
|
71
|
+
}
|
|
72
|
+
// 0 matches. Strict mode → MSL-T003; permissive → OK.
|
|
73
|
+
if (profile.types.size > 0) {
|
|
74
|
+
diagnostics.push({
|
|
75
|
+
code: "MSL-T003",
|
|
76
|
+
severity: "error",
|
|
77
|
+
message: `${entry.displayId}: un-classified entry ` +
|
|
78
|
+
`(profile declares ${profile.types.size} types; display ID matched none)`,
|
|
79
|
+
location: entry.location,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return { type: undefined, diagnostics };
|
|
83
|
+
}
|
|
84
|
+
function findExplicitTypeAttribute(entry) {
|
|
85
|
+
for (const attr of entry.rawAttributes) {
|
|
86
|
+
if (attr.key === "Type") {
|
|
87
|
+
return attr.value.trim();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Run classification across all entries. Produces new {@linkcode Entry}
|
|
94
|
+
* objects with `type` set when classification succeeds; un-classified
|
|
95
|
+
* entries pass through with `type` unchanged.
|
|
96
|
+
*
|
|
97
|
+
* Also emits `MSL-T004` when a classified entry's display ID violates the
|
|
98
|
+
* type's `display-id-pattern-enforcement` level.
|
|
99
|
+
*/
|
|
100
|
+
function classifyEntriesStage(entries, profile) {
|
|
101
|
+
const diagnostics = [];
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const classified = classifyEntry(entry, profile);
|
|
105
|
+
diagnostics.push(...classified.diagnostics);
|
|
106
|
+
if (classified.type !== undefined) {
|
|
107
|
+
const typeEntry = profile.types.get(classified.type);
|
|
108
|
+
if (typeEntry !== undefined) {
|
|
109
|
+
const enforceDiag = checkEnforcement(entry, typeEntry);
|
|
110
|
+
if (enforceDiag !== undefined) {
|
|
111
|
+
diagnostics.push(enforceDiag);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
out.push({ ...entry, type: classified.type });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
out.push(entry);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { entries: out, diagnostics };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* If the classified type declares a display-id-pattern and the entry's
|
|
124
|
+
* display ID doesn't match it, emit an MSL-T004 at the configured severity.
|
|
125
|
+
* Returns `undefined` when the display ID matches or enforcement is `off`.
|
|
126
|
+
*/
|
|
127
|
+
function checkEnforcement(entry, typeEntry) {
|
|
128
|
+
const pattern = typeEntry.value.displayIdPattern.value;
|
|
129
|
+
if (pattern === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
const level = typeEntry.value.displayIdPatternEnforcement.value;
|
|
132
|
+
if (level === "off")
|
|
133
|
+
return undefined;
|
|
134
|
+
const regex = (0, pattern_js_1.compileDisplayIdPattern)(pattern);
|
|
135
|
+
if (regex.test(entry.displayId))
|
|
136
|
+
return undefined;
|
|
137
|
+
return {
|
|
138
|
+
code: "MSL-T004",
|
|
139
|
+
severity: level === "error" ? "error" : "warning",
|
|
140
|
+
message: `${entry.displayId}: display ID doesn't match pattern ` +
|
|
141
|
+
`'${pattern}' for type '${typeEntry.value.name}'`,
|
|
142
|
+
location: entry.location,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/validator/value_types
|
|
3
|
+
*
|
|
4
|
+
* Per-type value validators for profile-declared attributes. Each validator
|
|
5
|
+
* takes a string value and the attribute's declaration, returns `null` when
|
|
6
|
+
* valid or a short error message explaining why it's invalid.
|
|
7
|
+
*
|
|
8
|
+
* The top-level {@linkcode validateValue} dispatches on the declared type.
|
|
9
|
+
*/
|
|
10
|
+
import type { AttrDecl } from "../model/mod.js";
|
|
11
|
+
/**
|
|
12
|
+
* Validate one string value against an attribute's declared value type.
|
|
13
|
+
* Returns `null` when the value is valid, or a short human-readable detail
|
|
14
|
+
* string (without the attribute name or display ID — the caller composes the
|
|
15
|
+
* full diagnostic message).
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateValue(value: string, decl: AttrDecl): string | null;
|
|
18
|
+
/** Signature for a single value-type validator. */
|
|
19
|
+
export type ValueValidator = (value: string, decl: AttrDecl) => string | null;
|
|
20
|
+
//# sourceMappingURL=value_types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value_types.d.ts","sourceRoot":"","sources":["../../src/validator/value_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAG3D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAG1E;AAED,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,MAAM,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/value_types
|
|
4
|
+
*
|
|
5
|
+
* Per-type value validators for profile-declared attributes. Each validator
|
|
6
|
+
* takes a string value and the attribute's declaration, returns `null` when
|
|
7
|
+
* valid or a short error message explaining why it's invalid.
|
|
8
|
+
*
|
|
9
|
+
* The top-level {@linkcode validateValue} dispatches on the declared type.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.validateValue = validateValue;
|
|
13
|
+
const mod_js_1 = require("../model/mod.js");
|
|
14
|
+
/**
|
|
15
|
+
* Validate one string value against an attribute's declared value type.
|
|
16
|
+
* Returns `null` when the value is valid, or a short human-readable detail
|
|
17
|
+
* string (without the attribute name or display ID — the caller composes the
|
|
18
|
+
* full diagnostic message).
|
|
19
|
+
*/
|
|
20
|
+
function validateValue(value, decl) {
|
|
21
|
+
const fn = VALIDATORS[decl.type];
|
|
22
|
+
return fn(value, decl);
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Individual validators (Task 6.3 simple types)
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
const validateText = (_value, _decl) => {
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
const INTEGER_RE = /^-?\d+$/;
|
|
31
|
+
const validateInteger = (value, _decl) => {
|
|
32
|
+
return INTEGER_RE.test(value)
|
|
33
|
+
? null
|
|
34
|
+
: `not a valid integer: '${value}' (expected digits optionally prefixed with '-')`;
|
|
35
|
+
};
|
|
36
|
+
const validateBoolean = (value, _decl) => {
|
|
37
|
+
return value === "true" || value === "false"
|
|
38
|
+
? null
|
|
39
|
+
: `not a valid boolean: '${value}' (expected 'true' or 'false')`;
|
|
40
|
+
};
|
|
41
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
42
|
+
const validateDate = (value, _decl) => {
|
|
43
|
+
return DATE_RE.test(value)
|
|
44
|
+
? null
|
|
45
|
+
: `not a valid ISO 8601 date: '${value}' (expected YYYY-MM-DD)`;
|
|
46
|
+
};
|
|
47
|
+
const validateEnum = (value, decl) => {
|
|
48
|
+
const values = decl.values ?? [];
|
|
49
|
+
if (values.includes(value))
|
|
50
|
+
return null;
|
|
51
|
+
return `value '${value}' is not in declared enum [${values.join(", ")}]`;
|
|
52
|
+
};
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Individual validators (Task 6.4 ID/URI types)
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
const validateId = (value, _decl) => {
|
|
57
|
+
if (mod_js_1.ULID_RE.test(value))
|
|
58
|
+
return null;
|
|
59
|
+
if (mod_js_1.URI_SCHEME_RE.test(value))
|
|
60
|
+
return null;
|
|
61
|
+
return `not a valid id: '${value}' (expected 26-char ULID or scheme-qualified URI)`;
|
|
62
|
+
};
|
|
63
|
+
const HTTP_URL_RE = /^https?:\/\//;
|
|
64
|
+
const validateUrl = (value, _decl) => {
|
|
65
|
+
return HTTP_URL_RE.test(value) ? null : `not a valid http(s) URL: '${value}'`;
|
|
66
|
+
};
|
|
67
|
+
const validateUri = (value, _decl) => {
|
|
68
|
+
return mod_js_1.URI_SCHEME_RE.test(value)
|
|
69
|
+
? null
|
|
70
|
+
: `not a valid URI: '${value}' (expected scheme-qualified per RFC 3986)`;
|
|
71
|
+
};
|
|
72
|
+
const validateExternalId = (value, _decl) => {
|
|
73
|
+
return value.trim().length > 0
|
|
74
|
+
? null
|
|
75
|
+
: `external-id cannot be empty or whitespace-only`;
|
|
76
|
+
};
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Individual validators (Task 6.5 path / list / citation types)
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// `/absolute` (POSIX) or `C:` / `C:\` / `C:/` (Windows) → absolute.
|
|
81
|
+
const ABSOLUTE_RE = /^(\/|[A-Za-z]:[\\/]?)/;
|
|
82
|
+
const validatePath = (value, _decl) => {
|
|
83
|
+
if (value.length === 0)
|
|
84
|
+
return `path cannot be empty`;
|
|
85
|
+
if (ABSOLUTE_RE.test(value)) {
|
|
86
|
+
return `absolute paths are not allowed: '${value}' (use a relative path)`;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
const validatePathOrId = (value, decl) => {
|
|
91
|
+
if (mod_js_1.ULID_RE.test(value))
|
|
92
|
+
return null;
|
|
93
|
+
if (mod_js_1.URI_SCHEME_RE.test(value))
|
|
94
|
+
return null;
|
|
95
|
+
return validatePath(value, decl);
|
|
96
|
+
};
|
|
97
|
+
const TAG_RE = /^[A-Za-z0-9_\-.]+$/;
|
|
98
|
+
const validateTagList = (value, _decl) => {
|
|
99
|
+
if (value.length === 0)
|
|
100
|
+
return `tag cannot be empty`;
|
|
101
|
+
return TAG_RE.test(value)
|
|
102
|
+
? null
|
|
103
|
+
: `invalid tag '${value}' (expected bareword of letters, digits, '_', '-', '.')`;
|
|
104
|
+
};
|
|
105
|
+
const validateCitation = (value, _decl) => {
|
|
106
|
+
return value.trim().length > 0
|
|
107
|
+
? null
|
|
108
|
+
: `citation cannot be empty or whitespace-only`;
|
|
109
|
+
};
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Registry — all 14 value types are now implemented.
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
/** Registry of per-type validators. */
|
|
114
|
+
const VALIDATORS = {
|
|
115
|
+
text: validateText,
|
|
116
|
+
integer: validateInteger,
|
|
117
|
+
boolean: validateBoolean,
|
|
118
|
+
date: validateDate,
|
|
119
|
+
enum: validateEnum,
|
|
120
|
+
id: validateId,
|
|
121
|
+
"id-list": validateId,
|
|
122
|
+
uri: validateUri,
|
|
123
|
+
url: validateUrl,
|
|
124
|
+
"external-id": validateExternalId,
|
|
125
|
+
path: validatePath,
|
|
126
|
+
"path-or-id": validatePathOrId,
|
|
127
|
+
"tag-list": validateTagList,
|
|
128
|
+
citation: validateCitation,
|
|
129
|
+
};
|