@agentshouse/mdmodel 0.1.0-c679f403bf3fb → 0.1.0-c69a8c1d0563b
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 +115 -101
- package/README.md +7 -5
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +29 -7
- package/dist/definition.d.ts +2 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +80 -26
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +15 -13
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +230 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +38 -0
- package/dist/index.d.ts +19 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/kinds.d.ts +19 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +161 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +42 -11
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -1
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +355 -0
- package/dist/query/language.d.ts +223 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +565 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +121 -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/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 +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +7 -5
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +230 -87
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +36 -3
- package/fixtures/README.md +21 -2
- 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/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/queries.json +913 -0
- package/package.json +7 -2
- package/dist/condition.d.ts +0 -162
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -616
package/dist/schema.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export type SchemaRefusal = {
|
|
|
4
4
|
readonly location: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function frontmatterRefusal(definition: Definition, fields: Readonly<Record<string, unknown>>): SchemaRefusal | undefined;
|
|
7
|
+
export declare function conditionedSections(definition: Definition, fields: Readonly<Record<string, unknown>>): readonly string[];
|
|
7
8
|
export declare function fitsItem(definition: Definition, section: string, text: string): boolean;
|
|
8
9
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0B5E,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AA6NjF,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,aAAa,GAAG,SAAS,CAI3B;AAYD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,SAAS,MAAM,EAAE,CAGnB;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMvF"}
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Validator } from '@cfworker/json-schema';
|
|
2
2
|
import { escapePointer, refTarget } from './definition.js';
|
|
3
3
|
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
4
|
+
import { withLinearRegExp } from './pattern.js';
|
|
4
5
|
import { interpretPlain, isRecord } from './yaml.js';
|
|
5
6
|
const STANDING_MAPS = ['properties', 'patternProperties'];
|
|
6
7
|
const STANDING = [
|
|
@@ -95,10 +96,49 @@ function closed(node, inPlace, defs, always = false) {
|
|
|
95
96
|
function copied(value) {
|
|
96
97
|
return JSON.parse(JSON.stringify(value));
|
|
97
98
|
}
|
|
99
|
+
function asks(asked) {
|
|
100
|
+
return asked.sections.length > 0 || asked.conditions.length > 0;
|
|
101
|
+
}
|
|
102
|
+
function branchOf(node, defs, closedDefs) {
|
|
103
|
+
if (!isRecord(node))
|
|
104
|
+
return { schema: node, asked: { sections: [], conditions: [] } };
|
|
105
|
+
const { sections, ...rest } = node;
|
|
106
|
+
const read = unconditioned(rest, defs, closedDefs);
|
|
107
|
+
const required = Object.entries(isRecord(sections) ? sections : {}).flatMap(([name, spec]) => isRecord(spec) && spec.required === true ? [name] : []);
|
|
108
|
+
return { schema: read.schema, asked: { sections: required, conditions: read.conditions } };
|
|
109
|
+
}
|
|
110
|
+
function unconditioned(node, defs, closedDefs) {
|
|
111
|
+
if (!isRecord(node))
|
|
112
|
+
return { schema: node, conditions: [] };
|
|
113
|
+
const schema = { ...node };
|
|
114
|
+
const conditions = [];
|
|
115
|
+
if (Array.isArray(node.allOf))
|
|
116
|
+
schema.allOf = node.allOf.map((entry) => {
|
|
117
|
+
const read = unconditioned(entry, defs, closedDefs);
|
|
118
|
+
conditions.push(...read.conditions);
|
|
119
|
+
return read.schema;
|
|
120
|
+
});
|
|
121
|
+
if (node.if === undefined)
|
|
122
|
+
return { schema, conditions };
|
|
123
|
+
const met = branchOf(node.then, defs, closedDefs);
|
|
124
|
+
const unmet = branchOf(node.else, defs, closedDefs);
|
|
125
|
+
if (node.then !== undefined)
|
|
126
|
+
schema.then = met.schema;
|
|
127
|
+
if (node.else !== undefined)
|
|
128
|
+
schema.else = unmet.schema;
|
|
129
|
+
if (!asks(met.asked) && !asks(unmet.asked))
|
|
130
|
+
return { schema, conditions };
|
|
131
|
+
const test = new Validator(isRecord(node.if)
|
|
132
|
+
? { ...closed(node.if, true, defs), $defs: closedDefs }
|
|
133
|
+
: node.if === true, '2020-12', false);
|
|
134
|
+
return { schema, conditions: [...conditions, { test, met: met.asked, unmet: unmet.asked }] };
|
|
135
|
+
}
|
|
98
136
|
function compile(definition) {
|
|
99
137
|
const defs = copied(definition.shape.defs);
|
|
100
|
-
const { sections, member_document: _mark, ...
|
|
138
|
+
const { sections, member_document: _mark, ...written } = copied(definition.shape.schema);
|
|
101
139
|
const closedDefs = mapped(defs, (held) => closed(held, true, defs));
|
|
140
|
+
const read = unconditioned(written, defs, closedDefs);
|
|
141
|
+
const root = read.schema;
|
|
102
142
|
const declared = isRecord(root.properties) ? root.properties : {};
|
|
103
143
|
const properties = {
|
|
104
144
|
[TYPE_FIELD]: true,
|
|
@@ -114,7 +154,7 @@ function compile(definition) {
|
|
|
114
154
|
continue;
|
|
115
155
|
lists.set(name, new Validator({ ...closed(spec.items, false, defs), $defs: closedDefs }, '2020-12', false));
|
|
116
156
|
}
|
|
117
|
-
return { frontmatter, sections: lists };
|
|
157
|
+
return { frontmatter, sections: lists, conditions: read.conditions };
|
|
118
158
|
}
|
|
119
159
|
function compiledOf(definition) {
|
|
120
160
|
const held = compiled.get(definition);
|
|
@@ -150,14 +190,25 @@ function refusalOf(errors) {
|
|
|
150
190
|
return { rule: 'schema', location: '' };
|
|
151
191
|
}
|
|
152
192
|
export function frontmatterRefusal(definition, fields) {
|
|
153
|
-
const
|
|
193
|
+
const { frontmatter } = compiledOf(definition);
|
|
194
|
+
const result = withLinearRegExp(() => frontmatter.validate(fields));
|
|
154
195
|
return result.valid ? undefined : refusalOf(result.errors);
|
|
155
196
|
}
|
|
197
|
+
function askedOf(conditions, fields) {
|
|
198
|
+
return conditions.flatMap((condition) => {
|
|
199
|
+
const asked = condition.test.validate(fields).valid ? condition.met : condition.unmet;
|
|
200
|
+
return [...asked.sections, ...askedOf(asked.conditions, fields)];
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
export function conditionedSections(definition, fields) {
|
|
204
|
+
const { conditions } = compiledOf(definition);
|
|
205
|
+
return withLinearRegExp(() => askedOf(conditions, fields));
|
|
206
|
+
}
|
|
156
207
|
export function fitsItem(definition, section, text) {
|
|
157
208
|
const spec = definition.sections[section];
|
|
158
209
|
const validator = compiledOf(definition).sections.get(section);
|
|
159
210
|
if (spec?.kind !== 'list' || validator === undefined)
|
|
160
211
|
return false;
|
|
161
212
|
const typed = spec.items.type === 'string' ? text : interpretPlain(text);
|
|
162
|
-
return validator.validate(typed).valid;
|
|
213
|
+
return withLinearRegExp(() => validator.validate(typed).valid);
|
|
163
214
|
}
|
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,9 +12,16 @@ 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[];
|
|
16
23
|
readonly anyRoom?: true;
|
|
24
|
+
readonly typedPaths?: readonly TypedPath[];
|
|
17
25
|
};
|
|
18
26
|
export type ProjectionContext = {
|
|
19
27
|
readonly documentTargets: readonly 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,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xB,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,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,11 +1,12 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
|
-
import type { DocumentCheck, Library, ModelVerification, Reached, RoomReference, Validation, ValidationContext, ValidationStep, VerifiedModel } from './types.js';
|
|
2
|
+
import type { Document, DocumentCheck, Library, ModelVerification, ParseResult, 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
4
|
export declare function verify(schema: string, provided?: VerifiedModel): ModelVerification;
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
5
|
+
export declare function readTypes(schema: string, provided?: VerifiedModel): VerifiedModel;
|
|
6
|
+
type Placing = Pick<ValidationContext, 'anyRoom' | 'typedPaths'>;
|
|
7
|
+
export declare function checkDocument(file: string, content: string, model: VerifiedModel, context?: Placing): DocumentCheck;
|
|
7
8
|
export declare function bodyRoomLinks(body: string): RoomReference[];
|
|
8
|
-
export declare function roomReferences(
|
|
9
|
+
export declare function roomReferences(document: Document, definition?: Definition): readonly RoomReference[];
|
|
9
10
|
type Placed = {
|
|
10
11
|
readonly reference: Reached;
|
|
11
12
|
readonly location: string;
|
|
@@ -20,7 +21,8 @@ export type Assessment = {
|
|
|
20
21
|
readonly linked: boolean;
|
|
21
22
|
readonly sections: readonly Placed[];
|
|
22
23
|
};
|
|
23
|
-
export declare function assess(file: string,
|
|
24
|
+
export declare function assess(file: string, parsed: ParseResult, binary: boolean, model?: VerifiedModel, context?: Placing): Assessment;
|
|
25
|
+
export declare function assessReferences(file: string, parsed: ParseResult, changed: ReadonlySet<string>, model?: VerifiedModel, context?: Placing): Assessment;
|
|
24
26
|
export type Verdicts = {
|
|
25
27
|
add(assessment: Assessment, typeOf: (path: string) => string | undefined, binary: (path: string) => boolean): number;
|
|
26
28
|
verdict(): Validation;
|
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,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":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AQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAKZ"}
|
package/dist/validate.js
CHANGED
|
@@ -1,15 +1,62 @@
|
|
|
1
|
-
import { ATTACHMENT, BUILT_IN_TYPE, readSchema } from './definition.js';
|
|
2
|
-
import { parse } from './document.js';
|
|
1
|
+
import { ATTACHMENT, BUILT_IN_TYPE, readSchema, } from './definition.js';
|
|
2
|
+
import { links, parse } from './document.js';
|
|
3
|
+
import { MEMBER_FIELD } from './fields.js';
|
|
3
4
|
import { hrefOccurrences, linkInventory } from './links.js';
|
|
4
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, changed) {
|
|
22
|
+
return (document.type !== undefined &&
|
|
23
|
+
isDocumentPath(file) &&
|
|
24
|
+
links(document, file).some((link) => !isDocumentPath(link.target) && (changed?.has(link.target) ?? true)));
|
|
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,6 +107,32 @@ function itemHrefs(content, items, uses) {
|
|
|
60
107
|
}
|
|
61
108
|
return hrefs;
|
|
62
109
|
}
|
|
110
|
+
function listReads(content, definition, spans = headingSpans(content, bodyStartOf(content))) {
|
|
111
|
+
const uses = usesIn(content);
|
|
112
|
+
const reads = [];
|
|
113
|
+
for (const span of spans) {
|
|
114
|
+
const spec = Object.hasOwn(definition.sections, span.name)
|
|
115
|
+
? definition.sections[span.name]
|
|
116
|
+
: undefined;
|
|
117
|
+
if (spec?.kind !== 'list')
|
|
118
|
+
continue;
|
|
119
|
+
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
120
|
+
reads.push({
|
|
121
|
+
section: span.name,
|
|
122
|
+
items: spec.items,
|
|
123
|
+
listed,
|
|
124
|
+
hrefs: listed === null || spec.items.reference === undefined
|
|
125
|
+
? null
|
|
126
|
+
: itemHrefs(content, listed, uses),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return reads;
|
|
130
|
+
}
|
|
131
|
+
function listedReferences(reads) {
|
|
132
|
+
return reads.flatMap(({ section, items, hrefs }) => items.reference === undefined || hrefs === null
|
|
133
|
+
? []
|
|
134
|
+
: [{ section, to: items.reference, crossRoom: items.crossRoom === true, hrefs }]);
|
|
135
|
+
}
|
|
63
136
|
export function verify(schema, provided) {
|
|
64
137
|
const read = readSchema(schema, provided);
|
|
65
138
|
if ('types' in read)
|
|
@@ -70,6 +143,12 @@ export function verify(schema, provided) {
|
|
|
70
143
|
...(read.location === undefined ? {} : { location: read.location }),
|
|
71
144
|
};
|
|
72
145
|
}
|
|
146
|
+
export function readTypes(schema, provided) {
|
|
147
|
+
const read = readSchema(schema, provided, false);
|
|
148
|
+
if ('types' in read)
|
|
149
|
+
return read;
|
|
150
|
+
throw new Error(`the schema reads as no types: ${read.rule} ${read.location ?? ''}`.trim());
|
|
151
|
+
}
|
|
73
152
|
function structure(file, content, document, definition) {
|
|
74
153
|
if (definition === undefined)
|
|
75
154
|
return { refusal: refuse(file, 'unknown-type', { location: '/type' }) };
|
|
@@ -78,33 +157,28 @@ function structure(file, content, document, definition) {
|
|
|
78
157
|
return { refusal: refuse(file, fieldFailure.rule, { location: fieldFailure.location }) };
|
|
79
158
|
}
|
|
80
159
|
const spans = headingSpans(content, bodyStartOf(content));
|
|
81
|
-
const
|
|
82
|
-
const
|
|
160
|
+
const reads = listReads(content, definition, spans);
|
|
161
|
+
const conditioned = conditionedSections(definition, document.fields);
|
|
83
162
|
for (const [name, spec] of Object.entries(definition.sections)) {
|
|
84
163
|
const occurrences = spans.filter((one) => one.name === name);
|
|
85
164
|
if (occurrences.length === 0 && spec.required)
|
|
86
165
|
return { refusal: refuse(file, 'required-section', { location: name }) };
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (spec.items.reference === undefined)
|
|
95
|
-
continue;
|
|
96
|
-
const hrefs = itemHrefs(content, items, uses);
|
|
97
|
-
if (hrefs === null)
|
|
166
|
+
if (conditioned.includes(name) &&
|
|
167
|
+
occurrences.every((span) => content.slice(span.bodyStart, span.bodyEnd).trim() === ''))
|
|
168
|
+
return { refusal: refuse(file, 'conditional-section', { location: name }) };
|
|
169
|
+
for (const { items, listed, hrefs } of reads.filter((read) => read.section === name)) {
|
|
170
|
+
if (listed === null ||
|
|
171
|
+
listed.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))) ||
|
|
172
|
+
(items.reference !== undefined && hrefs === null))
|
|
98
173
|
return { refusal: refuse(file, 'structured-section', { location: name }) };
|
|
99
|
-
sections.push({
|
|
100
|
-
section: name,
|
|
101
|
-
to: spec.items.reference,
|
|
102
|
-
crossRoom: spec.items.crossRoom === true,
|
|
103
|
-
hrefs,
|
|
104
|
-
});
|
|
105
174
|
}
|
|
106
175
|
}
|
|
107
|
-
|
|
176
|
+
const member = unmarkedMember(file, document, definition);
|
|
177
|
+
if (member !== null)
|
|
178
|
+
return { refusal: member };
|
|
179
|
+
return {
|
|
180
|
+
sections: Object.keys(definition.sections).flatMap((name) => listedReferences(reads.filter((read) => read.section === name))),
|
|
181
|
+
};
|
|
108
182
|
}
|
|
109
183
|
function linked(file, content) {
|
|
110
184
|
return hrefOccurrences(bodyAfterFrontmatter(content)).every((occurrence) => classifyHref(file, occurrence.href).kind !== 'invalid');
|
|
@@ -113,11 +187,19 @@ function reached(file, href, to) {
|
|
|
113
187
|
const resolved = classifyHref(file, href);
|
|
114
188
|
return { target: resolved.kind === 'path' ? resolved.path : null, to };
|
|
115
189
|
}
|
|
190
|
+
function referred(file, href, to) {
|
|
191
|
+
const reference = reached(file, href, to);
|
|
192
|
+
return reference.target !== null &&
|
|
193
|
+
isDocumentPath(file) &&
|
|
194
|
+
!isDocumentPath(reference.target) &&
|
|
195
|
+
!to.includes(ATTACHMENT)
|
|
196
|
+
? { target: null, to }
|
|
197
|
+
: reference;
|
|
198
|
+
}
|
|
116
199
|
function crossing(file, href, crossRoom) {
|
|
117
200
|
return crossRoom === true && classifyHref(file, href).kind === 'room';
|
|
118
201
|
}
|
|
119
|
-
function definitionOf(
|
|
120
|
-
const kind = instanceType(document);
|
|
202
|
+
function definitionOf(kind, model) {
|
|
121
203
|
return kind === null || !Object.hasOwn(model.types, kind) ? undefined : model.types[kind];
|
|
122
204
|
}
|
|
123
205
|
export function checkDocument(file, content, model, context = {}) {
|
|
@@ -127,9 +209,17 @@ export function checkDocument(file, content, model, context = {}) {
|
|
|
127
209
|
return { ok: false };
|
|
128
210
|
const document = parsed.document;
|
|
129
211
|
const type = document.type ?? BUILT_IN_TYPE;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
212
|
+
const typedPath = typedPathOf(file, context.typedPaths);
|
|
213
|
+
if (describedRoom(file, document) !== null ||
|
|
214
|
+
typedPathRefusal(file, content, document, typedPath) !== null ||
|
|
215
|
+
reservedLink(file, document))
|
|
216
|
+
return { ok: false };
|
|
217
|
+
const kind = kindOf(document, typedPath);
|
|
218
|
+
if (kind === BUILT_IN_TYPE)
|
|
219
|
+
return unmarkedMember(file, document, undefined) === null
|
|
220
|
+
? { ok: true, type, typed: false, references: [] }
|
|
221
|
+
: { ok: false };
|
|
222
|
+
const definition = definitionOf(kind, model);
|
|
133
223
|
const read = structure(file, content, document, definition);
|
|
134
224
|
if ('refusal' in read || definition === undefined || !linked(file, content))
|
|
135
225
|
return { ok: false };
|
|
@@ -138,32 +228,11 @@ export function checkDocument(file, content, model, context = {}) {
|
|
|
138
228
|
type,
|
|
139
229
|
typed: true,
|
|
140
230
|
references: [
|
|
141
|
-
...references(document, definition).flatMap(({ value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom) ? [] : [
|
|
142
|
-
...read.sections.flatMap(({ to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom) ? [] : [
|
|
231
|
+
...references(document, definition).flatMap(({ value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom) ? [] : [referred(file, value, to)]),
|
|
232
|
+
...read.sections.flatMap(({ to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom) ? [] : [referred(file, href, to)])),
|
|
143
233
|
],
|
|
144
234
|
};
|
|
145
235
|
}
|
|
146
|
-
export function sectionReferences(file, content, definition) {
|
|
147
|
-
const referring = (name) => {
|
|
148
|
-
const spec = Object.hasOwn(definition.sections, name) ? definition.sections[name] : undefined;
|
|
149
|
-
return spec?.kind === 'list' && spec.items.reference !== undefined ? spec.items : undefined;
|
|
150
|
-
};
|
|
151
|
-
if (!Object.keys(definition.sections).some((name) => referring(name) !== undefined))
|
|
152
|
-
return [];
|
|
153
|
-
const uses = usesIn(content);
|
|
154
|
-
const found = [];
|
|
155
|
-
for (const span of headingSpans(content, bodyStartOf(content))) {
|
|
156
|
-
const items = referring(span.name);
|
|
157
|
-
if (items === undefined)
|
|
158
|
-
continue;
|
|
159
|
-
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
160
|
-
const hrefs = listed === null ? null : itemHrefs(content, listed, uses);
|
|
161
|
-
for (const href of hrefs ?? [])
|
|
162
|
-
if (!crossing(file, href, items.crossRoom))
|
|
163
|
-
found.push(reached(file, href, items.reference));
|
|
164
|
-
}
|
|
165
|
-
return found;
|
|
166
|
-
}
|
|
167
236
|
export function bodyRoomLinks(body) {
|
|
168
237
|
const found = [];
|
|
169
238
|
for (const href of new Set(hrefOccurrences(body).map((occurrence) => occurrence.href))) {
|
|
@@ -173,14 +242,12 @@ export function bodyRoomLinks(body) {
|
|
|
173
242
|
}
|
|
174
243
|
return found;
|
|
175
244
|
}
|
|
176
|
-
export function roomReferences(
|
|
245
|
+
export function roomReferences(document, definition) {
|
|
246
|
+
const { content } = document;
|
|
177
247
|
const found = bodyRoomLinks(bodyAfterFrontmatter(content));
|
|
178
248
|
if (definition === undefined)
|
|
179
249
|
return found;
|
|
180
|
-
const
|
|
181
|
-
if (!parsed.ok)
|
|
182
|
-
return found;
|
|
183
|
-
for (const { pointer, value, to, crossRoom } of references(parsed.document, definition)) {
|
|
250
|
+
for (const { pointer, value, to, crossRoom } of references(document, definition)) {
|
|
184
251
|
const room = roomTarget(value);
|
|
185
252
|
if (room !== null)
|
|
186
253
|
found.push({
|
|
@@ -192,24 +259,17 @@ export function roomReferences(file, content, definition) {
|
|
|
192
259
|
...(crossRoom ? { crossRoom } : {}),
|
|
193
260
|
});
|
|
194
261
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
const spec = Object.hasOwn(definition.sections, span.name)
|
|
198
|
-
? definition.sections[span.name]
|
|
199
|
-
: undefined;
|
|
200
|
-
if (spec?.kind !== 'list' || spec.items.reference === undefined)
|
|
201
|
-
continue;
|
|
202
|
-
const listed = listItems(content, span.bodyStart, span.bodyEnd);
|
|
203
|
-
for (const href of (listed === null ? null : itemHrefs(content, listed, uses)) ?? []) {
|
|
262
|
+
for (const { section, to, crossRoom, hrefs } of listedReferences(listReads(content, definition))) {
|
|
263
|
+
for (const href of hrefs) {
|
|
204
264
|
const room = roomTarget(href);
|
|
205
265
|
if (room !== null)
|
|
206
266
|
found.push({
|
|
207
267
|
kind: 'item',
|
|
208
|
-
section
|
|
268
|
+
section,
|
|
209
269
|
href,
|
|
210
|
-
to
|
|
270
|
+
to,
|
|
211
271
|
...room,
|
|
212
|
-
...(
|
|
272
|
+
...(crossRoom ? { crossRoom: true } : {}),
|
|
213
273
|
});
|
|
214
274
|
}
|
|
215
275
|
}
|
|
@@ -218,20 +278,50 @@ export function roomReferences(file, content, definition) {
|
|
|
218
278
|
function least(refused, file, verdict) {
|
|
219
279
|
return refused === undefined || file < refused.file ? { file, verdict } : refused;
|
|
220
280
|
}
|
|
221
|
-
export function assess(file,
|
|
281
|
+
export function assess(file, parsed, binary, model = { types: {} }, context = {}) {
|
|
222
282
|
const unread = { file, type: undefined, targets: [], structured: null, fields: [], sections: [] };
|
|
223
283
|
if (binary)
|
|
224
284
|
return { ...unread, read: refuse(file, 'binary-target-document'), linked: true };
|
|
225
|
-
const parsed = parse(content, file);
|
|
226
285
|
if (!parsed.ok)
|
|
227
286
|
return { ...unread, read: { verdict: 'refuse', ...parsed.refusal }, linked: true };
|
|
228
287
|
const document = parsed.document;
|
|
288
|
+
const content = document.content;
|
|
229
289
|
const type = document.type ?? BUILT_IN_TYPE;
|
|
230
290
|
const typed = { file, type, read: null, structured: null };
|
|
231
|
-
|
|
232
|
-
|
|
291
|
+
const typedPath = typedPathOf(file, context.typedPaths);
|
|
292
|
+
const described = describedRoom(file, document) ?? typedPathRefusal(file, content, document, typedPath);
|
|
293
|
+
if (described !== null)
|
|
294
|
+
return { ...typed, targets: [], structured: described, fields: [], linked: true, sections: [] };
|
|
295
|
+
const kind = kindOf(document, typedPath);
|
|
296
|
+
if (kind === BUILT_IN_TYPE) {
|
|
297
|
+
const structured = unmarkedMember(file, document, undefined);
|
|
298
|
+
return {
|
|
299
|
+
...typed,
|
|
300
|
+
targets: [],
|
|
301
|
+
structured,
|
|
302
|
+
fields: [],
|
|
303
|
+
linked: !reservedLink(file, document),
|
|
304
|
+
sections: [],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const definition = definitionOf(kind, model);
|
|
308
|
+
try {
|
|
309
|
+
return structured(file, content, typed, document, definition, context);
|
|
233
310
|
}
|
|
234
|
-
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (!(error instanceof PatternTooCostly))
|
|
313
|
+
throw error;
|
|
314
|
+
return {
|
|
315
|
+
...typed,
|
|
316
|
+
targets: [],
|
|
317
|
+
structured: refuse(file, 'pattern', { location: '' }),
|
|
318
|
+
fields: [],
|
|
319
|
+
linked: true,
|
|
320
|
+
sections: [],
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function structured(file, content, typed, document, definition, context) {
|
|
235
325
|
const read = structure(file, content, document, definition);
|
|
236
326
|
if ('refusal' in read || definition === undefined) {
|
|
237
327
|
return {
|
|
@@ -246,16 +336,63 @@ export function assess(file, content, binary, model = { types: {} }, context = {
|
|
|
246
336
|
const anyRoom = context.anyRoom === true;
|
|
247
337
|
const fields = references(document, definition).flatMap(({ pointer, value, to, crossRoom }) => crossing(file, value, anyRoom || crossRoom)
|
|
248
338
|
? []
|
|
249
|
-
: [{ reference:
|
|
339
|
+
: [{ reference: referred(file, value, to), location: pointer }]);
|
|
250
340
|
const sections = read.sections.flatMap(({ section, to, crossRoom, hrefs }) => hrefs.flatMap((href) => crossing(file, href, anyRoom || crossRoom)
|
|
251
341
|
? []
|
|
252
|
-
: [{ reference:
|
|
342
|
+
: [{ reference: referred(file, href, to), location: section }]));
|
|
253
343
|
const targets = new Set();
|
|
254
344
|
for (const { reference } of [...fields, ...sections]) {
|
|
255
345
|
if (reference.target !== null)
|
|
256
346
|
targets.add(reference.target);
|
|
257
347
|
}
|
|
258
|
-
return {
|
|
348
|
+
return {
|
|
349
|
+
...typed,
|
|
350
|
+
targets: [...targets],
|
|
351
|
+
fields,
|
|
352
|
+
linked: linked(file, content) && !reservedLink(file, document),
|
|
353
|
+
sections,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
export function assessReferences(file, parsed, changed, model = { types: {} }, context = {}) {
|
|
357
|
+
const unread = {
|
|
358
|
+
file,
|
|
359
|
+
type: undefined,
|
|
360
|
+
targets: [],
|
|
361
|
+
read: null,
|
|
362
|
+
structured: null,
|
|
363
|
+
fields: [],
|
|
364
|
+
linked: true,
|
|
365
|
+
sections: [],
|
|
366
|
+
};
|
|
367
|
+
if (!parsed.ok)
|
|
368
|
+
return unread;
|
|
369
|
+
const { document } = parsed;
|
|
370
|
+
const definition = definitionOf(kindOf(document, typedPathOf(file, context.typedPaths)), model);
|
|
371
|
+
const placed = (href, to, location) => {
|
|
372
|
+
const resolved = classifyHref(file, href);
|
|
373
|
+
return resolved.kind === 'path' && changed.has(resolved.path)
|
|
374
|
+
? [{ reference: referred(file, href, to), location }]
|
|
375
|
+
: [];
|
|
376
|
+
};
|
|
377
|
+
const fields = definition === undefined
|
|
378
|
+
? []
|
|
379
|
+
: references(document, definition).flatMap(({ pointer, value, to }) => placed(value, to, pointer));
|
|
380
|
+
const sections = definition === undefined
|
|
381
|
+
? []
|
|
382
|
+
: listedReferences(listReads(document.content, definition)).flatMap(({ section, to, hrefs }) => hrefs.flatMap((href) => placed(href, to, section)));
|
|
383
|
+
const targets = new Set();
|
|
384
|
+
for (const { reference } of [...fields, ...sections]) {
|
|
385
|
+
if (reference.target !== null)
|
|
386
|
+
targets.add(reference.target);
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
...unread,
|
|
390
|
+
type: document.type ?? BUILT_IN_TYPE,
|
|
391
|
+
targets: [...targets],
|
|
392
|
+
fields,
|
|
393
|
+
linked: !reservedLink(file, document, changed),
|
|
394
|
+
sections,
|
|
395
|
+
};
|
|
259
396
|
}
|
|
260
397
|
export function verdicts() {
|
|
261
398
|
let read;
|
|
@@ -318,19 +455,25 @@ export function* validating(library, context = { binaryTargets: [] }, model = {
|
|
|
318
455
|
const binary = (path) => binaryTargets.has(path);
|
|
319
456
|
const types = new Map();
|
|
320
457
|
const assessments = [];
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
458
|
+
const closeBudget = openPatternBudget();
|
|
459
|
+
try {
|
|
460
|
+
for (const [file, content] of library) {
|
|
461
|
+
const assessment = assess(file, parse(content, file), binary(file), model, context);
|
|
462
|
+
if (assessment.type !== undefined)
|
|
463
|
+
types.set(file, assessment.type);
|
|
464
|
+
assessments.push(assessment);
|
|
465
|
+
yield { path: file, resolved: 0 };
|
|
466
|
+
}
|
|
467
|
+
const judged = verdicts();
|
|
468
|
+
for (const assessment of assessments) {
|
|
469
|
+
const resolved = judged.add(assessment, (path) => types.get(path), binary);
|
|
470
|
+
yield { path: assessment.file, resolved };
|
|
471
|
+
}
|
|
472
|
+
return judged.verdict();
|
|
327
473
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const resolved = judged.add(assessment, (path) => types.get(path), binary);
|
|
331
|
-
yield { path: assessment.file, resolved };
|
|
474
|
+
finally {
|
|
475
|
+
closeBudget();
|
|
332
476
|
}
|
|
333
|
-
return judged.verdict();
|
|
334
477
|
}
|
|
335
478
|
export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
|
|
336
479
|
const steps = validating(new Map(Object.entries(library)), context, model);
|