@agentshouse/mdmodel 0.1.0-cabd61587647f → 0.1.0-caefdbe3e3d42
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 +161 -116
- package/README.md +6 -4
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +29 -7
- package/dist/condition.d.ts +43 -13
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +225 -127
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +105 -21
- package/dist/divide.js +9 -9
- package/dist/document.d.ts +4 -4
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +41 -41
- package/dist/index.d.ts +20 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +141 -0
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +85 -39
- package/dist/paths.d.ts +9 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +28 -2
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +355 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +7 -7
- package/dist/query/language.d.ts +218 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +526 -0
- package/dist/query/match.d.ts +12 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +118 -0
- package/dist/query/rows.d.ts +32 -0
- package/dist/query/rows.d.ts.map +1 -0
- package/dist/query/rows.js +161 -0
- package/dist/query/sql.d.ts +39 -0
- package/dist/query/sql.d.ts.map +1 -0
- package/dist/query/sql.js +279 -0
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- package/dist/reserved.d.ts +5 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +20 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +55 -4
- package/dist/types.d.ts +34 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +28 -4
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +302 -75
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +26 -6
- package/fixtures/cases/conditional-section/context.json +1 -0
- package/fixtures/cases/conditional-section/expected.json +6 -0
- package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
- package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
- package/fixtures/cases/conditional-section/schema.yaml +14 -0
- package/fixtures/cases/cross-room-link/context.json +1 -0
- package/fixtures/cases/cross-room-link/expected.json +1 -0
- package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
- package/fixtures/cases/cross-room-link/schema.yaml +3 -0
- package/fixtures/cases/cross-room-reference/context.json +1 -0
- package/fixtures/cases/cross-room-reference/expected.json +1 -0
- package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
- package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
- package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
- package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
- package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
- package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
- package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
- package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/context.json +1 -0
- package/fixtures/cases/member-on-another-type/expected.json +6 -0
- package/fixtures/cases/member-on-another-type/library/note.md +4 -0
- package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
- package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
- package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
- package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
- package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
- package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
- package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
- package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
- package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
- package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
- package/fixtures/division.json +26 -26
- package/fixtures/queries.json +913 -0
- package/package.json +7 -2
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Definition } from './definition.js';
|
|
|
2
2
|
export type Library = Readonly<Record<string, string>>;
|
|
3
3
|
export type VerifiedModel = {
|
|
4
4
|
readonly types: Readonly<Record<string, Definition>>;
|
|
5
|
+
readonly nameable?: readonly string[];
|
|
5
6
|
};
|
|
6
7
|
export type ModelVerification = {
|
|
7
8
|
readonly verdict: 'accept';
|
|
@@ -11,15 +12,23 @@ export type ModelVerification = {
|
|
|
11
12
|
readonly rule: string;
|
|
12
13
|
readonly location?: string;
|
|
13
14
|
};
|
|
15
|
+
export type TypedPath = {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly type: string;
|
|
18
|
+
readonly named: boolean;
|
|
19
|
+
readonly body: boolean;
|
|
20
|
+
};
|
|
14
21
|
export type ValidationContext = {
|
|
15
22
|
readonly binaryTargets: readonly string[];
|
|
23
|
+
readonly anyRoom?: true;
|
|
24
|
+
readonly typedPaths?: readonly TypedPath[];
|
|
16
25
|
};
|
|
17
26
|
export type ProjectionContext = {
|
|
18
27
|
readonly documentTargets: readonly string[];
|
|
19
28
|
readonly definition?: Definition;
|
|
20
29
|
};
|
|
21
30
|
export type DivisionContext = ProjectionContext & {
|
|
22
|
-
readonly
|
|
31
|
+
readonly bound: number;
|
|
23
32
|
};
|
|
24
33
|
export type Extent = {
|
|
25
34
|
readonly start: number;
|
|
@@ -60,6 +69,10 @@ export type Validation = {
|
|
|
60
69
|
} | ({
|
|
61
70
|
readonly verdict: 'refuse';
|
|
62
71
|
} & Refusal);
|
|
72
|
+
export type ValidationStep = {
|
|
73
|
+
readonly path: string;
|
|
74
|
+
readonly resolved: number;
|
|
75
|
+
};
|
|
63
76
|
export type Projection = {
|
|
64
77
|
readonly ok: true;
|
|
65
78
|
readonly text: string;
|
|
@@ -92,14 +105,31 @@ export type Link = {
|
|
|
92
105
|
readonly href: string;
|
|
93
106
|
readonly target: string;
|
|
94
107
|
};
|
|
95
|
-
export type LinkOccurrence = Link & {
|
|
96
|
-
readonly start: number;
|
|
97
|
-
};
|
|
98
108
|
export type Reference = {
|
|
99
109
|
readonly pointer: string;
|
|
100
110
|
readonly value: string;
|
|
101
111
|
readonly to: readonly string[];
|
|
112
|
+
readonly crossRoom?: true;
|
|
102
113
|
};
|
|
114
|
+
export type RoomReference = {
|
|
115
|
+
readonly handle: string;
|
|
116
|
+
readonly path: string;
|
|
117
|
+
} & ({
|
|
118
|
+
readonly kind: 'link';
|
|
119
|
+
readonly href: string;
|
|
120
|
+
} | {
|
|
121
|
+
readonly kind: 'field';
|
|
122
|
+
readonly pointer: string;
|
|
123
|
+
readonly value: string;
|
|
124
|
+
readonly to: readonly string[];
|
|
125
|
+
readonly crossRoom?: true;
|
|
126
|
+
} | {
|
|
127
|
+
readonly kind: 'item';
|
|
128
|
+
readonly section: string;
|
|
129
|
+
readonly href: string;
|
|
130
|
+
readonly to: readonly string[];
|
|
131
|
+
readonly crossRoom?: true;
|
|
132
|
+
});
|
|
103
133
|
export type Change = {
|
|
104
134
|
readonly kind: 'field';
|
|
105
135
|
readonly name: 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;
|
|
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;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,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,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CA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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;IACE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,GACD;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,9 +1,33 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
|
-
import type { DocumentCheck, Library, ModelVerification, Reached, Validation, ValidationContext, VerifiedModel } from './types.js';
|
|
2
|
+
import type { DocumentCheck, Library, ModelVerification, Reached, RoomReference, Validation, ValidationContext, ValidationStep, VerifiedModel } from './types.js';
|
|
3
3
|
export declare function resolves(reference: Reached, typeOf: (path: string) => string | undefined, binary: (path: string) => boolean): boolean;
|
|
4
|
-
export declare function verify(schema: string): ModelVerification;
|
|
5
|
-
|
|
4
|
+
export declare function verify(schema: string, provided?: VerifiedModel): ModelVerification;
|
|
5
|
+
type Placing = Pick<ValidationContext, 'anyRoom' | 'typedPaths'>;
|
|
6
|
+
export declare function checkDocument(file: string, content: string, model: VerifiedModel, context?: Placing): DocumentCheck;
|
|
6
7
|
export declare function sectionReferences(file: string, content: string, definition: Definition): readonly Reached[];
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function bodyRoomLinks(body: string): RoomReference[];
|
|
9
|
+
export declare function roomReferences(file: string, content: string, definition?: Definition): readonly RoomReference[];
|
|
10
|
+
type Placed = {
|
|
11
|
+
readonly reference: Reached;
|
|
12
|
+
readonly location: string;
|
|
13
|
+
};
|
|
14
|
+
export type Assessment = {
|
|
15
|
+
readonly file: string;
|
|
16
|
+
readonly type: string | undefined;
|
|
17
|
+
readonly targets: readonly string[];
|
|
18
|
+
readonly read: Validation | null;
|
|
19
|
+
readonly structured: Validation | null;
|
|
20
|
+
readonly fields: readonly Placed[];
|
|
21
|
+
readonly linked: boolean;
|
|
22
|
+
readonly sections: readonly Placed[];
|
|
23
|
+
};
|
|
24
|
+
export declare function assess(file: string, content: string, binary: boolean, model?: VerifiedModel, context?: Placing): Assessment;
|
|
25
|
+
export type Verdicts = {
|
|
26
|
+
add(assessment: Assessment, typeOf: (path: string) => string | undefined, binary: (path: string) => boolean): number;
|
|
27
|
+
verdict(): Validation;
|
|
28
|
+
};
|
|
29
|
+
export declare function verdicts(): Verdicts;
|
|
30
|
+
export declare function validating(library: ReadonlyMap<string, string>, context?: ValidationContext, model?: VerifiedModel): Generator<ValidationStep, Validation, void>;
|
|
8
31
|
export declare function validate(library: Library, context?: ValidationContext, model?: VerifiedModel): Validation;
|
|
32
|
+
export {};
|
|
9
33
|
//# 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":"AAAA,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1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CHANGED
|
@@ -1,15 +1,62 @@
|
|
|
1
1
|
import { ATTACHMENT, BUILT_IN_TYPE, readSchema } from './definition.js';
|
|
2
|
-
import { parse } from './document.js';
|
|
2
|
+
import { links, parse } from './document.js';
|
|
3
|
+
import { MEMBER_FIELD } from './fields.js';
|
|
3
4
|
import { hrefOccurrences, linkInventory } from './links.js';
|
|
4
|
-
import { classifyHref } from './paths.js';
|
|
5
|
+
import { classifyHref, roomTarget } from './paths.js';
|
|
5
6
|
import { references } from './references.js';
|
|
7
|
+
import { isDocumentPath, ROOM_DESCRIPTION } from './reserved.js';
|
|
6
8
|
import { refusal } from './refuse.js';
|
|
7
|
-
import { fitsItem, frontmatterRefusal } from './schema.js';
|
|
9
|
+
import { conditionedSections, fitsItem, frontmatterRefusal } from './schema.js';
|
|
10
|
+
import { openPatternBudget, PatternTooCostly } from './pattern.js';
|
|
8
11
|
import { headingSpans, listItems } from './sections.js';
|
|
9
12
|
import { bodyAfterFrontmatter, bodyStartOf } from './yaml.js';
|
|
10
13
|
function refuse(file, rule, extra) {
|
|
11
14
|
return { verdict: 'refuse', ...refusal(file, rule, extra) };
|
|
12
15
|
}
|
|
16
|
+
function unmarkedMember(file, document, definition) {
|
|
17
|
+
return Object.hasOwn(document.fields, MEMBER_FIELD) && definition?.memberDocument !== true
|
|
18
|
+
? refuse(file, 'undeclared-field', { location: `/${MEMBER_FIELD}` })
|
|
19
|
+
: null;
|
|
20
|
+
}
|
|
21
|
+
function reservedLink(file, document) {
|
|
22
|
+
return (document.type !== undefined &&
|
|
23
|
+
isDocumentPath(file) &&
|
|
24
|
+
links(document, file).some((link) => !isDocumentPath(link.target)));
|
|
25
|
+
}
|
|
26
|
+
function describedRoom(file, document) {
|
|
27
|
+
return file === ROOM_DESCRIPTION && document.type !== undefined
|
|
28
|
+
? refuse(file, 'room-md-type', { location: '/type' })
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
function nameFits(pattern, name) {
|
|
32
|
+
const at = pattern.indexOf('*');
|
|
33
|
+
if (at === -1)
|
|
34
|
+
return pattern === name;
|
|
35
|
+
const head = pattern.slice(0, at);
|
|
36
|
+
const tail = pattern.slice(at + 1);
|
|
37
|
+
return name.length > head.length + tail.length && name.startsWith(head) && name.endsWith(tail);
|
|
38
|
+
}
|
|
39
|
+
function typedPathOf(file, typedPaths = []) {
|
|
40
|
+
const names = file.split('/');
|
|
41
|
+
return typedPaths.find(({ path }) => {
|
|
42
|
+
const patterns = path.split('/');
|
|
43
|
+
return (patterns.length === names.length &&
|
|
44
|
+
patterns.every((pattern, at) => nameFits(pattern, names[at])));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const HELD_TEXT = /\S/u;
|
|
48
|
+
function typedPathRefusal(file, content, document, typedPath) {
|
|
49
|
+
if (typedPath === undefined)
|
|
50
|
+
return null;
|
|
51
|
+
if (document.type !== (typedPath.named ? typedPath.type : undefined))
|
|
52
|
+
return refuse(file, 'unknown-type', { location: '/type' });
|
|
53
|
+
return typedPath.body && !HELD_TEXT.test(bodyAfterFrontmatter(content))
|
|
54
|
+
? refuse(file, 'required-body')
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
function kindOf(document, typedPath) {
|
|
58
|
+
return typedPath !== undefined && !typedPath.named ? typedPath.type : instanceType(document);
|
|
59
|
+
}
|
|
13
60
|
function instanceType(document) {
|
|
14
61
|
const raw = document.fields.type;
|
|
15
62
|
if (raw === undefined || raw === null)
|
|
@@ -60,8 +107,8 @@ function itemHrefs(content, items, uses) {
|
|
|
60
107
|
}
|
|
61
108
|
return hrefs;
|
|
62
109
|
}
|
|
63
|
-
export function verify(schema) {
|
|
64
|
-
const read = readSchema(schema);
|
|
110
|
+
export function verify(schema, provided) {
|
|
111
|
+
const read = readSchema(schema, provided);
|
|
65
112
|
if ('types' in read)
|
|
66
113
|
return { verdict: 'accept', model: read };
|
|
67
114
|
return {
|
|
@@ -80,10 +127,14 @@ function structure(file, content, document, definition) {
|
|
|
80
127
|
const spans = headingSpans(content, bodyStartOf(content));
|
|
81
128
|
const uses = usesIn(content);
|
|
82
129
|
const sections = [];
|
|
130
|
+
const conditioned = conditionedSections(definition, document.fields);
|
|
83
131
|
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
84
132
|
const occurrences = spans.filter((one) => one.name === name);
|
|
85
133
|
if (occurrences.length === 0 && spec.required)
|
|
86
134
|
return { refusal: refuse(file, 'required-section', { location: name }) };
|
|
135
|
+
if (conditioned.includes(name) &&
|
|
136
|
+
occurrences.every((span) => content.slice(span.bodyStart, span.bodyEnd).trim() === ''))
|
|
137
|
+
return { refusal: refuse(file, 'conditional-section', { location: name }) };
|
|
87
138
|
if (spec.kind !== 'list')
|
|
88
139
|
continue;
|
|
89
140
|
for (const span of occurrences) {
|
|
@@ -96,10 +147,16 @@ function structure(file, content, document, definition) {
|
|
|
96
147
|
const hrefs = itemHrefs(content, items, uses);
|
|
97
148
|
if (hrefs === null)
|
|
98
149
|
return { refusal: refuse(file, 'structured-section', { location: name }) };
|
|
99
|
-
sections.push({
|
|
150
|
+
sections.push({
|
|
151
|
+
section: name,
|
|
152
|
+
to: spec.items.reference,
|
|
153
|
+
crossRoom: spec.items.crossRoom === true,
|
|
154
|
+
hrefs,
|
|
155
|
+
});
|
|
100
156
|
}
|
|
101
157
|
}
|
|
102
|
-
|
|
158
|
+
const member = unmarkedMember(file, document, definition);
|
|
159
|
+
return member === null ? { sections } : { refusal: member };
|
|
103
160
|
}
|
|
104
161
|
function linked(file, content) {
|
|
105
162
|
return hrefOccurrences(bodyAfterFrontmatter(content)).every((occurrence) => classifyHref(file, occurrence.href).kind !== 'invalid');
|
|
@@ -108,19 +165,39 @@ function reached(file, href, to) {
|
|
|
108
165
|
const resolved = classifyHref(file, href);
|
|
109
166
|
return { target: resolved.kind === 'path' ? resolved.path : null, to };
|
|
110
167
|
}
|
|
111
|
-
function
|
|
112
|
-
const
|
|
168
|
+
function referred(file, href, to) {
|
|
169
|
+
const reference = reached(file, href, to);
|
|
170
|
+
return reference.target !== null &&
|
|
171
|
+
isDocumentPath(file) &&
|
|
172
|
+
!isDocumentPath(reference.target) &&
|
|
173
|
+
!to.includes(ATTACHMENT)
|
|
174
|
+
? { target: null, to }
|
|
175
|
+
: reference;
|
|
176
|
+
}
|
|
177
|
+
function crossing(file, href, crossRoom) {
|
|
178
|
+
return crossRoom === true && classifyHref(file, href).kind === 'room';
|
|
179
|
+
}
|
|
180
|
+
function definitionOf(kind, model) {
|
|
113
181
|
return kind === null || !Object.hasOwn(model.types, kind) ? undefined : model.types[kind];
|
|
114
182
|
}
|
|
115
|
-
export function checkDocument(file, content, model) {
|
|
183
|
+
export function checkDocument(file, content, model, context = {}) {
|
|
184
|
+
const anyRoom = context.anyRoom === true;
|
|
116
185
|
const parsed = parse(content, file);
|
|
117
186
|
if (!parsed.ok)
|
|
118
187
|
return { ok: false };
|
|
119
188
|
const document = parsed.document;
|
|
120
189
|
const type = document.type ?? BUILT_IN_TYPE;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
190
|
+
const typedPath = typedPathOf(file, context.typedPaths);
|
|
191
|
+
if (describedRoom(file, document) !== null ||
|
|
192
|
+
typedPathRefusal(file, content, document, typedPath) !== null ||
|
|
193
|
+
reservedLink(file, document))
|
|
194
|
+
return { ok: false };
|
|
195
|
+
const kind = kindOf(document, typedPath);
|
|
196
|
+
if (kind === BUILT_IN_TYPE)
|
|
197
|
+
return unmarkedMember(file, document, undefined) === null
|
|
198
|
+
? { ok: true, type, typed: false, references: [] }
|
|
199
|
+
: { ok: false };
|
|
200
|
+
const definition = definitionOf(kind, model);
|
|
124
201
|
const read = structure(file, content, document, definition);
|
|
125
202
|
if ('refusal' in read || definition === undefined || !linked(file, content))
|
|
126
203
|
return { ok: false };
|
|
@@ -129,94 +206,244 @@ export function checkDocument(file, content, model) {
|
|
|
129
206
|
type,
|
|
130
207
|
typed: true,
|
|
131
208
|
references: [
|
|
132
|
-
...references(document, definition).
|
|
133
|
-
...read.sections.flatMap(({ to, hrefs }) => hrefs.
|
|
209
|
+
...references(document, definition).flatMap(({ value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom) ? [] : [referred(file, value, to)]),
|
|
210
|
+
...read.sections.flatMap(({ to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom) ? [] : [referred(file, href, to)])),
|
|
134
211
|
],
|
|
135
212
|
};
|
|
136
213
|
}
|
|
137
214
|
export function sectionReferences(file, content, definition) {
|
|
138
215
|
const referring = (name) => {
|
|
139
216
|
const spec = Object.hasOwn(definition.sections, name) ? definition.sections[name] : undefined;
|
|
140
|
-
return spec?.kind === 'list'
|
|
217
|
+
return spec?.kind === 'list' && spec.items.reference !== undefined ? spec.items : undefined;
|
|
141
218
|
};
|
|
142
219
|
if (!Object.keys(definition.sections).some((name) => referring(name) !== undefined))
|
|
143
220
|
return [];
|
|
144
221
|
const uses = usesIn(content);
|
|
145
222
|
const found = [];
|
|
146
223
|
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
224
|
+
const items = referring(span.name);
|
|
225
|
+
if (items === undefined)
|
|
149
226
|
continue;
|
|
150
|
-
const
|
|
151
|
-
const hrefs =
|
|
227
|
+
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
228
|
+
const hrefs = listed === null ? null : itemHrefs(content, listed, uses);
|
|
152
229
|
for (const href of hrefs ?? [])
|
|
153
|
-
|
|
230
|
+
if (!crossing(file, href, items.crossRoom))
|
|
231
|
+
found.push(reached(file, href, items.reference));
|
|
232
|
+
}
|
|
233
|
+
return found;
|
|
234
|
+
}
|
|
235
|
+
export function bodyRoomLinks(body) {
|
|
236
|
+
const found = [];
|
|
237
|
+
for (const href of new Set(hrefOccurrences(body).map((occurrence) => occurrence.href))) {
|
|
238
|
+
const room = roomTarget(href);
|
|
239
|
+
if (room !== null)
|
|
240
|
+
found.push({ kind: 'link', href, ...room });
|
|
241
|
+
}
|
|
242
|
+
return found;
|
|
243
|
+
}
|
|
244
|
+
export function roomReferences(file, content, definition) {
|
|
245
|
+
const found = bodyRoomLinks(bodyAfterFrontmatter(content));
|
|
246
|
+
if (definition === undefined)
|
|
247
|
+
return found;
|
|
248
|
+
const parsed = parse(content, file);
|
|
249
|
+
if (!parsed.ok)
|
|
250
|
+
return found;
|
|
251
|
+
for (const { pointer, value, to, crossRoom } of references(parsed.document, definition)) {
|
|
252
|
+
const room = roomTarget(value);
|
|
253
|
+
if (room !== null)
|
|
254
|
+
found.push({
|
|
255
|
+
kind: 'field',
|
|
256
|
+
pointer,
|
|
257
|
+
value,
|
|
258
|
+
to,
|
|
259
|
+
...room,
|
|
260
|
+
...(crossRoom ? { crossRoom } : {}),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const uses = usesIn(content);
|
|
264
|
+
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
265
|
+
const spec = Object.hasOwn(definition.sections, span.name)
|
|
266
|
+
? definition.sections[span.name]
|
|
267
|
+
: undefined;
|
|
268
|
+
if (spec?.kind !== 'list' || spec.items.reference === undefined)
|
|
269
|
+
continue;
|
|
270
|
+
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
271
|
+
for (const href of (listed === null ? null : itemHrefs(content, listed, uses)) ?? []) {
|
|
272
|
+
const room = roomTarget(href);
|
|
273
|
+
if (room !== null)
|
|
274
|
+
found.push({
|
|
275
|
+
kind: 'item',
|
|
276
|
+
section: span.name,
|
|
277
|
+
href,
|
|
278
|
+
to: spec.items.reference,
|
|
279
|
+
...room,
|
|
280
|
+
...(spec.items.crossRoom === true ? { crossRoom: true } : {}),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
154
283
|
}
|
|
155
284
|
return found;
|
|
156
285
|
}
|
|
286
|
+
function least(refused, file, verdict) {
|
|
287
|
+
return refused === undefined || file < refused.file ? { file, verdict } : refused;
|
|
288
|
+
}
|
|
289
|
+
export function assess(file, content, binary, model = { types: {} }, context = {}) {
|
|
290
|
+
const unread = { file, type: undefined, targets: [], structured: null, fields: [], sections: [] };
|
|
291
|
+
if (binary)
|
|
292
|
+
return { ...unread, read: refuse(file, 'binary-target-document'), linked: true };
|
|
293
|
+
const parsed = parse(content, file);
|
|
294
|
+
if (!parsed.ok)
|
|
295
|
+
return { ...unread, read: { verdict: 'refuse', ...parsed.refusal }, linked: true };
|
|
296
|
+
const document = parsed.document;
|
|
297
|
+
const type = document.type ?? BUILT_IN_TYPE;
|
|
298
|
+
const typed = { file, type, read: null, structured: null };
|
|
299
|
+
const typedPath = typedPathOf(file, context.typedPaths);
|
|
300
|
+
const described = describedRoom(file, document) ?? typedPathRefusal(file, content, document, typedPath);
|
|
301
|
+
if (described !== null)
|
|
302
|
+
return { ...typed, targets: [], structured: described, fields: [], linked: true, sections: [] };
|
|
303
|
+
const kind = kindOf(document, typedPath);
|
|
304
|
+
if (kind === BUILT_IN_TYPE) {
|
|
305
|
+
const structured = unmarkedMember(file, document, undefined);
|
|
306
|
+
return {
|
|
307
|
+
...typed,
|
|
308
|
+
targets: [],
|
|
309
|
+
structured,
|
|
310
|
+
fields: [],
|
|
311
|
+
linked: !reservedLink(file, document),
|
|
312
|
+
sections: [],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const definition = definitionOf(kind, model);
|
|
316
|
+
try {
|
|
317
|
+
return structured(file, content, typed, document, definition, context);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (!(error instanceof PatternTooCostly))
|
|
321
|
+
throw error;
|
|
322
|
+
return {
|
|
323
|
+
...typed,
|
|
324
|
+
targets: [],
|
|
325
|
+
structured: refuse(file, 'pattern', { location: '' }),
|
|
326
|
+
fields: [],
|
|
327
|
+
linked: true,
|
|
328
|
+
sections: [],
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function structured(file, content, typed, document, definition, context) {
|
|
333
|
+
const read = structure(file, content, document, definition);
|
|
334
|
+
if ('refusal' in read || definition === undefined) {
|
|
335
|
+
return {
|
|
336
|
+
...typed,
|
|
337
|
+
targets: [],
|
|
338
|
+
structured: 'refusal' in read ? read.refusal : null,
|
|
339
|
+
fields: [],
|
|
340
|
+
linked: true,
|
|
341
|
+
sections: [],
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const anyRoom = context.anyRoom === true;
|
|
345
|
+
const fields = references(document, definition).flatMap(({ pointer, value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom)
|
|
346
|
+
? []
|
|
347
|
+
: [{ reference: referred(file, value, to), location: pointer }]);
|
|
348
|
+
const sections = read.sections.flatMap(({ section, to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom)
|
|
349
|
+
? []
|
|
350
|
+
: [{ reference: referred(file, href, to), location: section }]));
|
|
351
|
+
const targets = new Set();
|
|
352
|
+
for (const { reference } of [...fields, ...sections]) {
|
|
353
|
+
if (reference.target !== null)
|
|
354
|
+
targets.add(reference.target);
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
...typed,
|
|
358
|
+
targets: [...targets],
|
|
359
|
+
fields,
|
|
360
|
+
linked: linked(file, content) && !reservedLink(file, document),
|
|
361
|
+
sections,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
export function verdicts() {
|
|
365
|
+
let read;
|
|
366
|
+
let structured;
|
|
367
|
+
let referred;
|
|
368
|
+
let missed;
|
|
369
|
+
const unreached = (placed, typeOf, binary) => placed.find(({ reference }) => !reaches(reference, typeOf, binary));
|
|
370
|
+
return {
|
|
371
|
+
add(assessment, typeOf, binary) {
|
|
372
|
+
const { file } = assessment;
|
|
373
|
+
if (assessment.read !== null) {
|
|
374
|
+
read = least(read, file, assessment.read);
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
377
|
+
if (assessment.structured !== null) {
|
|
378
|
+
structured = least(structured, file, assessment.structured);
|
|
379
|
+
return 0;
|
|
380
|
+
}
|
|
381
|
+
const field = unreached(assessment.fields, typeOf, binary);
|
|
382
|
+
if (field !== undefined) {
|
|
383
|
+
referred = least(referred, file, refuse(file, 'unresolved-reference', { location: field.location }));
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
if (!assessment.linked) {
|
|
387
|
+
referred = least(referred, file, refuse(file, 'unresolved-link'));
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
const section = unreached(assessment.sections, typeOf, binary);
|
|
391
|
+
if (section !== undefined) {
|
|
392
|
+
referred = least(referred, file, refuse(file, 'unresolved-reference', { location: section.location }));
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
const all = [...assessment.fields, ...assessment.sections];
|
|
396
|
+
for (const { reference } of all) {
|
|
397
|
+
if (!missing(reference, typeOf, binary))
|
|
398
|
+
continue;
|
|
399
|
+
const path = reference.target;
|
|
400
|
+
if (missed === undefined || path < missed.path)
|
|
401
|
+
missed = { path, referrers: [] };
|
|
402
|
+
if (path === missed.path && missed.referrers.at(-1) !== file)
|
|
403
|
+
missed.referrers.push(file);
|
|
404
|
+
}
|
|
405
|
+
return all.length;
|
|
406
|
+
},
|
|
407
|
+
verdict() {
|
|
408
|
+
const refused = read ?? structured ?? referred;
|
|
409
|
+
if (refused !== undefined)
|
|
410
|
+
return refused.verdict;
|
|
411
|
+
if (missed !== undefined) {
|
|
412
|
+
return refuse(missed.path, 'referenced-missing-file', {
|
|
413
|
+
referrers: [...missed.referrers].sort(),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
return { verdict: 'accept' };
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
157
420
|
export function* validating(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
158
421
|
const binaryTargets = new Set(context.binaryTargets);
|
|
159
422
|
const binary = (path) => binaryTargets.has(path);
|
|
160
|
-
const files = Object.keys(library).sort();
|
|
161
423
|
const types = new Map();
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (instanceType(parsed.document) !== BUILT_IN_TYPE)
|
|
172
|
-
documents.set(file, parsed.document);
|
|
173
|
-
yield file;
|
|
174
|
-
}
|
|
175
|
-
const sectionReferences = new Map();
|
|
176
|
-
for (const [file, document] of documents) {
|
|
177
|
-
const read = structure(file, library[file], document, definitionOf(document, model));
|
|
178
|
-
if ('refusal' in read)
|
|
179
|
-
return read.refusal;
|
|
180
|
-
sectionReferences.set(file, read.sections);
|
|
181
|
-
yield file;
|
|
182
|
-
}
|
|
183
|
-
let least;
|
|
184
|
-
for (const [file, document] of documents) {
|
|
185
|
-
const definition = definitionOf(document, model);
|
|
186
|
-
const fields = references(document, definition).map(({ pointer, value, to }) => ({
|
|
187
|
-
reference: reached(file, value, to),
|
|
188
|
-
location: pointer,
|
|
189
|
-
}));
|
|
190
|
-
for (const { reference, location } of fields) {
|
|
191
|
-
if (!reaches(reference, typeOf, binary))
|
|
192
|
-
return refuse(file, 'unresolved-reference', { location });
|
|
424
|
+
const assessments = [];
|
|
425
|
+
const closeBudget = openPatternBudget();
|
|
426
|
+
try {
|
|
427
|
+
for (const [file, content] of library) {
|
|
428
|
+
const assessment = assess(file, content, binary(file), model, context);
|
|
429
|
+
if (assessment.type !== undefined)
|
|
430
|
+
types.set(file, assessment.type);
|
|
431
|
+
assessments.push(assessment);
|
|
432
|
+
yield { path: file, resolved: 0 };
|
|
193
433
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
.
|
|
198
|
-
.flatMap(({ section, to, hrefs }) => hrefs.map((href) => ({ reference: reached(file, href, to), location: section })));
|
|
199
|
-
for (const { reference, location } of sections) {
|
|
200
|
-
if (!reaches(reference, typeOf, binary))
|
|
201
|
-
return refuse(file, 'unresolved-reference', { location });
|
|
434
|
+
const judged = verdicts();
|
|
435
|
+
for (const assessment of assessments) {
|
|
436
|
+
const resolved = judged.add(assessment, (path) => types.get(path), binary);
|
|
437
|
+
yield { path: assessment.file, resolved };
|
|
202
438
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (least === undefined || path < least.path)
|
|
208
|
-
least = { path, referrers: [] };
|
|
209
|
-
if (path === least.path && least.referrers.at(-1) !== file)
|
|
210
|
-
least.referrers.push(file);
|
|
211
|
-
}
|
|
212
|
-
yield file;
|
|
439
|
+
return judged.verdict();
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
closeBudget();
|
|
213
443
|
}
|
|
214
|
-
if (least !== undefined)
|
|
215
|
-
return refuse(least.path, 'referenced-missing-file', { referrers: least.referrers });
|
|
216
|
-
return { verdict: 'accept' };
|
|
217
444
|
}
|
|
218
445
|
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
219
|
-
const steps = validating(library, context, model);
|
|
446
|
+
const steps = validating(new Map(Object.entries(library)), context, model);
|
|
220
447
|
let step = steps.next();
|
|
221
448
|
while (step.done !== true)
|
|
222
449
|
step = steps.next();
|
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,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