@agentshouse/mdmodel 0.1.0-cc9fa0498a7f7 → 0.1.0-ccf1367190878
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/API.md +135 -139
- package/dist/blocks.js +1 -1
- package/dist/condition.d.ts +0 -1
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +10 -7
- package/dist/definition.d.ts +14 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +215 -23
- package/dist/document.d.ts +4 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +68 -35
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +92 -12
- package/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/types.d.ts +25 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +5 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +146 -92
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +30 -18
- package/fixtures/README.md +1 -1
- package/package.json +4 -2
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { decodeNamedCharacterReference } from 'decode-named-character-reference';
|
|
2
|
+
import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
|
|
3
|
+
import { escapes } from './links.js';
|
|
1
4
|
export function dirname(path) {
|
|
2
5
|
const index = path.lastIndexOf('/');
|
|
3
6
|
return index === -1 ? '' : path.slice(0, index);
|
|
@@ -22,18 +25,95 @@ export function normalize(path) {
|
|
|
22
25
|
}
|
|
23
26
|
return parts.join('/');
|
|
24
27
|
}
|
|
28
|
+
const REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z][A-Za-z0-9]{0,31}));/y;
|
|
29
|
+
const PERCENT = /^%[0-9a-fA-F]{2}/;
|
|
30
|
+
function referenceAt(text, at) {
|
|
31
|
+
REFERENCE.lastIndex = at;
|
|
32
|
+
const match = REFERENCE.exec(text);
|
|
33
|
+
if (match === null)
|
|
34
|
+
return null;
|
|
35
|
+
const [whole, hex, decimal, name] = match;
|
|
36
|
+
const end = at + whole.length;
|
|
37
|
+
if (name !== undefined) {
|
|
38
|
+
const decoded = decodeNamedCharacterReference(name);
|
|
39
|
+
return decoded === false ? null : { text: decoded, end };
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
text: decodeNumericCharacterReference(hex ?? decimal, hex === undefined ? 10 : 16),
|
|
43
|
+
end,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function unescaped(written) {
|
|
47
|
+
let base = '';
|
|
48
|
+
let i = 0;
|
|
49
|
+
while (i < written.length) {
|
|
50
|
+
const escaped = escapes(written, i);
|
|
51
|
+
const reference = escaped || written[i] !== '&' ? null : referenceAt(written, i);
|
|
52
|
+
const text = escaped ? written[i + 1] : (reference?.text ?? written[i]);
|
|
53
|
+
if (text.startsWith('?') || text.startsWith('#'))
|
|
54
|
+
return { base, suffix: i };
|
|
55
|
+
base += text;
|
|
56
|
+
i = escaped ? i + 2 : (reference?.end ?? i + 1);
|
|
57
|
+
}
|
|
58
|
+
return { base, suffix: written.length };
|
|
59
|
+
}
|
|
60
|
+
function located(href) {
|
|
61
|
+
const written = href.trim();
|
|
62
|
+
const { base, suffix } = unescaped(written);
|
|
63
|
+
const url = base.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, '');
|
|
64
|
+
return { base: suffix === written.length ? url.replace(/[\u0000-\u0020]+$/, '') : url, suffix };
|
|
65
|
+
}
|
|
66
|
+
const ENCODED = /(?:%[0-9a-fA-F]{2})+/g;
|
|
67
|
+
function decodedRun(run) {
|
|
68
|
+
try {
|
|
69
|
+
return decodeURIComponent(run);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function destinationPath(href) {
|
|
76
|
+
const base = located(href).base;
|
|
77
|
+
let path = '';
|
|
78
|
+
let cursor = 0;
|
|
79
|
+
for (const match of base.matchAll(ENCODED)) {
|
|
80
|
+
const decoded = decodedRun(match[0]);
|
|
81
|
+
if (decoded === null)
|
|
82
|
+
return null;
|
|
83
|
+
path += base.slice(cursor, match.index) + decoded;
|
|
84
|
+
cursor = match.index + match[0].length;
|
|
85
|
+
}
|
|
86
|
+
return path + base.slice(cursor);
|
|
87
|
+
}
|
|
88
|
+
function written(path) {
|
|
89
|
+
let text = '';
|
|
90
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
91
|
+
const char = path[i];
|
|
92
|
+
if (char === '?' || char === '#' || char < ' ')
|
|
93
|
+
text += encodeURIComponent(char);
|
|
94
|
+
else if (char === ' ' && (i === 0 || i === path.length - 1))
|
|
95
|
+
text += '%20';
|
|
96
|
+
else if (char === '%' && PERCENT.test(path.slice(i)))
|
|
97
|
+
text += '%25';
|
|
98
|
+
else if (escapes(path, i))
|
|
99
|
+
text += '%5C';
|
|
100
|
+
else if (char === '&' && referenceAt(path, i) !== null)
|
|
101
|
+
text += '%26';
|
|
102
|
+
else
|
|
103
|
+
text += char;
|
|
104
|
+
}
|
|
105
|
+
return text;
|
|
106
|
+
}
|
|
25
107
|
export function classifyHref(from, href) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
108
|
+
const base = located(href).base;
|
|
109
|
+
if (base === '')
|
|
28
110
|
return { kind: 'skip' };
|
|
29
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(
|
|
111
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(base))
|
|
30
112
|
return { kind: 'skip' };
|
|
31
|
-
|
|
113
|
+
const path = destinationPath(href);
|
|
114
|
+
if (path === null || path.startsWith('/'))
|
|
32
115
|
return { kind: 'invalid' };
|
|
33
|
-
const
|
|
34
|
-
if (bare === '')
|
|
35
|
-
return { kind: 'skip' };
|
|
36
|
-
const resolved = normalize(join(dirname(from), bare));
|
|
116
|
+
const resolved = normalize(join(dirname(from), path));
|
|
37
117
|
if (resolved === null || resolved === '')
|
|
38
118
|
return { kind: 'invalid' };
|
|
39
119
|
return { kind: 'path', path: resolved };
|
|
@@ -44,8 +124,7 @@ export function target(from, href) {
|
|
|
44
124
|
}
|
|
45
125
|
export function retarget(href, to) {
|
|
46
126
|
const trimmed = href.trim();
|
|
47
|
-
|
|
48
|
-
return match === null ? to : to + trimmed.slice(match.index);
|
|
127
|
+
return written(to) + trimmed.slice(unescaped(trimmed).suffix);
|
|
49
128
|
}
|
|
50
129
|
export function relative(from, target) {
|
|
51
130
|
const base = dirname(from)
|
|
@@ -62,8 +141,9 @@ export function relative(from, target) {
|
|
|
62
141
|
export const SHELL_ROOMS = '/rooms/';
|
|
63
142
|
export function shellTarget(href, handle) {
|
|
64
143
|
const prefix = `${SHELL_ROOMS}${handle}/`;
|
|
65
|
-
|
|
144
|
+
const decoded = destinationPath(href);
|
|
145
|
+
if (decoded === null || !decoded.startsWith(prefix))
|
|
66
146
|
return null;
|
|
67
|
-
const path = normalize(
|
|
147
|
+
const path = normalize(decoded.slice(prefix.length));
|
|
68
148
|
return path === null || path === '' ? null : path;
|
|
69
149
|
}
|
package/dist/references.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function references(document:
|
|
2
|
+
import type { Frontmatter, Reference } from './types.js';
|
|
3
|
+
export declare function references(document: Pick<Frontmatter, 'fields'>, definition: Definition): readonly Reference[];
|
|
4
4
|
//# sourceMappingURL=references.d.ts.map
|
package/dist/references.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwBzD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EACrC,UAAU,EAAE,UAAU,GACrB,SAAS,SAAS,EAAE,CAItB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -28,10 +28,12 @@ export type Extent = {
|
|
|
28
28
|
export type Span = Extent & {
|
|
29
29
|
readonly text: string;
|
|
30
30
|
};
|
|
31
|
-
export type
|
|
31
|
+
export type Frontmatter = {
|
|
32
32
|
readonly content: string;
|
|
33
33
|
readonly type: string | undefined;
|
|
34
34
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
35
|
+
};
|
|
36
|
+
export type Document = Frontmatter & {
|
|
35
37
|
readonly preamble: string;
|
|
36
38
|
readonly sections: Readonly<Record<string, string>>;
|
|
37
39
|
};
|
|
@@ -41,6 +43,18 @@ export type Refusal = {
|
|
|
41
43
|
readonly location?: string;
|
|
42
44
|
readonly referrers?: readonly string[];
|
|
43
45
|
};
|
|
46
|
+
export type Reached = {
|
|
47
|
+
readonly target: string | null;
|
|
48
|
+
readonly to: readonly string[];
|
|
49
|
+
};
|
|
50
|
+
export type DocumentCheck = {
|
|
51
|
+
readonly ok: false;
|
|
52
|
+
} | {
|
|
53
|
+
readonly ok: true;
|
|
54
|
+
readonly type: string;
|
|
55
|
+
readonly typed: boolean;
|
|
56
|
+
readonly references: readonly Reached[];
|
|
57
|
+
};
|
|
44
58
|
export type Validation = {
|
|
45
59
|
readonly verdict: 'accept';
|
|
46
60
|
} | ({
|
|
@@ -60,6 +74,13 @@ export type Division = {
|
|
|
60
74
|
readonly ok: false;
|
|
61
75
|
readonly refusal: Refusal;
|
|
62
76
|
};
|
|
77
|
+
export type FrontmatterResult = {
|
|
78
|
+
readonly ok: true;
|
|
79
|
+
readonly frontmatter: Frontmatter;
|
|
80
|
+
} | {
|
|
81
|
+
readonly ok: false;
|
|
82
|
+
readonly refusal: Refusal;
|
|
83
|
+
};
|
|
63
84
|
export type ParseResult = {
|
|
64
85
|
readonly ok: true;
|
|
65
86
|
readonly document: Document;
|
|
@@ -71,6 +92,9 @@ export type Link = {
|
|
|
71
92
|
readonly href: string;
|
|
72
93
|
readonly target: string;
|
|
73
94
|
};
|
|
95
|
+
export type LinkOccurrence = Link & {
|
|
96
|
+
readonly start: number;
|
|
97
|
+
};
|
|
74
98
|
export type Reference = {
|
|
75
99
|
readonly pointer: string;
|
|
76
100
|
readonly value: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GAC7D;IACE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAA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MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEN,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Definition } from './definition.js';
|
|
2
|
+
import type { DocumentCheck, Library, ModelVerification, Reached, Validation, ValidationContext, VerifiedModel } from './types.js';
|
|
3
|
+
export declare function resolves(reference: Reached, typeOf: (path: string) => string | undefined, binary: (path: string) => boolean): boolean;
|
|
2
4
|
export declare function verify(schema: string): ModelVerification;
|
|
5
|
+
export declare function checkDocument(file: string, content: string, model: VerifiedModel): DocumentCheck;
|
|
6
|
+
export declare function sectionReferences(file: string, content: string, definition: Definition): readonly Reached[];
|
|
3
7
|
export declare function validate(library: Library, context?: ValidationContext, model?: VerifiedModel): Validation;
|
|
4
8
|
//# sourceMappingURL=validate.d.ts.map
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQzF,OAAO,KAAK,EAEV,aAAa,EAEb,OAAO,EACP,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AA6CpB,wBAAgB,QAAQ,CACtB,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,OAAO,CAET;AA8BD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQxD;AA2DD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAmBhG;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,UAAU,GACrB,SAAS,OAAO,EAAE,CAgBpB;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CA+DZ"}
|
package/dist/validate.js
CHANGED
|
@@ -18,25 +18,42 @@ function instanceType(document) {
|
|
|
18
18
|
return null;
|
|
19
19
|
return raw;
|
|
20
20
|
}
|
|
21
|
-
function reaches(
|
|
22
|
-
|
|
23
|
-
if (resolved.kind !== 'path')
|
|
21
|
+
function reaches(reference, typeOf, binary) {
|
|
22
|
+
if (reference.target === null)
|
|
24
23
|
return false;
|
|
25
|
-
if (to.includes(ATTACHMENT))
|
|
24
|
+
if (reference.to.includes(ATTACHMENT))
|
|
26
25
|
return true;
|
|
27
|
-
if (
|
|
26
|
+
if (binary(reference.target))
|
|
27
|
+
return false;
|
|
28
|
+
const held = typeOf(reference.target);
|
|
29
|
+
return held === undefined || reference.to.includes(held);
|
|
30
|
+
}
|
|
31
|
+
function missing(reference, typeOf, binary) {
|
|
32
|
+
if (reference.to.includes(ATTACHMENT) || reference.target === null)
|
|
28
33
|
return false;
|
|
29
|
-
|
|
30
|
-
return held === undefined || to.includes(held);
|
|
34
|
+
return typeOf(reference.target) === undefined && !binary(reference.target);
|
|
31
35
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
export function resolves(reference, typeOf, binary) {
|
|
37
|
+
return reaches(reference, typeOf, binary) && !missing(reference, typeOf, binary);
|
|
38
|
+
}
|
|
39
|
+
function usesIn(content) {
|
|
40
|
+
let held;
|
|
41
|
+
return () => {
|
|
42
|
+
if (held !== undefined)
|
|
43
|
+
return held;
|
|
44
|
+
const bodyStart = bodyStartOf(content);
|
|
45
|
+
held = linkInventory(content.slice(bodyStart)).uses.map((use) => ({
|
|
46
|
+
...use,
|
|
47
|
+
start: bodyStart + use.start,
|
|
48
|
+
end: bodyStart + use.end,
|
|
49
|
+
}));
|
|
50
|
+
return held;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function itemHrefs(content, items, uses) {
|
|
35
54
|
const hrefs = [];
|
|
36
55
|
for (const item of items) {
|
|
37
|
-
const link = uses.find((use) =>
|
|
38
|
-
bodyStart + use.end === item.end &&
|
|
39
|
-
content[item.start] === '[');
|
|
56
|
+
const link = uses().find((use) => use.start === item.start && use.end === item.end && content[item.start] === '[');
|
|
40
57
|
if (link === undefined)
|
|
41
58
|
return null;
|
|
42
59
|
hrefs.push(link.destination.href);
|
|
@@ -53,10 +70,96 @@ export function verify(schema) {
|
|
|
53
70
|
...(read.location === undefined ? {} : { location: read.location }),
|
|
54
71
|
};
|
|
55
72
|
}
|
|
73
|
+
function structure(file, content, document, definition) {
|
|
74
|
+
if (definition === undefined)
|
|
75
|
+
return { refusal: refuse(file, 'unknown-type', { location: '/type' }) };
|
|
76
|
+
const fieldFailure = frontmatterRefusal(definition, document.fields);
|
|
77
|
+
if (fieldFailure !== undefined) {
|
|
78
|
+
return { refusal: refuse(file, fieldFailure.rule, { location: fieldFailure.location }) };
|
|
79
|
+
}
|
|
80
|
+
const spans = headingSpans(content, bodyStartOf(content));
|
|
81
|
+
const uses = usesIn(content);
|
|
82
|
+
const sections = [];
|
|
83
|
+
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
84
|
+
const occurrences = spans.filter((one) => one.name === name);
|
|
85
|
+
if (occurrences.length === 0 && spec.required)
|
|
86
|
+
return { refusal: refuse(file, 'required-section', { location: name }) };
|
|
87
|
+
if (spec.kind !== 'list')
|
|
88
|
+
continue;
|
|
89
|
+
for (const span of occurrences) {
|
|
90
|
+
const items = listItems(content, span.bodyStart, span.bodyEnd);
|
|
91
|
+
if (items === null ||
|
|
92
|
+
items.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))))
|
|
93
|
+
return { refusal: refuse(file, 'structured-section', { location: name }) };
|
|
94
|
+
if (spec.items.reference === undefined)
|
|
95
|
+
continue;
|
|
96
|
+
const hrefs = itemHrefs(content, items, uses);
|
|
97
|
+
if (hrefs === null)
|
|
98
|
+
return { refusal: refuse(file, 'structured-section', { location: name }) };
|
|
99
|
+
sections.push({ section: name, to: spec.items.reference, hrefs });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { sections };
|
|
103
|
+
}
|
|
104
|
+
function linked(file, content) {
|
|
105
|
+
return hrefOccurrences(bodyAfterFrontmatter(content)).every((occurrence) => classifyHref(file, occurrence.href).kind !== 'invalid');
|
|
106
|
+
}
|
|
107
|
+
function reached(file, href, to) {
|
|
108
|
+
const resolved = classifyHref(file, href);
|
|
109
|
+
return { target: resolved.kind === 'path' ? resolved.path : null, to };
|
|
110
|
+
}
|
|
111
|
+
function definitionOf(document, model) {
|
|
112
|
+
const kind = instanceType(document);
|
|
113
|
+
return kind === null || !Object.hasOwn(model.types, kind) ? undefined : model.types[kind];
|
|
114
|
+
}
|
|
115
|
+
export function checkDocument(file, content, model) {
|
|
116
|
+
const parsed = parse(content, file);
|
|
117
|
+
if (!parsed.ok)
|
|
118
|
+
return { ok: false };
|
|
119
|
+
const document = parsed.document;
|
|
120
|
+
const type = document.type ?? BUILT_IN_TYPE;
|
|
121
|
+
if (instanceType(document) === BUILT_IN_TYPE)
|
|
122
|
+
return { ok: true, type, typed: false, references: [] };
|
|
123
|
+
const definition = definitionOf(document, model);
|
|
124
|
+
const read = structure(file, content, document, definition);
|
|
125
|
+
if ('refusal' in read || definition === undefined || !linked(file, content))
|
|
126
|
+
return { ok: false };
|
|
127
|
+
return {
|
|
128
|
+
ok: true,
|
|
129
|
+
type,
|
|
130
|
+
typed: true,
|
|
131
|
+
references: [
|
|
132
|
+
...references(document, definition).map(({ value, to }) => reached(file, value, to)),
|
|
133
|
+
...read.sections.flatMap(({ to, hrefs }) => hrefs.map((href) => reached(file, href, to))),
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export function sectionReferences(file, content, definition) {
|
|
138
|
+
const referring = (name) => {
|
|
139
|
+
const spec = Object.hasOwn(definition.sections, name) ? definition.sections[name] : undefined;
|
|
140
|
+
return spec?.kind === 'list' ? spec.items.reference : undefined;
|
|
141
|
+
};
|
|
142
|
+
if (!Object.keys(definition.sections).some((name) => referring(name) !== undefined))
|
|
143
|
+
return [];
|
|
144
|
+
const uses = usesIn(content);
|
|
145
|
+
const found = [];
|
|
146
|
+
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
147
|
+
const to = referring(span.name);
|
|
148
|
+
if (to === undefined)
|
|
149
|
+
continue;
|
|
150
|
+
const items = listItems(content, span.bodyStart, span.bodyEnd);
|
|
151
|
+
const hrefs = items === null ? null : itemHrefs(content, items, uses);
|
|
152
|
+
for (const href of hrefs ?? [])
|
|
153
|
+
found.push(reached(file, href, to));
|
|
154
|
+
}
|
|
155
|
+
return found;
|
|
156
|
+
}
|
|
56
157
|
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
57
158
|
const binaryTargets = new Set(context.binaryTargets);
|
|
159
|
+
const binary = (path) => binaryTargets.has(path);
|
|
58
160
|
const files = Object.keys(library).sort();
|
|
59
161
|
const types = new Map();
|
|
162
|
+
const typeOf = (path) => types.get(path);
|
|
60
163
|
const documents = new Map();
|
|
61
164
|
for (const file of files) {
|
|
62
165
|
if (binaryTargets.has(file))
|
|
@@ -68,98 +171,49 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
|
|
|
68
171
|
if (instanceType(parsed.document) !== BUILT_IN_TYPE)
|
|
69
172
|
documents.set(file, parsed.document);
|
|
70
173
|
}
|
|
71
|
-
const definitions = new Map(Object.entries(model.types));
|
|
72
174
|
const sectionReferences = new Map();
|
|
73
175
|
for (const [file, document] of documents) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (definition === undefined)
|
|
79
|
-
return refuse(file, 'unknown-type', { location: '/type' });
|
|
80
|
-
const fieldFailure = frontmatterRefusal(definition, document.fields);
|
|
81
|
-
if (fieldFailure !== undefined) {
|
|
82
|
-
return refuse(file, fieldFailure.rule, { location: fieldFailure.location });
|
|
83
|
-
}
|
|
84
|
-
const content = library[file];
|
|
85
|
-
const spans = headingSpans(content, bodyStartOf(content));
|
|
86
|
-
const references = [];
|
|
87
|
-
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
88
|
-
const occurrences = spans.filter((one) => one.name === name);
|
|
89
|
-
if (occurrences.length === 0 && spec.required)
|
|
90
|
-
return refuse(file, 'required-section', { location: name });
|
|
91
|
-
if (spec.kind !== 'list')
|
|
92
|
-
continue;
|
|
93
|
-
for (const span of occurrences) {
|
|
94
|
-
const items = listItems(content, span.bodyStart, span.bodyEnd);
|
|
95
|
-
if (items === null ||
|
|
96
|
-
items.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))))
|
|
97
|
-
return refuse(file, 'structured-section', { location: name });
|
|
98
|
-
if (spec.items.reference === undefined)
|
|
99
|
-
continue;
|
|
100
|
-
const hrefs = itemHrefs(content, items);
|
|
101
|
-
if (hrefs === null)
|
|
102
|
-
return refuse(file, 'structured-section', { location: name });
|
|
103
|
-
references.push({ section: name, to: spec.items.reference, hrefs });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
sectionReferences.set(file, references);
|
|
176
|
+
const read = structure(file, library[file], document, definitionOf(document, model));
|
|
177
|
+
if ('refusal' in read)
|
|
178
|
+
return read.refusal;
|
|
179
|
+
sectionReferences.set(file, read.sections);
|
|
107
180
|
}
|
|
181
|
+
const named = new Map();
|
|
108
182
|
for (const [file, document] of documents) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return refuse(file, 'unresolved-reference', { location: pointer });
|
|
183
|
+
const definition = definitionOf(document, model);
|
|
184
|
+
const fields = references(document, definition).map(({ pointer, value, to }) => ({
|
|
185
|
+
reference: reached(file, value, to),
|
|
186
|
+
location: pointer,
|
|
187
|
+
}));
|
|
188
|
+
for (const { reference, location } of fields) {
|
|
189
|
+
if (!reaches(reference, typeOf, binary))
|
|
190
|
+
return refuse(file, 'unresolved-reference', { location });
|
|
118
191
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!reaches(file, href, to, types, binaryTargets))
|
|
128
|
-
return refuse(file, 'unresolved-reference', { location: section });
|
|
129
|
-
}
|
|
192
|
+
if (!linked(file, library[file]))
|
|
193
|
+
return refuse(file, 'unresolved-link');
|
|
194
|
+
const sections = sectionReferences
|
|
195
|
+
.get(file)
|
|
196
|
+
.flatMap(({ section, to, hrefs }) => hrefs.map((href) => ({ reference: reached(file, href, to), location: section })));
|
|
197
|
+
for (const { reference, location } of sections) {
|
|
198
|
+
if (!reaches(reference, typeOf, binary))
|
|
199
|
+
return refuse(file, 'unresolved-reference', { location });
|
|
130
200
|
}
|
|
201
|
+
named.set(file, [...fields, ...sections]);
|
|
131
202
|
}
|
|
132
|
-
const
|
|
133
|
-
for (const [file,
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
continue;
|
|
137
|
-
const definition = definitions.get(kind);
|
|
138
|
-
if (definition === undefined)
|
|
139
|
-
continue;
|
|
140
|
-
const named = [
|
|
141
|
-
...references(document, definition),
|
|
142
|
-
...sectionReferences
|
|
143
|
-
.get(file)
|
|
144
|
-
.flatMap(({ to, hrefs }) => hrefs.map((value) => ({ value, to }))),
|
|
145
|
-
];
|
|
146
|
-
for (const { value, to } of named) {
|
|
147
|
-
if (to.includes(ATTACHMENT))
|
|
148
|
-
continue;
|
|
149
|
-
const resolved = classifyHref(file, value);
|
|
150
|
-
if (resolved.kind !== 'path')
|
|
151
|
-
continue;
|
|
152
|
-
if (types.has(resolved.path) || binaryTargets.has(resolved.path))
|
|
203
|
+
const absent = new Map();
|
|
204
|
+
for (const [file, references] of named) {
|
|
205
|
+
for (const { reference } of references) {
|
|
206
|
+
if (!missing(reference, typeOf, binary))
|
|
153
207
|
continue;
|
|
154
|
-
const referrers =
|
|
208
|
+
const referrers = absent.get(reference.target) ?? [];
|
|
155
209
|
referrers.push(file);
|
|
156
|
-
|
|
210
|
+
absent.set(reference.target, referrers);
|
|
157
211
|
}
|
|
158
212
|
}
|
|
159
|
-
const missingPaths = [...
|
|
213
|
+
const missingPaths = [...absent.keys()].sort();
|
|
160
214
|
if (missingPaths.length > 0) {
|
|
161
215
|
const path = missingPaths[0];
|
|
162
|
-
const referrers = [...new Set(
|
|
216
|
+
const referrers = [...new Set(absent.get(path) ?? [])].sort();
|
|
163
217
|
return refuse(path, 'referenced-missing-file', { referrers });
|
|
164
218
|
}
|
|
165
219
|
return { verdict: 'accept' };
|
package/dist/yaml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAnC,YAAqB,MAAM,EAAE,MAAM,EAGlC;CACF;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB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CAAC,CAEzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3E;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAqB9F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBjE;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAEzD"}
|
package/dist/yaml.js
CHANGED
|
@@ -84,6 +84,30 @@ export function interpretPlain(text) {
|
|
|
84
84
|
return Number(text);
|
|
85
85
|
return text;
|
|
86
86
|
}
|
|
87
|
+
const ESCAPES = {
|
|
88
|
+
b: '\b',
|
|
89
|
+
f: '\f',
|
|
90
|
+
n: '\n',
|
|
91
|
+
r: '\r',
|
|
92
|
+
t: '\t',
|
|
93
|
+
'"': '"',
|
|
94
|
+
'/': '/',
|
|
95
|
+
'\\': '\\',
|
|
96
|
+
};
|
|
97
|
+
function parseEscape(c) {
|
|
98
|
+
c.i += 1;
|
|
99
|
+
const escaped = peek(c);
|
|
100
|
+
const held = ESCAPES[escaped];
|
|
101
|
+
if (held !== undefined) {
|
|
102
|
+
c.i += 1;
|
|
103
|
+
return held;
|
|
104
|
+
}
|
|
105
|
+
const hex = c.text.slice(c.i + 1, c.i + 5);
|
|
106
|
+
if (escaped !== 'u' || c.i + 5 > c.end || !/^[0-9A-Fa-f]{4}$/.test(hex))
|
|
107
|
+
throw new YamlError(c.i);
|
|
108
|
+
c.i += 5;
|
|
109
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
110
|
+
}
|
|
87
111
|
function parseQuoted(c) {
|
|
88
112
|
const quote = peek(c);
|
|
89
113
|
const start = c.i;
|
|
@@ -91,31 +115,19 @@ function parseQuoted(c) {
|
|
|
91
115
|
let out = '';
|
|
92
116
|
while (c.i < c.end) {
|
|
93
117
|
const ch = peek(c);
|
|
118
|
+
if (quote === "'" && ch === "'" && c.i + 1 < c.end && c.text[c.i + 1] === "'") {
|
|
119
|
+
out += "'";
|
|
120
|
+
c.i += 2;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
94
123
|
if (ch === quote) {
|
|
95
124
|
c.i += 1;
|
|
96
125
|
return scalar(out, start, c.i);
|
|
97
126
|
}
|
|
98
127
|
if (ch === '\n' || ch === '\r')
|
|
99
128
|
throw new YamlError(c.i);
|
|
100
|
-
if (quote === "'" && ch === "'" && c.text[c.i + 1] === "'") {
|
|
101
|
-
out += "'";
|
|
102
|
-
c.i += 2;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
129
|
if (quote === '"' && ch === '\\') {
|
|
106
|
-
|
|
107
|
-
const escaped = peek(c);
|
|
108
|
-
if (escaped === 'n')
|
|
109
|
-
out += '\n';
|
|
110
|
-
else if (escaped === 't')
|
|
111
|
-
out += '\t';
|
|
112
|
-
else if (escaped === '"')
|
|
113
|
-
out += '"';
|
|
114
|
-
else if (escaped === '\\')
|
|
115
|
-
out += '\\';
|
|
116
|
-
else
|
|
117
|
-
throw new YamlError(c.i);
|
|
118
|
-
c.i += 1;
|
|
130
|
+
out += parseEscape(c);
|
|
119
131
|
continue;
|
|
120
132
|
}
|
|
121
133
|
out += ch;
|
package/fixtures/README.md
CHANGED
|
@@ -136,6 +136,6 @@ Library is accepted too, so `unresolved-link` never names it and
|
|
|
136
136
|
## YAML subset
|
|
137
137
|
|
|
138
138
|
Frontmatter and a schema text are each a mapping in a closed YAML subset: block and flow mappings,
|
|
139
|
-
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars, `true`, `false`, `null`,
|
|
139
|
+
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars (a single-quoted scalar doubles its apostrophe, a double-quoted one takes JSON's escapes), `true`, `false`, `null`,
|
|
140
140
|
and decimal numbers. It does not take YAML 1.1 boolean or timestamp aliases,
|
|
141
141
|
octal numbers, anchors, tags, or block scalars. A mapping carries each key once.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdmodel",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-ccf1367190878",
|
|
4
4
|
"description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cfworker/json-schema": "4.1.1"
|
|
29
|
+
"@cfworker/json-schema": "4.1.1",
|
|
30
|
+
"decode-named-character-reference": "1.3.0",
|
|
31
|
+
"micromark-util-decode-numeric-character-reference": "2.0.2"
|
|
30
32
|
}
|
|
31
33
|
}
|