@agentshouse/mdmodel 0.1.0-ccf1367190878 → 0.1.0-cd90851746292
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 +152 -142
- package/README.md +16 -19
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +35 -20
- package/dist/condition.d.ts +41 -10
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +218 -85
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +105 -21
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +27 -17
- package/dist/document.d.ts +5 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +304 -187
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/links.d.ts +2 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +107 -50
- 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 +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +38 -15
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -1
- 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 +28 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +27 -3
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +219 -70
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +9 -4
- 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/division.json +26 -26
- package/package.json +7 -2
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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M,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;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,8 +1,32 @@
|
|
|
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
|
-
export declare function checkDocument(file: string, content: string, model: VerifiedModel): DocumentCheck;
|
|
4
|
+
export declare function verify(schema: string, provided?: VerifiedModel): ModelVerification;
|
|
5
|
+
export declare function checkDocument(file: string, content: string, model: VerifiedModel, context?: Pick<ValidationContext, 'anyRoom'>): DocumentCheck;
|
|
6
6
|
export declare function sectionReferences(file: string, content: string, definition: Definition): readonly Reached[];
|
|
7
|
+
export declare function bodyRoomLinks(body: string): RoomReference[];
|
|
8
|
+
export declare function roomReferences(file: string, content: string, definition?: Definition): readonly RoomReference[];
|
|
9
|
+
type Placed = {
|
|
10
|
+
readonly reference: Reached;
|
|
11
|
+
readonly location: string;
|
|
12
|
+
};
|
|
13
|
+
export type Assessment = {
|
|
14
|
+
readonly file: string;
|
|
15
|
+
readonly type: string | undefined;
|
|
16
|
+
readonly targets: readonly string[];
|
|
17
|
+
readonly read: Validation | null;
|
|
18
|
+
readonly structured: Validation | null;
|
|
19
|
+
readonly fields: readonly Placed[];
|
|
20
|
+
readonly linked: boolean;
|
|
21
|
+
readonly sections: readonly Placed[];
|
|
22
|
+
};
|
|
23
|
+
export declare function assess(file: string, content: string, binary: boolean, model?: VerifiedModel, context?: Pick<ValidationContext, 'anyRoom'>): Assessment;
|
|
24
|
+
export type Verdicts = {
|
|
25
|
+
add(assessment: Assessment, typeOf: (path: string) => string | undefined, binary: (path: string) => boolean): number;
|
|
26
|
+
verdict(): Validation;
|
|
27
|
+
};
|
|
28
|
+
export declare function verdicts(): Verdicts;
|
|
29
|
+
export declare function validating(library: ReadonlyMap<string, string>, context?: ValidationContext, model?: VerifiedModel): Generator<ValidationStep, Validation, void>;
|
|
7
30
|
export declare function validate(library: Library, context?: ValidationContext, model?: VerifiedModel): Validation;
|
|
31
|
+
export {};
|
|
8
32
|
//# 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,M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/dist/validate.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ATTACHMENT, BUILT_IN_TYPE, readSchema } from './definition.js';
|
|
2
2
|
import { parse } from './document.js';
|
|
3
3
|
import { hrefOccurrences, linkInventory } from './links.js';
|
|
4
|
-
import { classifyHref } from './paths.js';
|
|
4
|
+
import { classifyHref, roomTarget } from './paths.js';
|
|
5
5
|
import { references } from './references.js';
|
|
6
6
|
import { refusal } from './refuse.js';
|
|
7
|
-
import { fitsItem, frontmatterRefusal } from './schema.js';
|
|
7
|
+
import { conditionedSections, fitsItem, frontmatterRefusal } from './schema.js';
|
|
8
|
+
import { openPatternBudget, PatternTooCostly } from './pattern.js';
|
|
8
9
|
import { headingSpans, listItems } from './sections.js';
|
|
9
10
|
import { bodyAfterFrontmatter, bodyStartOf } from './yaml.js';
|
|
10
11
|
function refuse(file, rule, extra) {
|
|
@@ -60,8 +61,8 @@ function itemHrefs(content, items, uses) {
|
|
|
60
61
|
}
|
|
61
62
|
return hrefs;
|
|
62
63
|
}
|
|
63
|
-
export function verify(schema) {
|
|
64
|
-
const read = readSchema(schema);
|
|
64
|
+
export function verify(schema, provided) {
|
|
65
|
+
const read = readSchema(schema, provided);
|
|
65
66
|
if ('types' in read)
|
|
66
67
|
return { verdict: 'accept', model: read };
|
|
67
68
|
return {
|
|
@@ -80,10 +81,14 @@ function structure(file, content, document, definition) {
|
|
|
80
81
|
const spans = headingSpans(content, bodyStartOf(content));
|
|
81
82
|
const uses = usesIn(content);
|
|
82
83
|
const sections = [];
|
|
84
|
+
const conditioned = conditionedSections(definition, document.fields);
|
|
83
85
|
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
84
86
|
const occurrences = spans.filter((one) => one.name === name);
|
|
85
87
|
if (occurrences.length === 0 && spec.required)
|
|
86
88
|
return { refusal: refuse(file, 'required-section', { location: name }) };
|
|
89
|
+
if (conditioned.includes(name) &&
|
|
90
|
+
occurrences.every((span) => content.slice(span.bodyStart, span.bodyEnd).trim() === ''))
|
|
91
|
+
return { refusal: refuse(file, 'conditional-section', { location: name }) };
|
|
87
92
|
if (spec.kind !== 'list')
|
|
88
93
|
continue;
|
|
89
94
|
for (const span of occurrences) {
|
|
@@ -96,7 +101,12 @@ function structure(file, content, document, definition) {
|
|
|
96
101
|
const hrefs = itemHrefs(content, items, uses);
|
|
97
102
|
if (hrefs === null)
|
|
98
103
|
return { refusal: refuse(file, 'structured-section', { location: name }) };
|
|
99
|
-
sections.push({
|
|
104
|
+
sections.push({
|
|
105
|
+
section: name,
|
|
106
|
+
to: spec.items.reference,
|
|
107
|
+
crossRoom: spec.items.crossRoom === true,
|
|
108
|
+
hrefs,
|
|
109
|
+
});
|
|
100
110
|
}
|
|
101
111
|
}
|
|
102
112
|
return { sections };
|
|
@@ -108,11 +118,15 @@ function reached(file, href, to) {
|
|
|
108
118
|
const resolved = classifyHref(file, href);
|
|
109
119
|
return { target: resolved.kind === 'path' ? resolved.path : null, to };
|
|
110
120
|
}
|
|
121
|
+
function crossing(file, href, crossRoom) {
|
|
122
|
+
return crossRoom === true && classifyHref(file, href).kind === 'room';
|
|
123
|
+
}
|
|
111
124
|
function definitionOf(document, model) {
|
|
112
125
|
const kind = instanceType(document);
|
|
113
126
|
return kind === null || !Object.hasOwn(model.types, kind) ? undefined : model.types[kind];
|
|
114
127
|
}
|
|
115
|
-
export function checkDocument(file, content, model) {
|
|
128
|
+
export function checkDocument(file, content, model, context = {}) {
|
|
129
|
+
const anyRoom = context.anyRoom === true;
|
|
116
130
|
const parsed = parse(content, file);
|
|
117
131
|
if (!parsed.ok)
|
|
118
132
|
return { ok: false };
|
|
@@ -129,92 +143,227 @@ export function checkDocument(file, content, model) {
|
|
|
129
143
|
type,
|
|
130
144
|
typed: true,
|
|
131
145
|
references: [
|
|
132
|
-
...references(document, definition).
|
|
133
|
-
...read.sections.flatMap(({ to, hrefs }) => hrefs.
|
|
146
|
+
...references(document, definition).flatMap(({ value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom) ? [] : [reached(file, value, to)]),
|
|
147
|
+
...read.sections.flatMap(({ to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom) ? [] : [reached(file, href, to)])),
|
|
134
148
|
],
|
|
135
149
|
};
|
|
136
150
|
}
|
|
137
151
|
export function sectionReferences(file, content, definition) {
|
|
138
152
|
const referring = (name) => {
|
|
139
153
|
const spec = Object.hasOwn(definition.sections, name) ? definition.sections[name] : undefined;
|
|
140
|
-
return spec?.kind === 'list'
|
|
154
|
+
return spec?.kind === 'list' && spec.items.reference !== undefined ? spec.items : undefined;
|
|
141
155
|
};
|
|
142
156
|
if (!Object.keys(definition.sections).some((name) => referring(name) !== undefined))
|
|
143
157
|
return [];
|
|
144
158
|
const uses = usesIn(content);
|
|
145
159
|
const found = [];
|
|
146
160
|
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
161
|
+
const items = referring(span.name);
|
|
162
|
+
if (items === undefined)
|
|
149
163
|
continue;
|
|
150
|
-
const
|
|
151
|
-
const hrefs =
|
|
164
|
+
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
165
|
+
const hrefs = listed === null ? null : itemHrefs(content, listed, uses);
|
|
152
166
|
for (const href of hrefs ?? [])
|
|
153
|
-
|
|
167
|
+
if (!crossing(file, href, items.crossRoom))
|
|
168
|
+
found.push(reached(file, href, items.reference));
|
|
154
169
|
}
|
|
155
170
|
return found;
|
|
156
171
|
}
|
|
157
|
-
export function
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const documents = new Map();
|
|
164
|
-
for (const file of files) {
|
|
165
|
-
if (binaryTargets.has(file))
|
|
166
|
-
return refuse(file, 'binary-target-document');
|
|
167
|
-
const parsed = parse(library[file], file);
|
|
168
|
-
if (!parsed.ok)
|
|
169
|
-
return { verdict: 'refuse', ...parsed.refusal };
|
|
170
|
-
types.set(file, parsed.document.type ?? BUILT_IN_TYPE);
|
|
171
|
-
if (instanceType(parsed.document) !== BUILT_IN_TYPE)
|
|
172
|
-
documents.set(file, parsed.document);
|
|
172
|
+
export function bodyRoomLinks(body) {
|
|
173
|
+
const found = [];
|
|
174
|
+
for (const href of new Set(hrefOccurrences(body).map((occurrence) => occurrence.href))) {
|
|
175
|
+
const room = roomTarget(href);
|
|
176
|
+
if (room !== null)
|
|
177
|
+
found.push({ kind: 'link', href, ...room });
|
|
173
178
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
return found;
|
|
180
|
+
}
|
|
181
|
+
export function roomReferences(file, content, definition) {
|
|
182
|
+
const found = bodyRoomLinks(bodyAfterFrontmatter(content));
|
|
183
|
+
if (definition === undefined)
|
|
184
|
+
return found;
|
|
185
|
+
const parsed = parse(content, file);
|
|
186
|
+
if (!parsed.ok)
|
|
187
|
+
return found;
|
|
188
|
+
for (const { pointer, value, to, crossRoom } of references(parsed.document, definition)) {
|
|
189
|
+
const room = roomTarget(value);
|
|
190
|
+
if (room !== null)
|
|
191
|
+
found.push({
|
|
192
|
+
kind: 'field',
|
|
193
|
+
pointer,
|
|
194
|
+
value,
|
|
195
|
+
to,
|
|
196
|
+
...room,
|
|
197
|
+
...(crossRoom ? { crossRoom } : {}),
|
|
198
|
+
});
|
|
180
199
|
}
|
|
181
|
-
const
|
|
182
|
-
for (const
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
const uses = usesIn(content);
|
|
201
|
+
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
202
|
+
const spec = Object.hasOwn(definition.sections, span.name)
|
|
203
|
+
? definition.sections[span.name]
|
|
204
|
+
: undefined;
|
|
205
|
+
if (spec?.kind !== 'list' || spec.items.reference === undefined)
|
|
206
|
+
continue;
|
|
207
|
+
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
208
|
+
for (const href of (listed === null ? null : itemHrefs(content, listed, uses)) ?? []) {
|
|
209
|
+
const room = roomTarget(href);
|
|
210
|
+
if (room !== null)
|
|
211
|
+
found.push({
|
|
212
|
+
kind: 'item',
|
|
213
|
+
section: span.name,
|
|
214
|
+
href,
|
|
215
|
+
to: spec.items.reference,
|
|
216
|
+
...room,
|
|
217
|
+
...(spec.items.crossRoom === true ? { crossRoom: true } : {}),
|
|
218
|
+
});
|
|
200
219
|
}
|
|
201
|
-
named.set(file, [...fields, ...sections]);
|
|
202
220
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
221
|
+
return found;
|
|
222
|
+
}
|
|
223
|
+
function least(refused, file, verdict) {
|
|
224
|
+
return refused === undefined || file < refused.file ? { file, verdict } : refused;
|
|
225
|
+
}
|
|
226
|
+
export function assess(file, content, binary, model = { types: {} }, context = {}) {
|
|
227
|
+
const unread = { file, type: undefined, targets: [], structured: null, fields: [], sections: [] };
|
|
228
|
+
if (binary)
|
|
229
|
+
return { ...unread, read: refuse(file, 'binary-target-document'), linked: true };
|
|
230
|
+
const parsed = parse(content, file);
|
|
231
|
+
if (!parsed.ok)
|
|
232
|
+
return { ...unread, read: { verdict: 'refuse', ...parsed.refusal }, linked: true };
|
|
233
|
+
const document = parsed.document;
|
|
234
|
+
const type = document.type ?? BUILT_IN_TYPE;
|
|
235
|
+
const typed = { file, type, read: null, structured: null };
|
|
236
|
+
if (instanceType(document) === BUILT_IN_TYPE) {
|
|
237
|
+
return { ...typed, targets: [], fields: [], linked: true, sections: [] };
|
|
238
|
+
}
|
|
239
|
+
const definition = definitionOf(document, model);
|
|
240
|
+
try {
|
|
241
|
+
return structured(file, content, typed, document, definition, context);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (!(error instanceof PatternTooCostly))
|
|
245
|
+
throw error;
|
|
246
|
+
return {
|
|
247
|
+
...typed,
|
|
248
|
+
targets: [],
|
|
249
|
+
structured: refuse(file, 'pattern', { location: '' }),
|
|
250
|
+
fields: [],
|
|
251
|
+
linked: true,
|
|
252
|
+
sections: [],
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function structured(file, content, typed, document, definition, context) {
|
|
257
|
+
const read = structure(file, content, document, definition);
|
|
258
|
+
if ('refusal' in read || definition === undefined) {
|
|
259
|
+
return {
|
|
260
|
+
...typed,
|
|
261
|
+
targets: [],
|
|
262
|
+
structured: 'refusal' in read ? read.refusal : null,
|
|
263
|
+
fields: [],
|
|
264
|
+
linked: true,
|
|
265
|
+
sections: [],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const anyRoom = context.anyRoom === true;
|
|
269
|
+
const fields = references(document, definition).flatMap(({ pointer, value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom)
|
|
270
|
+
? []
|
|
271
|
+
: [{ reference: reached(file, value, to), location: pointer }]);
|
|
272
|
+
const sections = read.sections.flatMap(({ section, to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom)
|
|
273
|
+
? []
|
|
274
|
+
: [{ reference: reached(file, href, to), location: section }]));
|
|
275
|
+
const targets = new Set();
|
|
276
|
+
for (const { reference } of [...fields, ...sections]) {
|
|
277
|
+
if (reference.target !== null)
|
|
278
|
+
targets.add(reference.target);
|
|
279
|
+
}
|
|
280
|
+
return { ...typed, targets: [...targets], fields, linked: linked(file, content), sections };
|
|
281
|
+
}
|
|
282
|
+
export function verdicts() {
|
|
283
|
+
let read;
|
|
284
|
+
let structured;
|
|
285
|
+
let referred;
|
|
286
|
+
let missed;
|
|
287
|
+
const unreached = (placed, typeOf, binary) => placed.find(({ reference }) => !reaches(reference, typeOf, binary));
|
|
288
|
+
return {
|
|
289
|
+
add(assessment, typeOf, binary) {
|
|
290
|
+
const { file } = assessment;
|
|
291
|
+
if (assessment.read !== null) {
|
|
292
|
+
read = least(read, file, assessment.read);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
if (assessment.structured !== null) {
|
|
296
|
+
structured = least(structured, file, assessment.structured);
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
const field = unreached(assessment.fields, typeOf, binary);
|
|
300
|
+
if (field !== undefined) {
|
|
301
|
+
referred = least(referred, file, refuse(file, 'unresolved-reference', { location: field.location }));
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
304
|
+
if (!assessment.linked) {
|
|
305
|
+
referred = least(referred, file, refuse(file, 'unresolved-link'));
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
const section = unreached(assessment.sections, typeOf, binary);
|
|
309
|
+
if (section !== undefined) {
|
|
310
|
+
referred = least(referred, file, refuse(file, 'unresolved-reference', { location: section.location }));
|
|
311
|
+
return 0;
|
|
312
|
+
}
|
|
313
|
+
const all = [...assessment.fields, ...assessment.sections];
|
|
314
|
+
for (const { reference } of all) {
|
|
315
|
+
if (!missing(reference, typeOf, binary))
|
|
316
|
+
continue;
|
|
317
|
+
const path = reference.target;
|
|
318
|
+
if (missed === undefined || path < missed.path)
|
|
319
|
+
missed = { path, referrers: [] };
|
|
320
|
+
if (path === missed.path && missed.referrers.at(-1) !== file)
|
|
321
|
+
missed.referrers.push(file);
|
|
322
|
+
}
|
|
323
|
+
return all.length;
|
|
324
|
+
},
|
|
325
|
+
verdict() {
|
|
326
|
+
const refused = read ?? structured ?? referred;
|
|
327
|
+
if (refused !== undefined)
|
|
328
|
+
return refused.verdict;
|
|
329
|
+
if (missed !== undefined) {
|
|
330
|
+
return refuse(missed.path, 'referenced-missing-file', {
|
|
331
|
+
referrers: [...missed.referrers].sort(),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return { verdict: 'accept' };
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
export function* validating(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
339
|
+
const binaryTargets = new Set(context.binaryTargets);
|
|
340
|
+
const binary = (path) => binaryTargets.has(path);
|
|
341
|
+
const types = new Map();
|
|
342
|
+
const assessments = [];
|
|
343
|
+
const closeBudget = openPatternBudget();
|
|
344
|
+
try {
|
|
345
|
+
for (const [file, content] of library) {
|
|
346
|
+
const assessment = assess(file, content, binary(file), model, context);
|
|
347
|
+
if (assessment.type !== undefined)
|
|
348
|
+
types.set(file, assessment.type);
|
|
349
|
+
assessments.push(assessment);
|
|
350
|
+
yield { path: file, resolved: 0 };
|
|
351
|
+
}
|
|
352
|
+
const judged = verdicts();
|
|
353
|
+
for (const assessment of assessments) {
|
|
354
|
+
const resolved = judged.add(assessment, (path) => types.get(path), binary);
|
|
355
|
+
yield { path: assessment.file, resolved };
|
|
211
356
|
}
|
|
357
|
+
return judged.verdict();
|
|
212
358
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const path = missingPaths[0];
|
|
216
|
-
const referrers = [...new Set(absent.get(path) ?? [])].sort();
|
|
217
|
-
return refuse(path, 'referenced-missing-file', { referrers });
|
|
359
|
+
finally {
|
|
360
|
+
closeBudget();
|
|
218
361
|
}
|
|
219
|
-
|
|
362
|
+
}
|
|
363
|
+
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
364
|
+
const steps = validating(new Map(Object.entries(library)), context, model);
|
|
365
|
+
let step = steps.next();
|
|
366
|
+
while (step.done !== true)
|
|
367
|
+
step = steps.next();
|
|
368
|
+
return step.value;
|
|
220
369
|
}
|
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,S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AAC,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
|
@@ -6,6 +6,18 @@ export class YamlError extends Error {
|
|
|
6
6
|
this.name = 'YamlError';
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
const YAML_DEPTH_MAX = 64;
|
|
10
|
+
function nested(c, parse) {
|
|
11
|
+
if (c.depth >= YAML_DEPTH_MAX)
|
|
12
|
+
throw new YamlError(c.i);
|
|
13
|
+
c.depth += 1;
|
|
14
|
+
try {
|
|
15
|
+
return parse();
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
c.depth -= 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
9
21
|
function peek(c) {
|
|
10
22
|
return c.i < c.end ? c.text[c.i] : '';
|
|
11
23
|
}
|
|
@@ -70,7 +82,10 @@ function indentAt(c) {
|
|
|
70
82
|
}
|
|
71
83
|
return n;
|
|
72
84
|
}
|
|
85
|
+
const UNHELD_TEXT = /[\0\ud800-\udfff]/u;
|
|
73
86
|
function scalar(value, start, end) {
|
|
87
|
+
if (typeof value === 'string' && UNHELD_TEXT.test(value))
|
|
88
|
+
throw new YamlError(start);
|
|
74
89
|
return { kind: 'scalar', value, start, end };
|
|
75
90
|
}
|
|
76
91
|
export function interpretPlain(text) {
|
|
@@ -202,6 +217,9 @@ function parseFlowValue(c) {
|
|
|
202
217
|
return parseScalar(c, true);
|
|
203
218
|
}
|
|
204
219
|
function parseFlowMap(c) {
|
|
220
|
+
return nested(c, () => flowMap(c));
|
|
221
|
+
}
|
|
222
|
+
function flowMap(c) {
|
|
205
223
|
const start = c.i;
|
|
206
224
|
if (peek(c) !== '{')
|
|
207
225
|
throw new YamlError(c.i);
|
|
@@ -240,6 +258,9 @@ function parseFlowMap(c) {
|
|
|
240
258
|
throw new YamlError(c.i);
|
|
241
259
|
}
|
|
242
260
|
function parseFlowSeq(c) {
|
|
261
|
+
return nested(c, () => flowSeq(c));
|
|
262
|
+
}
|
|
263
|
+
function flowSeq(c) {
|
|
243
264
|
const start = c.i;
|
|
244
265
|
if (peek(c) !== '[')
|
|
245
266
|
throw new YamlError(c.i);
|
|
@@ -336,6 +357,9 @@ function parseSeqItem(c, indent) {
|
|
|
336
357
|
return parseValue(c, indent);
|
|
337
358
|
}
|
|
338
359
|
function parseBlockSeq(c, indent) {
|
|
360
|
+
return nested(c, () => blockSeq(c, indent));
|
|
361
|
+
}
|
|
362
|
+
function blockSeq(c, indent) {
|
|
339
363
|
const start = c.i;
|
|
340
364
|
const items = [];
|
|
341
365
|
let end = start;
|
|
@@ -355,6 +379,9 @@ function parseBlockSeq(c, indent) {
|
|
|
355
379
|
return { kind: 'seq', items, start, end };
|
|
356
380
|
}
|
|
357
381
|
function parseBlockMap(c, indent, inline = false) {
|
|
382
|
+
return nested(c, () => blockMap(c, indent, inline));
|
|
383
|
+
}
|
|
384
|
+
function blockMap(c, indent, inline) {
|
|
358
385
|
const start = c.i;
|
|
359
386
|
const entries = [];
|
|
360
387
|
const seen = new Set();
|
|
@@ -387,7 +414,7 @@ function parseBlockMap(c, indent, inline = false) {
|
|
|
387
414
|
return { kind: 'map', entries, start, end };
|
|
388
415
|
}
|
|
389
416
|
export function parseYamlMapping(text, start, end) {
|
|
390
|
-
const c = { text, i: start, end };
|
|
417
|
+
const c = { text, i: start, end, depth: 0 };
|
|
391
418
|
skipBlankAndComments(c);
|
|
392
419
|
if (c.i >= end)
|
|
393
420
|
return { kind: 'map', entries: [], start, end };
|
|
@@ -439,17 +466,23 @@ function listed(value) {
|
|
|
439
466
|
return keys.length === value.length && keys.every((key, index) => key === String(index));
|
|
440
467
|
}
|
|
441
468
|
function heldWithin(value, within) {
|
|
442
|
-
if (
|
|
469
|
+
if (typeof value === 'string')
|
|
470
|
+
return !UNHELD_TEXT.test(value);
|
|
471
|
+
if (value === null || typeof value === 'boolean')
|
|
443
472
|
return true;
|
|
444
473
|
if (typeof value === 'number')
|
|
445
474
|
return Number.isFinite(value);
|
|
446
475
|
if (typeof value !== 'object' || within.includes(value))
|
|
447
476
|
return false;
|
|
477
|
+
if (within.length + 1 >= YAML_DEPTH_MAX)
|
|
478
|
+
return false;
|
|
448
479
|
const path = [...within, value];
|
|
449
480
|
const held = (item) => heldWithin(item, path);
|
|
450
481
|
if (Array.isArray(value))
|
|
451
482
|
return listed(value) && value.every(held);
|
|
452
|
-
return plain(value) &&
|
|
483
|
+
return (plain(value) &&
|
|
484
|
+
Object.keys(value).every((key) => !UNHELD_TEXT.test(key)) &&
|
|
485
|
+
Object.values(value).every(held));
|
|
453
486
|
}
|
|
454
487
|
export function frontmatterValue(value) {
|
|
455
488
|
return heldWithin(value, []);
|
package/fixtures/README.md
CHANGED
|
@@ -51,8 +51,8 @@ change to a value that is not prose leaves the projection alone.
|
|
|
51
51
|
|
|
52
52
|
`division.json` exercises the public `divide` seam separately from the
|
|
53
53
|
validation Libraries. It carries `schema` and `cases` like `projection.json`,
|
|
54
|
-
and each case adds the `
|
|
55
|
-
`divide(document, file, context)` with `{ documentTargets, definition,
|
|
54
|
+
and each case adds the `bound` the division runs under. Parse the source, call
|
|
55
|
+
`divide(document, file, context)` with `{ documentTargets, definition, bound }`,
|
|
56
56
|
and compare against `expected`: either `{ "ok": true, "spans": [...] }`, where
|
|
57
57
|
each span carries the exact `text` to embed and the exact `source` the returned
|
|
58
58
|
`start` and `end` address in that case's source, or `{ "ok": false, "refusal": ... }`. Then
|
|
@@ -107,6 +107,7 @@ schema text. The model's own rules:
|
|
|
107
107
|
| `frontmatter-fence` | A present frontmatter fence does not parse as the accepted YAML subset |
|
|
108
108
|
| `schema-yaml` | A schema text is not a mapping in the accepted YAML subset |
|
|
109
109
|
| `schema-type-name` | A type name is empty, starts with `$`, or is `any` or `attachment` |
|
|
110
|
+
| `provided-type` | A schema names a type its caller provides with a key but its two role keywords |
|
|
110
111
|
| `schema` | A type or subschema is neither a mapping nor a boolean |
|
|
111
112
|
| `schema-keyword` | A schema carries a key that is no JSON Schema 2020-12 keyword the model admits |
|
|
112
113
|
| `$defs` | `$defs` is not a mapping |
|
|
@@ -117,14 +118,18 @@ schema text. The model's own rules:
|
|
|
117
118
|
| `unknown-type` | A file declares a type absent from the governing schema |
|
|
118
119
|
| `undeclared-field` | A closed object carries a key it does not declare |
|
|
119
120
|
| `required-section` | A required section heading is missing |
|
|
121
|
+
| `conditional-section` | A section its type's `if` branch requires is absent or holds no text |
|
|
120
122
|
| `unresolved-reference` | A reference at any depth or a section item reaches no member it admits |
|
|
121
123
|
| `unresolved-link` | A body link is an absolute path or leaves the collection |
|
|
122
124
|
| `structured-section` | A declared list section is not a list of values of its item schema |
|
|
123
125
|
| `referenced-missing-file` | Remaining files still reference an absent path |
|
|
124
126
|
| `unwritable-link` | No Markdown destination form can carry a new link destination |
|
|
125
|
-
| `division-
|
|
127
|
+
| `division-bound` | A division bound is not a whole number of at least 2 |
|
|
126
128
|
|
|
127
|
-
`
|
|
129
|
+
A `then` or `else` of an `if` on a type, in its `allOf` or in such a branch may hold
|
|
130
|
+
`sections`, naming sections the type declares as the type declares them, else `sections`.
|
|
131
|
+
|
|
132
|
+
`unwritable-link` is refused by `apply` and `division-bound` by `divide`, not
|
|
128
133
|
by `validate`, so no case under `cases/` carries either.
|
|
129
134
|
|
|
130
135
|
A reference that admits `attachment` reaches any path in the same Library, so
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
question:
|
|
2
|
+
properties:
|
|
3
|
+
title: { type: string }
|
|
4
|
+
status: { enum: [open, answered, withdrawn] }
|
|
5
|
+
required: [title, status]
|
|
6
|
+
sections:
|
|
7
|
+
Question: { kind: text, required: true }
|
|
8
|
+
Answer: { kind: text }
|
|
9
|
+
if:
|
|
10
|
+
properties:
|
|
11
|
+
status: { enum: [answered, withdrawn] }
|
|
12
|
+
then:
|
|
13
|
+
sections:
|
|
14
|
+
Answer: { kind: text, required: true }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "binaryTargets": [] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "verdict": "accept" }
|