@agentshouse/mdmodel 0.1.0-c5a71fe539a49 → 0.1.0-c60b1ddb74fcc

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.
Files changed (58) hide show
  1. package/API.md +220 -164
  2. package/dist/blocks.d.ts.map +1 -1
  3. package/dist/blocks.js +31 -17
  4. package/dist/condition.d.ts +19 -7
  5. package/dist/condition.d.ts.map +1 -1
  6. package/dist/condition.js +223 -117
  7. package/dist/definition.d.ts +23 -0
  8. package/dist/definition.d.ts.map +1 -1
  9. package/dist/definition.js +266 -25
  10. package/dist/document.d.ts +7 -8
  11. package/dist/document.d.ts.map +1 -1
  12. package/dist/document.js +105 -49
  13. package/dist/fields.d.ts +2 -0
  14. package/dist/fields.d.ts.map +1 -1
  15. package/dist/fields.js +7 -0
  16. package/dist/index.d.ts +11 -7
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +7 -5
  19. package/dist/links.d.ts +1 -0
  20. package/dist/links.d.ts.map +1 -1
  21. package/dist/links.js +1 -1
  22. package/dist/paths.d.ts +1 -0
  23. package/dist/paths.d.ts.map +1 -1
  24. package/dist/paths.js +92 -12
  25. package/dist/references.d.ts +2 -2
  26. package/dist/references.d.ts.map +1 -1
  27. package/dist/schema.js +2 -2
  28. package/dist/types.d.ts +32 -1
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/validate.d.ts +6 -1
  31. package/dist/validate.d.ts.map +1 -1
  32. package/dist/validate.js +163 -109
  33. package/dist/yaml.d.ts +7 -3
  34. package/dist/yaml.d.ts.map +1 -1
  35. package/dist/yaml.js +72 -43
  36. package/fixtures/README.md +1 -1
  37. package/fixtures/cases/absent-link-dangles/context.json +1 -0
  38. package/fixtures/cases/absent-link-dangles/expected.json +1 -0
  39. package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
  40. package/fixtures/cases/absent-link-dangles/schema.yaml +6 -0
  41. package/fixtures/cases/absolute-link/context.json +1 -0
  42. package/fixtures/cases/{missing-binary-image → absolute-link}/expected.json +1 -1
  43. package/fixtures/cases/absolute-link/library/item.md +8 -0
  44. package/fixtures/cases/absolute-link/schema.yaml +6 -0
  45. package/fixtures/cases/binary-image-dangles/expected.json +1 -0
  46. package/fixtures/cases/binary-link-dangles/expected.json +1 -0
  47. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
  48. package/fixtures/cases/shortcut-reference-link/library/item.md +1 -1
  49. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
  50. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  51. package/package.json +4 -2
  52. package/fixtures/cases/missing-binary-link/expected.json +0 -5
  53. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
  54. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
  55. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/schema.yaml +0 -0
  56. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
  57. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
  58. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/schema.yaml +0 -0
package/dist/validate.js CHANGED
@@ -18,25 +18,42 @@ function instanceType(document) {
18
18
  return null;
19
19
  return raw;
20
20
  }
21
- function reaches(file, href, to, documents, binaryTargets) {
22
- const resolved = classifyHref(file, href);
23
- if (resolved.kind !== 'path')
21
+ function reaches(reference, typeOf, binary) {
22
+ if (reference.target === null)
24
23
  return false;
25
- if (to.includes(ATTACHMENT))
24
+ if (reference.to.includes(ATTACHMENT))
26
25
  return true;
27
- if (binaryTargets.has(resolved.path))
26
+ if (binary(reference.target))
27
+ return false;
28
+ const held = typeOf(reference.target);
29
+ return held === undefined || reference.to.includes(held);
30
+ }
31
+ function missing(reference, typeOf, binary) {
32
+ if (reference.to.includes(ATTACHMENT) || reference.target === null)
28
33
  return false;
29
- const held = documents.get(resolved.path);
30
- return held === undefined || (held.ok && to.includes(held.document.type ?? BUILT_IN_TYPE));
34
+ return typeOf(reference.target) === undefined && !binary(reference.target);
35
+ }
36
+ export function resolves(reference, typeOf, binary) {
37
+ return reaches(reference, typeOf, binary) && !missing(reference, typeOf, binary);
38
+ }
39
+ function usesIn(content) {
40
+ let held;
41
+ return () => {
42
+ if (held !== undefined)
43
+ return held;
44
+ const bodyStart = bodyStartOf(content);
45
+ held = linkInventory(content.slice(bodyStart)).uses.map((use) => ({
46
+ ...use,
47
+ start: bodyStart + use.start,
48
+ end: bodyStart + use.end,
49
+ }));
50
+ return held;
51
+ };
31
52
  }
32
- function itemHrefs(content, items) {
33
- const bodyStart = bodyStartOf(content);
34
- const { uses } = linkInventory(content.slice(bodyStart));
53
+ function itemHrefs(content, items, uses) {
35
54
  const hrefs = [];
36
55
  for (const item of items) {
37
- const link = uses.find((use) => bodyStart + use.start === item.start &&
38
- bodyStart + use.end === item.end &&
39
- content[item.start] === '[');
56
+ const link = uses().find((use) => use.start === item.start && use.end === item.end && content[item.start] === '[');
40
57
  if (link === undefined)
41
58
  return null;
42
59
  hrefs.push(link.destination.href);
@@ -53,118 +70,155 @@ export function verify(schema) {
53
70
  ...(read.location === undefined ? {} : { location: read.location }),
54
71
  };
55
72
  }
56
- export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
73
+ function structure(file, content, document, definition) {
74
+ if (definition === undefined)
75
+ return { refusal: refuse(file, 'unknown-type', { location: '/type' }) };
76
+ const fieldFailure = frontmatterRefusal(definition, document.fields);
77
+ if (fieldFailure !== undefined) {
78
+ return { refusal: refuse(file, fieldFailure.rule, { location: fieldFailure.location }) };
79
+ }
80
+ const spans = headingSpans(content, bodyStartOf(content));
81
+ const uses = usesIn(content);
82
+ const sections = [];
83
+ for (const [name, spec] of Object.entries(definition.sections)) {
84
+ const occurrences = spans.filter((one) => one.name === name);
85
+ if (occurrences.length === 0 && spec.required)
86
+ return { refusal: refuse(file, 'required-section', { location: name }) };
87
+ if (spec.kind !== 'list')
88
+ continue;
89
+ for (const span of occurrences) {
90
+ const items = listItems(content, span.bodyStart, span.bodyEnd);
91
+ if (items === null ||
92
+ items.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))))
93
+ return { refusal: refuse(file, 'structured-section', { location: name }) };
94
+ if (spec.items.reference === undefined)
95
+ continue;
96
+ const hrefs = itemHrefs(content, items, uses);
97
+ if (hrefs === null)
98
+ return { refusal: refuse(file, 'structured-section', { location: name }) };
99
+ sections.push({ section: name, to: spec.items.reference, hrefs });
100
+ }
101
+ }
102
+ return { sections };
103
+ }
104
+ function linked(file, content) {
105
+ return hrefOccurrences(bodyAfterFrontmatter(content)).every((occurrence) => classifyHref(file, occurrence.href).kind !== 'invalid');
106
+ }
107
+ function reached(file, href, to) {
108
+ const resolved = classifyHref(file, href);
109
+ return { target: resolved.kind === 'path' ? resolved.path : null, to };
110
+ }
111
+ function definitionOf(document, model) {
112
+ const kind = instanceType(document);
113
+ return kind === null || !Object.hasOwn(model.types, kind) ? undefined : model.types[kind];
114
+ }
115
+ export function checkDocument(file, content, model) {
116
+ const parsed = parse(content, file);
117
+ if (!parsed.ok)
118
+ return { ok: false };
119
+ const document = parsed.document;
120
+ const type = document.type ?? BUILT_IN_TYPE;
121
+ if (instanceType(document) === BUILT_IN_TYPE)
122
+ return { ok: true, type, typed: false, references: [] };
123
+ const definition = definitionOf(document, model);
124
+ const read = structure(file, content, document, definition);
125
+ if ('refusal' in read || definition === undefined || !linked(file, content))
126
+ return { ok: false };
127
+ return {
128
+ ok: true,
129
+ type,
130
+ typed: true,
131
+ references: [
132
+ ...references(document, definition).map(({ value, to }) => reached(file, value, to)),
133
+ ...read.sections.flatMap(({ to, hrefs }) => hrefs.map((href) => reached(file, href, to))),
134
+ ],
135
+ };
136
+ }
137
+ export function sectionReferences(file, content, definition) {
138
+ const referring = (name) => {
139
+ const spec = Object.hasOwn(definition.sections, name) ? definition.sections[name] : undefined;
140
+ return spec?.kind === 'list' ? spec.items.reference : undefined;
141
+ };
142
+ if (!Object.keys(definition.sections).some((name) => referring(name) !== undefined))
143
+ return [];
144
+ const uses = usesIn(content);
145
+ const found = [];
146
+ for (const span of headingSpans(content, bodyStartOf(content))) {
147
+ const to = referring(span.name);
148
+ if (to === undefined)
149
+ continue;
150
+ const items = listItems(content, span.bodyStart, span.bodyEnd);
151
+ const hrefs = items === null ? null : itemHrefs(content, items, uses);
152
+ for (const href of hrefs ?? [])
153
+ found.push(reached(file, href, to));
154
+ }
155
+ return found;
156
+ }
157
+ export function* validating(library, context = { binaryTargets: [] }, model = { types: {} }) {
57
158
  const binaryTargets = new Set(context.binaryTargets);
159
+ const binary = (path) => binaryTargets.has(path);
58
160
  const files = Object.keys(library).sort();
161
+ const types = new Map();
162
+ const typeOf = (path) => types.get(path);
59
163
  const documents = new Map();
60
164
  for (const file of files) {
61
165
  if (binaryTargets.has(file))
62
166
  return refuse(file, 'binary-target-document');
63
167
  const parsed = parse(library[file], file);
64
- documents.set(file, parsed);
65
168
  if (!parsed.ok)
66
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);
173
+ yield file;
67
174
  }
68
- const definitions = new Map(Object.entries(model.types));
69
175
  const sectionReferences = new Map();
70
- for (const file of files) {
71
- const parsed = documents.get(file);
72
- if (parsed === undefined || !parsed.ok)
73
- continue;
74
- const kind = instanceType(parsed.document);
75
- if (kind === BUILT_IN_TYPE)
76
- continue;
77
- const definition = kind === null ? undefined : definitions.get(kind);
78
- if (definition === undefined)
79
- return refuse(file, 'unknown-type', { location: '/type' });
80
- const fieldFailure = frontmatterRefusal(definition, parsed.document.fields);
81
- if (fieldFailure !== undefined) {
82
- return refuse(file, fieldFailure.rule, { location: fieldFailure.location });
83
- }
84
- const content = library[file];
85
- const spans = headingSpans(content, bodyStartOf(content));
86
- const references = [];
87
- for (const [name, spec] of Object.entries(definition.sections)) {
88
- const occurrences = spans.filter((one) => one.name === name);
89
- if (occurrences.length === 0 && spec.required)
90
- return refuse(file, 'required-section', { location: name });
91
- if (spec.kind !== 'list')
92
- continue;
93
- for (const span of occurrences) {
94
- const items = listItems(content, span.bodyStart, span.bodyEnd);
95
- if (items === null ||
96
- items.some((item) => !fitsItem(definition, name, content.slice(item.start, item.end))))
97
- return refuse(file, 'structured-section', { location: name });
98
- if (spec.items.reference === undefined)
99
- continue;
100
- const hrefs = itemHrefs(content, items);
101
- if (hrefs === null)
102
- return refuse(file, 'structured-section', { location: name });
103
- references.push({ section: name, to: spec.items.reference, hrefs });
104
- }
105
- }
106
- sectionReferences.set(file, references);
176
+ 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;
107
182
  }
108
- for (const file of files) {
109
- const parsed = documents.get(file);
110
- if (parsed === undefined || !parsed.ok)
111
- continue;
112
- const kind = instanceType(parsed.document);
113
- if (kind === null || kind === BUILT_IN_TYPE)
114
- continue;
115
- const definition = definitions.get(kind);
116
- if (definition === undefined)
117
- continue;
118
- for (const { pointer, to, value } of references(parsed.document, definition)) {
119
- if (!reaches(file, value, to, documents, binaryTargets))
120
- return refuse(file, 'unresolved-reference', { location: pointer });
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 });
121
193
  }
122
- const body = bodyAfterFrontmatter(library[file]);
123
- for (const occurrence of hrefOccurrences(body)) {
124
- const resolved = classifyHref(file, occurrence.href);
125
- if (resolved.kind === 'skip')
126
- continue;
127
- if (resolved.kind === 'invalid' ||
128
- (!documents.has(resolved.path) && !binaryTargets.has(resolved.path))) {
129
- return refuse(file, 'unresolved-link');
130
- }
194
+ if (!linked(file, library[file]))
195
+ return refuse(file, 'unresolved-link');
196
+ const sections = sectionReferences
197
+ .get(file)
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 });
131
202
  }
132
- for (const { section, to, hrefs } of sectionReferences.get(file)) {
133
- for (const href of hrefs) {
134
- if (!reaches(file, href, to, documents, binaryTargets))
135
- return refuse(file, 'unresolved-reference', { location: section });
136
- }
137
- }
138
- }
139
- const missing = new Map();
140
- for (const file of files) {
141
- const parsed = documents.get(file);
142
- if (parsed === undefined || !parsed.ok)
143
- continue;
144
- const kind = instanceType(parsed.document);
145
- if (kind === null || kind === BUILT_IN_TYPE)
146
- continue;
147
- const definition = definitions.get(kind);
148
- if (definition === undefined)
149
- continue;
150
- for (const { value, to } of references(parsed.document, definition)) {
151
- if (to.includes(ATTACHMENT))
203
+ for (const { reference } of [...fields, ...sections]) {
204
+ if (!missing(reference, typeOf, binary))
152
205
  continue;
153
- const resolved = classifyHref(file, value);
154
- if (resolved.kind !== 'path')
155
- continue;
156
- if (documents.has(resolved.path) || binaryTargets.has(resolved.path))
157
- continue;
158
- const referrers = missing.get(resolved.path) ?? [];
159
- referrers.push(file);
160
- missing.set(resolved.path, referrers);
206
+ const path = reference.target;
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);
161
211
  }
212
+ yield file;
162
213
  }
163
- const missingPaths = [...missing.keys()].sort();
164
- if (missingPaths.length > 0) {
165
- const path = missingPaths[0];
166
- const referrers = [...new Set(missing.get(path) ?? [])].sort();
167
- return refuse(path, 'referenced-missing-file', { referrers });
168
- }
214
+ if (least !== undefined)
215
+ return refuse(least.path, 'referenced-missing-file', { referrers: least.referrers });
169
216
  return { verdict: 'accept' };
170
217
  }
218
+ export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
219
+ const steps = validating(library, context, model);
220
+ let step = steps.next();
221
+ while (step.done !== true)
222
+ step = steps.next();
223
+ return step.value;
224
+ }
package/dist/yaml.d.ts CHANGED
@@ -16,8 +16,7 @@ export type YamlSeq = {
16
16
  };
17
17
  export type YamlEntry = {
18
18
  readonly key: string;
19
- readonly keyStart: number;
20
- readonly keyEnd: number;
19
+ readonly after: number;
21
20
  readonly value: YamlNode;
22
21
  };
23
22
  export type YamlMap = {
@@ -32,7 +31,12 @@ export declare function parseYamlMapping(text: string, start: number, end: numbe
32
31
  export declare function jsValue(node: YamlNode): unknown;
33
32
  export declare function mapEntry(map: YamlMap, key: string): YamlEntry | undefined;
34
33
  export declare function isPlainSafe(text: string): boolean;
35
- export declare function serializeJs(value: unknown): string;
34
+ export type FrontmatterValue = string | number | boolean | null | readonly FrontmatterValue[] | {
35
+ readonly [name: string]: FrontmatterValue;
36
+ };
37
+ export declare function plain(value: unknown): value is Record<string, unknown>;
38
+ export declare function frontmatterValue(value: unknown): value is FrontmatterValue;
39
+ export declare function serializeJs(value: FrontmatterValue): string;
36
40
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
37
41
  export declare function serializeKey(name: string): string;
38
42
  export declare function bodyStartAfterYaml(content: string, yamlEnd: number): number;
@@ -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,MA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 export function interpretPlain(text) {
84
84
  return Number(text);
85
85
  return text;
86
86
  }
87
+ const ESCAPES = {
88
+ b: '\b',
89
+ f: '\f',
90
+ n: '\n',
91
+ r: '\r',
92
+ t: '\t',
93
+ '"': '"',
94
+ '/': '/',
95
+ '\\': '\\',
96
+ };
97
+ function parseEscape(c) {
98
+ c.i += 1;
99
+ const escaped = peek(c);
100
+ const held = ESCAPES[escaped];
101
+ if (held !== undefined) {
102
+ c.i += 1;
103
+ return held;
104
+ }
105
+ const hex = c.text.slice(c.i + 1, c.i + 5);
106
+ if (escaped !== 'u' || c.i + 5 > c.end || !/^[0-9A-Fa-f]{4}$/.test(hex))
107
+ throw new YamlError(c.i);
108
+ c.i += 5;
109
+ return String.fromCharCode(Number.parseInt(hex, 16));
110
+ }
87
111
  function parseQuoted(c) {
88
112
  const quote = peek(c);
89
113
  const start = c.i;
@@ -91,31 +115,19 @@ function parseQuoted(c) {
91
115
  let out = '';
92
116
  while (c.i < c.end) {
93
117
  const ch = peek(c);
118
+ if (quote === "'" && ch === "'" && c.i + 1 < c.end && c.text[c.i + 1] === "'") {
119
+ out += "'";
120
+ c.i += 2;
121
+ continue;
122
+ }
94
123
  if (ch === quote) {
95
124
  c.i += 1;
96
125
  return scalar(out, start, c.i);
97
126
  }
98
127
  if (ch === '\n' || ch === '\r')
99
128
  throw new YamlError(c.i);
100
- if (quote === "'" && ch === "'" && c.text[c.i + 1] === "'") {
101
- out += "'";
102
- c.i += 2;
103
- continue;
104
- }
105
129
  if (quote === '"' && ch === '\\') {
106
- c.i += 1;
107
- const escaped = peek(c);
108
- if (escaped === 'n')
109
- out += '\n';
110
- else if (escaped === 't')
111
- out += '\t';
112
- else if (escaped === '"')
113
- out += '"';
114
- else if (escaped === '\\')
115
- out += '\\';
116
- else
117
- throw new YamlError(c.i);
118
- c.i += 1;
130
+ out += parseEscape(c);
119
131
  continue;
120
132
  }
121
133
  out += ch;
@@ -208,11 +220,12 @@ function parseFlowMap(c) {
208
220
  if (peek(c) !== ':')
209
221
  throw new YamlError(c.i);
210
222
  c.i += 1;
223
+ const after = c.i;
211
224
  const value = parseFlowValue(c);
212
225
  if (seen.has(key.name))
213
226
  throw new YamlError(key.start);
214
227
  seen.add(key.name);
215
- entries.push({ key: key.name, keyStart: key.start, keyEnd: key.end, value });
228
+ entries.push({ key: key.name, after, value });
216
229
  skipFlowSpace(c);
217
230
  if (peek(c) === ',') {
218
231
  c.i += 1;
@@ -254,6 +267,7 @@ function parseFlowSeq(c) {
254
267
  throw new YamlError(c.i);
255
268
  }
256
269
  function parseValue(c, parentKeyIndent) {
270
+ const at = c.i;
257
271
  skipSpaces(c);
258
272
  if (peek(c) === '#')
259
273
  skipToEol(c);
@@ -262,12 +276,12 @@ function parseValue(c, parentKeyIndent) {
262
276
  skipEol(c);
263
277
  skipBlankAndComments(c);
264
278
  if (c.i >= c.end)
265
- return scalar(null, c.i, c.i);
279
+ return scalar(null, at, at);
266
280
  const nextIndent = indentAt(c);
267
281
  if (nextIndent === parentKeyIndent && seqAhead(c))
268
282
  return parseBlockSeq(c, nextIndent);
269
283
  if (nextIndent <= parentKeyIndent)
270
- return scalar(null, c.i, c.i);
284
+ return scalar(null, at, at);
271
285
  if (peek(c) === '-')
272
286
  return parseBlockSeq(c, nextIndent);
273
287
  if (peek(c) === '[')
@@ -315,9 +329,6 @@ function lineStartOf(c) {
315
329
  j -= 1;
316
330
  return j;
317
331
  }
318
- function valueEnd(value, marked) {
319
- return value.kind === 'scalar' && value.start === value.end ? marked : value.end;
320
- }
321
332
  function parseSeqItem(c, indent) {
322
333
  skipSpaces(c);
323
334
  if (peek(c) !== '#' && peek(c) !== '\n' && peek(c) !== '\r' && c.i < c.end && mappingAhead(c))
@@ -337,10 +348,9 @@ function parseBlockSeq(c, indent) {
337
348
  if (peek(c) !== '-')
338
349
  break;
339
350
  c.i += 1;
340
- const marked = c.i;
341
351
  const item = parseSeqItem(c, indent);
342
352
  items.push(item);
343
- end = valueEnd(item, marked);
353
+ end = item.end;
344
354
  }
345
355
  return { kind: 'seq', items, start, end };
346
356
  }
@@ -366,13 +376,13 @@ function parseBlockMap(c, indent, inline = false) {
366
376
  if (peek(c) !== ':')
367
377
  throw new YamlError(c.i);
368
378
  c.i += 1;
369
- const marked = c.i;
379
+ const after = c.i;
370
380
  const value = parseValue(c, indent);
371
381
  if (seen.has(key.name))
372
382
  throw new YamlError(key.start);
373
383
  seen.add(key.name);
374
- entries.push({ key: key.name, keyStart: key.start, keyEnd: key.end, value });
375
- end = valueEnd(value, marked);
384
+ entries.push({ key: key.name, after, value });
385
+ end = value.end;
376
386
  }
377
387
  return { kind: 'map', entries, start, end };
378
388
  }
@@ -418,24 +428,42 @@ export function isPlainSafe(text) {
418
428
  return false;
419
429
  return true;
420
430
  }
431
+ export function plain(value) {
432
+ if (!isRecord(value))
433
+ return false;
434
+ const prototype = Object.getPrototypeOf(value);
435
+ return prototype === Object.prototype || prototype === null;
436
+ }
437
+ function listed(value) {
438
+ const keys = Object.keys(value);
439
+ return keys.length === value.length && keys.every((key, index) => key === String(index));
440
+ }
441
+ function heldWithin(value, within) {
442
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
443
+ return true;
444
+ if (typeof value === 'number')
445
+ return Number.isFinite(value);
446
+ if (typeof value !== 'object' || within.includes(value))
447
+ return false;
448
+ const path = [...within, value];
449
+ const held = (item) => heldWithin(item, path);
450
+ if (Array.isArray(value))
451
+ return listed(value) && value.every(held);
452
+ return plain(value) && Object.values(value).every(held);
453
+ }
454
+ export function frontmatterValue(value) {
455
+ return heldWithin(value, []);
456
+ }
421
457
  export function serializeJs(value) {
422
- if (value === null)
423
- return 'null';
424
- if (value === true)
425
- return 'true';
426
- if (value === false)
427
- return 'false';
428
- if (typeof value === 'number' && Number.isFinite(value))
429
- return JSON.stringify(value);
430
458
  if (typeof value === 'string')
431
459
  return isPlainSafe(value) ? value : JSON.stringify(value);
460
+ if (value === null || typeof value !== 'object')
461
+ return JSON.stringify(value);
432
462
  if (Array.isArray(value))
433
463
  return `[${value.map(serializeJs).join(', ')}]`;
434
- if (isRecord(value))
435
- return `{${Object.entries(value)
436
- .map(([key, held]) => `${serializeKey(key)}: ${serializeJs(held)}`)
437
- .join(', ')}}`;
438
- throw new YamlError(0);
464
+ return `{${Object.entries(value)
465
+ .map(([key, held]) => `${serializeKey(key)}: ${serializeJs(held)}`)
466
+ .join(', ')}}`;
439
467
  }
440
468
  export function isRecord(value) {
441
469
  return value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -485,7 +513,8 @@ export function equalValue(left, right) {
485
513
  if (left === right)
486
514
  return true;
487
515
  if (Array.isArray(left) && Array.isArray(right)) {
488
- return (left.length === right.length && left.every((item, index) => equalValue(item, right[index])));
516
+ return (left.length === right.length &&
517
+ Array.from(left).every((item, index) => equalValue(item, right[index])));
489
518
  }
490
519
  if (isRecord(left) && isRecord(right)) {
491
520
  const keys = Object.keys(left);
@@ -136,6 +136,6 @@ Library is accepted too, so `unresolved-link` never names it and
136
136
  ## YAML subset
137
137
 
138
138
  Frontmatter and a schema text are each a mapping in a closed YAML subset: block and flow mappings,
139
- block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars, `true`, `false`, `null`,
139
+ block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars (a single-quoted scalar doubles its apostrophe, a double-quoted one takes JSON's escapes), `true`, `false`, `null`,
140
140
  and decimal numbers. It does not take YAML 1.1 boolean or timestamp aliases,
141
141
  octal numbers, anchors, tags, or block scalars. A mapping carries each key once.
@@ -0,0 +1 @@
1
+ { "binaryTargets": [] }
@@ -0,0 +1 @@
1
+ { "verdict": "accept" }
@@ -0,0 +1,8 @@
1
+ ---
2
+ type: task
3
+ title: Ship
4
+ ---
5
+
6
+ ## Description
7
+
8
+ See [plan](missing.md).
@@ -0,0 +1,6 @@
1
+ task:
2
+ properties:
3
+ title: { type: string }
4
+ required: [title]
5
+ sections:
6
+ Description: { kind: text, required: true }
@@ -0,0 +1 @@
1
+ { "binaryTargets": [] }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "verdict": "refuse",
3
- "file": "notes/draft.md",
3
+ "file": "item.md",
4
4
  "rule": "unresolved-link"
5
5
  }
@@ -0,0 +1,8 @@
1
+ ---
2
+ type: task
3
+ title: Ship
4
+ ---
5
+
6
+ ## Description
7
+
8
+ See [plan](/notes/plan.md).
@@ -0,0 +1,6 @@
1
+ task:
2
+ properties:
3
+ title: { type: string }
4
+ required: [title]
5
+ sections:
6
+ Description: { kind: text, required: true }
@@ -0,0 +1 @@
1
+ { "verdict": "accept" }
@@ -0,0 +1 @@
1
+ { "verdict": "accept" }
@@ -4,4 +4,4 @@ type: note
4
4
 
5
5
  See [the export][ex].
6
6
 
7
- > [ex]: ../data/export.csv
7
+ > [ex]: ../../export.csv
@@ -7,4 +7,4 @@ title: Ship
7
7
 
8
8
  See [Plan].
9
9
 
10
- [plan]: missing.md
10
+ [plan]: ../missing.md
@@ -4,4 +4,4 @@ type: note
4
4
 
5
5
  See [the other note][ex].
6
6
 
7
- [ex]: <../notes/other.md extra>
7
+ [ex]: <../notes/other.md ../../../../extra.md>
@@ -5,4 +5,4 @@ title: Ship
5
5
 
6
6
  ## Description
7
7
 
8
- See [nope](missing.md).
8
+ See [outside](../outside.md).