@agentshouse/mdmodel 0.1.0-alpha.9 → 0.1.0-c68e2039f1ca8
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 +300 -0
- package/README.md +34 -189
- package/dist/blocks.d.ts +11 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +62 -0
- package/dist/condition.d.ts +137 -0
- package/dist/condition.d.ts.map +1 -0
- package/dist/condition.js +394 -0
- package/dist/definition.d.ts +42 -27
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +473 -152
- package/dist/divide.d.ts +3 -0
- package/dist/divide.d.ts.map +1 -0
- package/dist/divide.js +310 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +89 -120
- package/dist/fields.d.ts +4 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +618 -224
- package/dist/paths.d.ts +2 -3
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +27 -37
- package/dist/profile.js +1 -3
- package/dist/project.d.ts +19 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +77 -94
- package/dist/refuse.d.ts.map +1 -1
- package/dist/refuse.js +2 -10
- package/dist/schema.d.ts +7 -5
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +156 -41
- package/dist/sections.d.ts +2 -1
- package/dist/sections.d.ts.map +1 -1
- package/dist/sections.js +44 -66
- package/dist/types.d.ts +30 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/validate.d.ts +3 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +138 -141
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -3
- package/dist/yaml.d.ts +2 -0
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +254 -190
- package/fixtures/README.md +85 -56
- package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
- package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
- package/fixtures/cases/absent-optional-field/schema.yaml +56 -0
- package/fixtures/cases/binary-any-reference/expected.json +1 -2
- package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-document-collision/expected.json +1 -2
- package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
- package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
- package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +1 -2
- package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-typed-reference/expected.json +1 -2
- package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
- package/fixtures/cases/boolean-field/context.json +1 -0
- package/fixtures/cases/boolean-field/expected.json +6 -0
- package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
- package/fixtures/cases/boolean-field/library/deals/renewal.md +31 -0
- package/fixtures/cases/boolean-field/schema.yaml +56 -0
- package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
- package/fixtures/cases/closed-nested-object/context.json +1 -0
- package/fixtures/cases/closed-nested-object/expected.json +6 -0
- package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
- package/fixtures/cases/closed-nested-object/library/deals/renewal.md +32 -0
- package/fixtures/cases/closed-nested-object/schema.yaml +56 -0
- package/fixtures/cases/composed-root-reference/context.json +1 -0
- package/fixtures/cases/composed-root-reference/expected.json +6 -0
- package/fixtures/cases/composed-root-reference/library/a.md +5 -0
- package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
- package/fixtures/cases/date-time-format/context.json +1 -0
- package/fixtures/cases/date-time-format/expected.json +6 -0
- package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
- package/fixtures/cases/date-time-format/library/deals/renewal.md +31 -0
- package/fixtures/cases/date-time-format/schema.yaml +56 -0
- package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
- package/fixtures/cases/default-unfilled/context.json +1 -0
- package/fixtures/cases/default-unfilled/expected.json +6 -0
- package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
- package/fixtures/cases/default-unfilled/library/deals/renewal.md +29 -0
- package/fixtures/cases/default-unfilled/schema.yaml +56 -0
- package/fixtures/cases/defs-pattern/context.json +1 -0
- package/fixtures/cases/defs-pattern/expected.json +6 -0
- package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
- package/fixtures/cases/defs-pattern/library/deals/renewal.md +31 -0
- package/fixtures/cases/defs-pattern/schema.yaml +56 -0
- package/fixtures/cases/dependent-rule/context.json +1 -0
- package/fixtures/cases/dependent-rule/expected.json +6 -0
- package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
- package/fixtures/cases/dependent-rule/library/deals/renewal.md +30 -0
- package/fixtures/cases/dependent-rule/schema.yaml +56 -0
- package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
- package/fixtures/cases/email-format/context.json +1 -0
- package/fixtures/cases/email-format/expected.json +6 -0
- package/fixtures/cases/email-format/library/companies/acme.md +4 -0
- package/fixtures/cases/email-format/library/deals/renewal.md +31 -0
- package/fixtures/cases/email-format/schema.yaml +56 -0
- package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
- package/fixtures/cases/field-enum/expected.json +2 -3
- package/fixtures/cases/field-enum/schema.yaml +7 -0
- package/fixtures/cases/frontmatter-schema/context.json +1 -0
- package/fixtures/cases/frontmatter-schema/expected.json +5 -0
- package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
- package/fixtures/cases/integer-field/context.json +1 -0
- package/fixtures/cases/integer-field/expected.json +6 -0
- package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
- package/fixtures/cases/integer-field/library/deals/renewal.md +31 -0
- package/fixtures/cases/integer-field/schema.yaml +56 -0
- package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
- package/fixtures/cases/json-schema-constructs/context.json +1 -0
- package/fixtures/cases/json-schema-constructs/expected.json +1 -0
- package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
- package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +31 -0
- package/fixtures/cases/json-schema-constructs/schema.yaml +56 -0
- package/fixtures/cases/list-of-objects-closed/context.json +1 -0
- package/fixtures/cases/list-of-objects-closed/expected.json +6 -0
- package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
- package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +32 -0
- package/fixtures/cases/list-of-objects-closed/schema.yaml +56 -0
- package/fixtures/cases/list-of-objects-item/context.json +1 -0
- package/fixtures/cases/list-of-objects-item/expected.json +6 -0
- package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
- package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +31 -0
- package/fixtures/cases/list-of-objects-item/schema.yaml +56 -0
- package/fixtures/cases/list-size/context.json +1 -0
- package/fixtures/cases/list-size/expected.json +6 -0
- package/fixtures/cases/list-size/library/companies/acme.md +4 -0
- package/fixtures/cases/list-size/library/deals/renewal.md +31 -0
- package/fixtures/cases/list-size/schema.yaml +56 -0
- package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
- package/fixtures/cases/malformed-definition/expected.json +2 -4
- package/fixtures/cases/malformed-definition/schema.yaml +3 -0
- package/fixtures/cases/member-document/context.json +1 -0
- package/fixtures/cases/member-document/expected.json +1 -0
- package/fixtures/cases/member-document/library/people/ana.md +5 -0
- package/fixtures/cases/member-document/schema.yaml +5 -0
- package/fixtures/cases/missing-binary-image/expected.json +1 -2
- package/fixtures/cases/missing-binary-image/schema.yaml +1 -0
- package/fixtures/cases/missing-binary-link/expected.json +1 -2
- package/fixtures/cases/missing-binary-link/schema.yaml +1 -0
- package/fixtures/cases/missing-required-field/expected.json +2 -3
- package/fixtures/cases/missing-required-field/schema.yaml +7 -0
- package/fixtures/cases/missing-section-item-kind/expected.json +2 -4
- package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
- package/fixtures/cases/misspelled-key/context.json +1 -0
- package/fixtures/cases/misspelled-key/expected.json +6 -0
- package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
- package/fixtures/cases/misspelled-key/library/deals/renewal.md +32 -0
- package/fixtures/cases/misspelled-key/schema.yaml +56 -0
- package/fixtures/cases/nested-defs/context.json +1 -0
- package/fixtures/cases/nested-defs/expected.json +6 -0
- package/fixtures/cases/nested-defs/library/deal.md +6 -0
- package/fixtures/cases/nested-defs/schema.yaml +11 -0
- package/fixtures/cases/nested-required-field/context.json +1 -0
- package/fixtures/cases/nested-required-field/expected.json +6 -0
- package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
- package/fixtures/cases/nested-required-field/library/deals/renewal.md +30 -0
- package/fixtures/cases/nested-required-field/schema.yaml +56 -0
- package/fixtures/cases/null-refused/context.json +1 -0
- package/fixtures/cases/null-refused/expected.json +6 -0
- package/fixtures/cases/null-refused/library/companies/acme.md +4 -0
- package/fixtures/cases/null-refused/library/deals/renewal.md +31 -0
- package/fixtures/cases/null-refused/schema.yaml +56 -0
- package/fixtures/cases/numeric-range/context.json +1 -0
- package/fixtures/cases/numeric-range/expected.json +6 -0
- package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
- package/fixtures/cases/numeric-range/library/deals/renewal.md +31 -0
- package/fixtures/cases/numeric-range/schema.yaml +56 -0
- package/fixtures/cases/one-of-variant/context.json +1 -0
- package/fixtures/cases/one-of-variant/expected.json +6 -0
- package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
- package/fixtures/cases/one-of-variant/library/deals/renewal.md +31 -0
- package/fixtures/cases/one-of-variant/schema.yaml +56 -0
- package/fixtures/cases/open-map-value/context.json +1 -0
- package/fixtures/cases/open-map-value/expected.json +6 -0
- package/fixtures/cases/open-map-value/library/companies/acme.md +4 -0
- package/fixtures/cases/open-map-value/library/deals/renewal.md +31 -0
- package/fixtures/cases/open-map-value/schema.yaml +56 -0
- package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
- package/fixtures/cases/prototype-field/expected.json +2 -3
- package/fixtures/cases/prototype-field/schema.yaml +6 -0
- package/fixtures/cases/quoted-link-definition/expected.json +1 -2
- package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
- package/fixtures/cases/referenced-missing-file/expected.json +0 -1
- package/fixtures/cases/referenced-missing-file/schema.yaml +11 -0
- package/fixtures/cases/remote-ref/context.json +1 -0
- package/fixtures/cases/remote-ref/expected.json +5 -0
- package/fixtures/cases/remote-ref/schema.yaml +3 -0
- package/fixtures/cases/second-member-document/context.json +1 -0
- package/fixtures/cases/second-member-document/expected.json +5 -0
- package/fixtures/cases/second-member-document/schema.yaml +4 -0
- package/fixtures/cases/section-item-enum/context.json +1 -0
- package/fixtures/cases/section-item-enum/expected.json +6 -0
- package/fixtures/cases/section-item-enum/library/task.md +8 -0
- package/fixtures/cases/section-item-enum/schema.yaml +3 -0
- package/fixtures/cases/section-item-kind/context.json +1 -0
- package/fixtures/cases/section-item-kind/expected.json +6 -0
- package/fixtures/cases/section-item-kind/library/task.md +8 -0
- package/fixtures/cases/section-item-kind/schema.yaml +3 -0
- package/fixtures/cases/section-items/context.json +1 -0
- package/fixtures/cases/section-items/expected.json +1 -0
- package/fixtures/cases/section-items/library/other.md +3 -0
- package/fixtures/cases/section-items/library/page.md +42 -0
- package/fixtures/cases/section-items/schema.yaml +10 -0
- package/fixtures/cases/section-reference-path/context.json +1 -0
- package/fixtures/cases/section-reference-path/expected.json +6 -0
- package/fixtures/cases/section-reference-path/library/other.md +3 -0
- package/fixtures/cases/section-reference-path/library/page.md +7 -0
- package/fixtures/cases/section-reference-path/schema.yaml +3 -0
- package/fixtures/cases/section-reference-type/context.json +1 -0
- package/fixtures/cases/section-reference-type/expected.json +6 -0
- package/fixtures/cases/section-reference-type/library/note.md +1 -0
- package/fixtures/cases/section-reference-type/library/page.md +7 -0
- package/fixtures/cases/section-reference-type/schema.yaml +3 -0
- package/fixtures/cases/shortcut-reference-link/context.json +1 -0
- package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
- package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
- package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
- package/fixtures/cases/string-length/context.json +1 -0
- package/fixtures/cases/string-length/expected.json +6 -0
- package/fixtures/cases/string-length/library/companies/acme.md +4 -0
- package/fixtures/cases/string-length/library/deals/renewal.md +31 -0
- package/fixtures/cases/string-length/schema.yaml +56 -0
- package/fixtures/cases/structured-section/expected.json +1 -2
- package/fixtures/cases/structured-section/schema.yaml +7 -0
- package/fixtures/cases/submission-keys/context.json +1 -0
- package/fixtures/cases/submission-keys/expected.json +1 -0
- package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
- package/fixtures/cases/submission-keys/schema.yaml +4 -0
- package/fixtures/cases/text-field-kind/context.json +1 -0
- package/fixtures/cases/text-field-kind/expected.json +6 -0
- package/fixtures/cases/text-field-kind/library/page.md +4 -0
- package/fixtures/cases/text-field-kind/schema.yaml +4 -0
- package/fixtures/cases/truncated-link-definition/expected.json +1 -2
- package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
- package/fixtures/cases/types-folder-content/context.json +1 -0
- package/fixtures/cases/types-folder-content/expected.json +1 -0
- package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
- package/fixtures/cases/types-folder-content/schema.yaml +4 -0
- package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
- package/fixtures/cases/undeclared-field/expected.json +2 -3
- package/fixtures/cases/undeclared-field/schema.yaml +6 -0
- package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
- package/fixtures/cases/unevaluated-items-closed/expected.json +6 -0
- package/fixtures/cases/unevaluated-items-closed/library/trip.md +6 -0
- package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
- package/fixtures/cases/unknown-type/context.json +1 -0
- package/fixtures/cases/unknown-type/expected.json +6 -0
- package/fixtures/cases/unknown-type/library/item.md +3 -0
- package/fixtures/cases/unknown-type/schema.yaml +3 -0
- package/fixtures/cases/unlisted-reference-type/context.json +1 -0
- package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
- package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
- package/fixtures/cases/unresolved-link/expected.json +1 -2
- package/fixtures/cases/unresolved-link/schema.yaml +6 -0
- package/fixtures/cases/valid-typed-document/schema.yaml +16 -0
- package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
- package/fixtures/division.json +409 -0
- package/fixtures/projection.json +90 -21
- package/package.json +3 -12
- package/dist/definition.js.map +0 -1
- package/dist/document.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/links.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/profile.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/refuse.js.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/sections.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/yaml.js.map +0 -1
- package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
- package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
- package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
- package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
- package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/field-enum/library/types/task.md +0 -8
- package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
- package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
- package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
- package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
- package/fixtures/cases/missing-section-item-kind/library/types/task.md +0 -7
- package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/prd-definition/library/types/task.md +0 -16
- package/fixtures/cases/prototype-field/library/types/task.md +0 -7
- package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
- package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
- package/fixtures/cases/structured-section/library/types/task.md +0 -8
- package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/undeclared-field/library/types/task.md +0 -7
- package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
- package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
- package/fixtures/cases/valid-typed-document/library/types/task.md +0 -13
- package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
- package/markdown-syntax-profile.md +0 -9
- /package/fixtures/cases/{prd-definition → absent-optional-field}/context.json +0 -0
- /package/fixtures/cases/{prd-definition → absent-optional-field}/expected.json +0 -0
package/dist/sections.js
CHANGED
|
@@ -1,79 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { headingLines } from './blocks.js';
|
|
2
2
|
const ITEM = /^([ \t]*)([-*+]|\d+[.)])[ \t]+/;
|
|
3
|
-
function lineRange(content, from) {
|
|
4
|
-
const nl = content.indexOf('\n', from);
|
|
5
|
-
const end = nl === -1 ? content.length : nl;
|
|
6
|
-
let line = content.slice(from, end);
|
|
7
|
-
if (line.endsWith('\r')) line = line.slice(0, -1);
|
|
8
|
-
return {
|
|
9
|
-
line,
|
|
10
|
-
start: from,
|
|
11
|
-
next: nl === -1 ? content.length : nl + 1
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function fenceMarker(line) {
|
|
15
|
-
let i = 0;
|
|
16
|
-
while(i < 3 && (line[i] === ' ' || line[i] === '\t'))i += 1;
|
|
17
|
-
if (line.startsWith('```', i)) return '```';
|
|
18
|
-
if (line.startsWith('~~~', i)) return '~~~';
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
3
|
export function headingSpans(content, bodyStart) {
|
|
22
4
|
const found = [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (match !== null && match[1] !== undefined) {
|
|
35
|
-
const name = match[1].trim();
|
|
36
|
-
if (found.length > 0) found[found.length - 1] = {
|
|
37
|
-
...found[found.length - 1],
|
|
38
|
-
bodyEnd: start
|
|
39
|
-
};
|
|
40
|
-
found.push({
|
|
41
|
-
name,
|
|
42
|
-
headingStart: start,
|
|
43
|
-
bodyStart: next,
|
|
44
|
-
bodyEnd: content.length
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (next === i) break;
|
|
49
|
-
i = next;
|
|
5
|
+
for (const heading of headingLines(content, bodyStart, content.length)) {
|
|
6
|
+
if (heading.level !== 2)
|
|
7
|
+
continue;
|
|
8
|
+
if (found.length > 0)
|
|
9
|
+
found[found.length - 1] = { ...found[found.length - 1], bodyEnd: heading.start };
|
|
10
|
+
found.push({
|
|
11
|
+
name: heading.name,
|
|
12
|
+
headingStart: heading.start,
|
|
13
|
+
bodyStart: heading.next,
|
|
14
|
+
bodyEnd: content.length,
|
|
15
|
+
});
|
|
50
16
|
}
|
|
51
17
|
return found;
|
|
52
18
|
}
|
|
53
19
|
export function sectionsRecord(spans, content) {
|
|
54
20
|
const record = Object.create(null);
|
|
55
|
-
for (const span of spans){
|
|
56
|
-
if (record[span.name] === undefined)
|
|
21
|
+
for (const span of spans) {
|
|
22
|
+
if (record[span.name] === undefined)
|
|
23
|
+
record[span.name] = content.slice(span.bodyStart, span.bodyEnd);
|
|
57
24
|
}
|
|
58
25
|
return record;
|
|
59
26
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
while(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
27
|
+
function trimmed(content, extent) {
|
|
28
|
+
let { start, end } = extent;
|
|
29
|
+
while (start < end && /\s/.test(content[start]))
|
|
30
|
+
start += 1;
|
|
31
|
+
while (end > start && /\s/.test(content[end - 1]))
|
|
32
|
+
end -= 1;
|
|
33
|
+
return { start, end };
|
|
34
|
+
}
|
|
35
|
+
export function listItems(content, from, to) {
|
|
36
|
+
const items = [];
|
|
37
|
+
let indent;
|
|
38
|
+
let start = from;
|
|
39
|
+
while (start < to) {
|
|
40
|
+
const newline = content.indexOf('\n', start);
|
|
41
|
+
const end = newline === -1 || newline >= to ? to : newline;
|
|
42
|
+
const line = content.slice(start, end);
|
|
43
|
+
start = end + 1;
|
|
44
|
+
if (line.trim() === '')
|
|
45
|
+
continue;
|
|
46
|
+
const item = ITEM.exec(line);
|
|
47
|
+
if (item !== null && (indent === undefined || item[1].length === indent)) {
|
|
48
|
+
indent = item[1].length;
|
|
49
|
+
items.push({ start: end - line.length + item[0].length, end });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (indent === undefined || /^\s*/.exec(line)[0].length <= indent)
|
|
53
|
+
return null;
|
|
54
|
+
items[items.length - 1] = { start: items.at(-1).start, end };
|
|
75
55
|
}
|
|
76
|
-
return
|
|
56
|
+
return items.map((item) => trimmed(content, item));
|
|
77
57
|
}
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=sections.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
|
+
import type { Definition } from './definition.js';
|
|
1
2
|
export type Library = Readonly<Record<string, string>>;
|
|
3
|
+
export type VerifiedModel = {
|
|
4
|
+
readonly types: Readonly<Record<string, Definition>>;
|
|
5
|
+
};
|
|
6
|
+
export type ModelVerification = {
|
|
7
|
+
readonly verdict: 'accept';
|
|
8
|
+
readonly model: VerifiedModel;
|
|
9
|
+
} | {
|
|
10
|
+
readonly verdict: 'refuse';
|
|
11
|
+
readonly rule: string;
|
|
12
|
+
readonly location?: string;
|
|
13
|
+
};
|
|
2
14
|
export type ValidationContext = {
|
|
3
15
|
readonly binaryTargets: readonly string[];
|
|
4
16
|
};
|
|
5
17
|
export type ProjectionContext = {
|
|
6
18
|
readonly documentTargets: readonly string[];
|
|
7
|
-
readonly definition?:
|
|
19
|
+
readonly definition?: Definition;
|
|
20
|
+
};
|
|
21
|
+
export type DivisionContext = ProjectionContext & {
|
|
22
|
+
readonly budget: number;
|
|
23
|
+
};
|
|
24
|
+
export type Extent = {
|
|
25
|
+
readonly start: number;
|
|
26
|
+
readonly end: number;
|
|
27
|
+
};
|
|
28
|
+
export type Span = Extent & {
|
|
29
|
+
readonly text: string;
|
|
8
30
|
};
|
|
9
31
|
export type Document = {
|
|
10
32
|
readonly content: string;
|
|
@@ -16,7 +38,6 @@ export type Document = {
|
|
|
16
38
|
export type Refusal = {
|
|
17
39
|
readonly file: string;
|
|
18
40
|
readonly rule: string;
|
|
19
|
-
readonly version: string;
|
|
20
41
|
readonly location?: string;
|
|
21
42
|
readonly referrers?: readonly string[];
|
|
22
43
|
};
|
|
@@ -32,6 +53,13 @@ export type Projection = {
|
|
|
32
53
|
readonly ok: false;
|
|
33
54
|
readonly refusal: Refusal;
|
|
34
55
|
};
|
|
56
|
+
export type Division = {
|
|
57
|
+
readonly ok: true;
|
|
58
|
+
readonly spans: readonly Span[];
|
|
59
|
+
} | {
|
|
60
|
+
readonly ok: false;
|
|
61
|
+
readonly refusal: Refusal;
|
|
62
|
+
};
|
|
35
63
|
export type ParseResult = {
|
|
36
64
|
readonly ok: true;
|
|
37
65
|
readonly document: Document;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
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,CAAC;CAC5B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;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AAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,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,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"}
|
package/dist/types.js
CHANGED
package/dist/validate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Library, Validation, ValidationContext } from './types.js';
|
|
2
|
-
export declare function
|
|
1
|
+
import type { Library, ModelVerification, Validation, ValidationContext, VerifiedModel } from './types.js';
|
|
2
|
+
export declare function verify(schema: string): ModelVerification;
|
|
3
|
+
export declare function validate(library: Library, context?: ValidationContext, model?: VerifiedModel): Validation;
|
|
3
4
|
//# 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,KAAK,EAGV,OAAO,EACP,iBAAiB,EAEjB,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AA6EpB,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQxD;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAwGZ"}
|
package/dist/validate.js
CHANGED
|
@@ -1,183 +1,180 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BUILT_IN_TYPE, escapePointer, readSchema, } from './definition.js';
|
|
2
2
|
import { parse } from './document.js';
|
|
3
|
-
import { hrefOccurrences } from './links.js';
|
|
4
|
-
import { classifyHref
|
|
3
|
+
import { hrefOccurrences, linkInventory } from './links.js';
|
|
4
|
+
import { classifyHref } from './paths.js';
|
|
5
5
|
import { refusal } from './refuse.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { bodyAfterFrontmatter } from './yaml.js';
|
|
6
|
+
import { fitsItem, frontmatterRefusal } from './schema.js';
|
|
7
|
+
import { headingSpans, listItems } from './sections.js';
|
|
8
|
+
import { bodyAfterFrontmatter, bodyStartOf } from './yaml.js';
|
|
9
9
|
function refuse(file, rule, extra) {
|
|
10
|
-
return {
|
|
11
|
-
verdict: 'refuse',
|
|
12
|
-
...refusal(file, rule, extra)
|
|
13
|
-
};
|
|
10
|
+
return { verdict: 'refuse', ...refusal(file, rule, extra) };
|
|
14
11
|
}
|
|
15
|
-
function instanceType(document
|
|
16
|
-
if (isTypesPath(file)) return 'definition';
|
|
12
|
+
function instanceType(document) {
|
|
17
13
|
const raw = document.fields.type;
|
|
18
|
-
if (raw === undefined || raw === null)
|
|
19
|
-
|
|
14
|
+
if (raw === undefined || raw === null)
|
|
15
|
+
return BUILT_IN_TYPE;
|
|
16
|
+
if (typeof raw !== 'string' || raw === '')
|
|
17
|
+
return null;
|
|
20
18
|
return raw;
|
|
21
19
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
function fieldReferences(definition, document) {
|
|
21
|
+
const found = [];
|
|
22
|
+
for (const [name, facts] of Object.entries(definition.fields)) {
|
|
23
|
+
const value = document.fields[name];
|
|
24
|
+
const location = `/${escapePointer(name)}`;
|
|
25
|
+
if (facts.reference !== undefined && typeof value === 'string')
|
|
26
|
+
found.push({ location, to: facts.reference, target: value });
|
|
27
|
+
const items = facts.items;
|
|
28
|
+
if (items?.reference === undefined || !Array.isArray(value))
|
|
29
|
+
continue;
|
|
30
|
+
for (const [index, item] of value.entries()) {
|
|
31
|
+
if (typeof item === 'string')
|
|
32
|
+
found.push({ location: `${location}/${index}`, to: items.reference, target: item });
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
|
-
return
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
function reaches(file, href, to, documents, binaryTargets) {
|
|
38
|
+
const resolved = classifyHref(file, href);
|
|
39
|
+
if (resolved.kind !== 'path' || binaryTargets.has(resolved.path))
|
|
40
|
+
return false;
|
|
41
|
+
const held = documents.get(resolved.path);
|
|
42
|
+
return held === undefined || (held.ok && to.includes(held.document.type ?? BUILT_IN_TYPE));
|
|
30
43
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
function itemHrefs(content, items) {
|
|
45
|
+
const bodyStart = bodyStartOf(content);
|
|
46
|
+
const { uses } = linkInventory(content.slice(bodyStart));
|
|
47
|
+
const hrefs = [];
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
const link = uses.find((use) => bodyStart + use.start === item.start &&
|
|
50
|
+
bodyStart + use.end === item.end &&
|
|
51
|
+
content[item.start] === '[');
|
|
52
|
+
if (link === undefined)
|
|
53
|
+
return null;
|
|
54
|
+
hrefs.push(link.destination.href);
|
|
55
|
+
}
|
|
56
|
+
return hrefs;
|
|
35
57
|
}
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
|
|
58
|
+
export function verify(schema) {
|
|
59
|
+
const read = readSchema(schema);
|
|
60
|
+
if ('types' in read)
|
|
61
|
+
return { verdict: 'accept', model: read };
|
|
62
|
+
return {
|
|
63
|
+
verdict: 'refuse',
|
|
64
|
+
rule: read.rule,
|
|
65
|
+
...(read.location === undefined ? {} : { location: read.location }),
|
|
66
|
+
};
|
|
40
67
|
}
|
|
41
|
-
export function validate(library, context = {
|
|
42
|
-
binaryTargets: []
|
|
43
|
-
}) {
|
|
68
|
+
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
44
69
|
const binaryTargets = new Set(context.binaryTargets);
|
|
45
70
|
const files = Object.keys(library).sort();
|
|
46
71
|
const documents = new Map();
|
|
47
|
-
for (const file of files){
|
|
48
|
-
if (binaryTargets.has(file))
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
if (binaryTargets.has(file))
|
|
74
|
+
return refuse(file, 'binary-target-document');
|
|
49
75
|
const parsed = parse(library[file], file);
|
|
50
76
|
documents.set(file, parsed);
|
|
51
|
-
if (!parsed.ok)
|
|
52
|
-
verdict: 'refuse',
|
|
53
|
-
...parsed.refusal
|
|
54
|
-
};
|
|
77
|
+
if (!parsed.ok)
|
|
78
|
+
return { verdict: 'refuse', ...parsed.refusal };
|
|
55
79
|
}
|
|
56
|
-
const definitions = new Map();
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
const definitions = new Map(Object.entries(model.types));
|
|
81
|
+
const sectionReferences = new Map();
|
|
82
|
+
for (const file of files) {
|
|
59
83
|
const parsed = documents.get(file);
|
|
60
|
-
if (parsed === undefined || !parsed.ok)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
definitions.set(definition.name, definition);
|
|
71
|
-
}
|
|
72
|
-
for (const file of files){
|
|
73
|
-
const parsed = documents.get(file);
|
|
74
|
-
if (parsed === undefined || !parsed.ok) continue;
|
|
75
|
-
const kind = instanceType(parsed.document, file);
|
|
76
|
-
if (kind === 'any') continue;
|
|
77
|
-
if (kind === 'invalid' || kind === 'definition') {
|
|
78
|
-
if (kind === 'definition' && isTypesPath(file)) continue;
|
|
79
|
-
return refuse(file, 'unknown-type', {
|
|
80
|
-
location: 'type'
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const definition = definitions.get(kind);
|
|
84
|
-
if (definition === undefined) return refuse(file, 'unknown-type', {
|
|
85
|
-
location: 'type'
|
|
86
|
-
});
|
|
87
|
-
const fieldFailure = validateFields(definition.fields, parsed.document.fields);
|
|
84
|
+
if (parsed === undefined || !parsed.ok)
|
|
85
|
+
continue;
|
|
86
|
+
const kind = instanceType(parsed.document);
|
|
87
|
+
if (kind === BUILT_IN_TYPE)
|
|
88
|
+
continue;
|
|
89
|
+
const definition = kind === null ? undefined : definitions.get(kind);
|
|
90
|
+
if (definition === undefined)
|
|
91
|
+
return refuse(file, 'unknown-type', { location: '/type' });
|
|
92
|
+
const fieldFailure = frontmatterRefusal(definition, parsed.document.fields);
|
|
88
93
|
if (fieldFailure !== undefined) {
|
|
89
|
-
return refuse(file, fieldFailure.rule, {
|
|
90
|
-
location: fieldFailure.field
|
|
91
|
-
});
|
|
94
|
+
return refuse(file, fieldFailure.rule, { location: fieldFailure.location });
|
|
92
95
|
}
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
if (spec.required) return refuse(file, 'required-section', {
|
|
102
|
-
location: name
|
|
103
|
-
});
|
|
96
|
+
const content = library[file];
|
|
97
|
+
const spans = headingSpans(content, bodyStartOf(content));
|
|
98
|
+
const references = [];
|
|
99
|
+
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
100
|
+
const occurrences = spans.filter((one) => one.name === name);
|
|
101
|
+
if (occurrences.length === 0 && spec.required)
|
|
102
|
+
return refuse(file, 'required-section', { location: name });
|
|
103
|
+
if (spec.kind !== 'list')
|
|
104
104
|
continue;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
for (const span of occurrences) {
|
|
106
|
+
const items = listItems(content, span.bodyStart, span.bodyEnd);
|
|
107
|
+
if (items === null ||
|
|
108
|
+
items.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))))
|
|
109
|
+
return refuse(file, 'structured-section', { location: name });
|
|
110
|
+
if (spec.items.reference === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
const hrefs = itemHrefs(content, items);
|
|
113
|
+
if (hrefs === null)
|
|
114
|
+
return refuse(file, 'structured-section', { location: name });
|
|
115
|
+
references.push({ section: name, to: spec.items.reference, hrefs });
|
|
110
116
|
}
|
|
111
117
|
}
|
|
118
|
+
sectionReferences.set(file, references);
|
|
112
119
|
}
|
|
113
|
-
for (const file of files){
|
|
120
|
+
for (const file of files) {
|
|
114
121
|
const parsed = documents.get(file);
|
|
115
|
-
if (parsed === undefined || !parsed.ok)
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
if (parsed === undefined || !parsed.ok)
|
|
123
|
+
continue;
|
|
124
|
+
const kind = instanceType(parsed.document);
|
|
125
|
+
if (kind === null || kind === BUILT_IN_TYPE)
|
|
126
|
+
continue;
|
|
118
127
|
const definition = definitions.get(kind);
|
|
119
|
-
if (definition === undefined)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
for (const target of targets){
|
|
125
|
-
const resolved = classifyHref(file, target);
|
|
126
|
-
if (resolved.kind !== 'path' || binaryTargets.has(resolved.path)) return refuse(file, 'unresolved-reference', {
|
|
127
|
-
location: name
|
|
128
|
-
});
|
|
129
|
-
if (!documents.has(resolved.path)) continue;
|
|
130
|
-
const targetType = declaredTypeOf(library[resolved.path]);
|
|
131
|
-
if (targetType !== expected) return refuse(file, 'unresolved-reference', {
|
|
132
|
-
location: name
|
|
133
|
-
});
|
|
134
|
-
}
|
|
128
|
+
if (definition === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
for (const { location, to, target } of fieldReferences(definition, parsed.document)) {
|
|
131
|
+
if (!reaches(file, target, to, documents, binaryTargets))
|
|
132
|
+
return refuse(file, 'unresolved-reference', { location });
|
|
135
133
|
}
|
|
136
134
|
const body = bodyAfterFrontmatter(library[file]);
|
|
137
|
-
for (const occurrence of hrefOccurrences(body)){
|
|
135
|
+
for (const occurrence of hrefOccurrences(body)) {
|
|
138
136
|
const resolved = classifyHref(file, occurrence.href);
|
|
139
|
-
if (resolved.kind === 'skip')
|
|
140
|
-
|
|
137
|
+
if (resolved.kind === 'skip')
|
|
138
|
+
continue;
|
|
139
|
+
if (resolved.kind === 'invalid' ||
|
|
140
|
+
(!documents.has(resolved.path) && !binaryTargets.has(resolved.path))) {
|
|
141
141
|
return refuse(file, 'unresolved-link');
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
for (const { section, to, hrefs } of sectionReferences.get(file)) {
|
|
145
|
+
for (const href of hrefs) {
|
|
146
|
+
if (!reaches(file, href, to, documents, binaryTargets))
|
|
147
|
+
return refuse(file, 'unresolved-reference', { location: section });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
144
150
|
}
|
|
145
151
|
const missing = new Map();
|
|
146
|
-
for (const file of files){
|
|
152
|
+
for (const file of files) {
|
|
147
153
|
const parsed = documents.get(file);
|
|
148
|
-
if (parsed === undefined || !parsed.ok)
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
if (parsed === undefined || !parsed.ok)
|
|
155
|
+
continue;
|
|
156
|
+
const kind = instanceType(parsed.document);
|
|
157
|
+
if (kind === null || kind === BUILT_IN_TYPE)
|
|
158
|
+
continue;
|
|
151
159
|
const definition = definitions.get(kind);
|
|
152
|
-
if (definition === undefined)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
160
|
+
if (definition === undefined)
|
|
161
|
+
continue;
|
|
162
|
+
for (const { target } of fieldReferences(definition, parsed.document)) {
|
|
163
|
+
const resolved = classifyHref(file, target);
|
|
164
|
+
if (resolved.kind !== 'path')
|
|
165
|
+
continue;
|
|
166
|
+
if (documents.has(resolved.path))
|
|
167
|
+
continue;
|
|
168
|
+
const referrers = missing.get(resolved.path) ?? [];
|
|
169
|
+
referrers.push(file);
|
|
170
|
+
missing.set(resolved.path, referrers);
|
|
164
171
|
}
|
|
165
172
|
}
|
|
166
|
-
const missingPaths = [
|
|
167
|
-
...missing.keys()
|
|
168
|
-
].sort();
|
|
173
|
+
const missingPaths = [...missing.keys()].sort();
|
|
169
174
|
if (missingPaths.length > 0) {
|
|
170
175
|
const path = missingPaths[0];
|
|
171
|
-
const referrers = [
|
|
172
|
-
|
|
173
|
-
].sort();
|
|
174
|
-
return refuse(path, 'referenced-missing-file', {
|
|
175
|
-
referrers
|
|
176
|
-
});
|
|
176
|
+
const referrers = [...new Set(missing.get(path) ?? [])].sort();
|
|
177
|
+
return refuse(path, 'referenced-missing-file', { referrers });
|
|
177
178
|
}
|
|
178
|
-
return {
|
|
179
|
-
verdict: 'accept'
|
|
180
|
-
};
|
|
179
|
+
return { verdict: 'accept' };
|
|
181
180
|
}
|
|
182
|
-
|
|
183
|
-
//# sourceMappingURL=validate.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.19";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/dist/version.js
CHANGED
package/dist/yaml.d.ts
CHANGED
|
@@ -27,11 +27,13 @@ export type YamlMap = {
|
|
|
27
27
|
readonly end: number;
|
|
28
28
|
};
|
|
29
29
|
export type YamlNode = YamlScalar | YamlSeq | YamlMap;
|
|
30
|
+
export declare function interpretPlain(text: string): string | number | boolean | null;
|
|
30
31
|
export declare function parseYamlMapping(text: string, start: number, end: number): YamlMap;
|
|
31
32
|
export declare function jsValue(node: YamlNode): unknown;
|
|
32
33
|
export declare function mapEntry(map: YamlMap, key: string): YamlEntry | undefined;
|
|
33
34
|
export declare function isPlainSafe(text: string): boolean;
|
|
34
35
|
export declare function serializeJs(value: unknown): string;
|
|
36
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
35
37
|
export declare function serializeKey(name: string): string;
|
|
36
38
|
export declare function bodyStartAfterYaml(content: string, yamlEnd: number): number;
|
|
37
39
|
export declare function bodyStartOf(content: string): number;
|
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,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