@agentshouse/mdmodel 0.1.0-cc9fa0498a7f7 → 0.1.0-ccf1367190878

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.
@@ -12,6 +12,18 @@ export const JSON_TYPES = [
12
12
  export const BUILT_IN_TYPE = 'any';
13
13
  export const ATTACHMENT = 'attachment';
14
14
  const SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean']);
15
+ const COMPOSITES = ['array', 'object'];
16
+ const ANNOTATIONS = new Set([
17
+ '$comment',
18
+ 'title',
19
+ 'description',
20
+ 'default',
21
+ 'examples',
22
+ 'deprecated',
23
+ 'readOnly',
24
+ 'writeOnly',
25
+ ]);
26
+ const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
15
27
  const DEFS_REFERENCE = '#/$defs/';
16
28
  const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
17
29
  export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
@@ -270,24 +282,43 @@ function united(left, right) {
270
282
  return undefined;
271
283
  return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
272
284
  }
285
+ function both(left, right) {
286
+ return left !== undefined && right !== undefined ? joined(left, right) : undefined;
287
+ }
273
288
  function joined(left, right) {
274
289
  const type = left.type === right.type ? left.type : undefined;
275
290
  const format = left.format === right.format ? left.format : undefined;
276
291
  const values = united(left.values, right.values);
277
292
  const reference = united(left.reference, right.reference);
278
- const items = left.items !== undefined && right.items !== undefined
279
- ? joined(left.items, right.items)
280
- : undefined;
293
+ const items = both(left.items, right.items);
294
+ const prefix = left.prefix === undefined && right.prefix === undefined
295
+ ? undefined
296
+ : Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
297
+ const properties = Object.create(null);
298
+ for (const [name, facts] of Object.entries(left.properties ?? {})) {
299
+ const shared = both(facts, right.properties?.[name]);
300
+ if (shared !== undefined)
301
+ properties[name] = shared;
302
+ }
303
+ const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
304
+ const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
305
+ return shared === undefined ? [] : [{ pattern, facts: shared }];
306
+ });
307
+ const additional = both(left.additional, right.additional);
281
308
  return {
282
309
  ...(type === undefined ? {} : { type }),
283
310
  ...(format === undefined ? {} : { format }),
284
311
  ...(values === undefined ? {} : { values }),
285
312
  ...(reference === undefined ? {} : { reference }),
286
313
  prose: left.prose && right.prose,
314
+ ...(prefix === undefined ? {} : { prefix }),
287
315
  ...(items === undefined ? {} : { items }),
316
+ ...(Object.keys(properties).length === 0 ? {} : { properties }),
317
+ ...(patterns.length === 0 ? {} : { patterns }),
318
+ ...(additional === undefined ? {} : { additional }),
288
319
  };
289
320
  }
290
- function propertiesOf(held, defs, ancestry) {
321
+ function propertiesOf(held, variants, defs, ancestry) {
291
322
  const declared = new Map();
292
323
  for (const node of held) {
293
324
  if (!isRecord(node.properties))
@@ -298,46 +329,87 @@ function propertiesOf(held, defs, ancestry) {
298
329
  const properties = Object.create(null);
299
330
  for (const [name, schemas] of declared)
300
331
  properties[name] = factsOf(schemas, defs, ancestry);
301
- const variants = Object.create(null);
302
- for (const branch of held.flatMap(variantsOf)) {
303
- for (const [name, facts] of Object.entries(factsOf([branch], defs, ancestry).properties ?? {})) {
332
+ const conditional = Object.create(null);
333
+ for (const branch of variants.values()) {
334
+ for (const [name, facts] of Object.entries(branch.properties ?? {})) {
304
335
  if (Object.hasOwn(properties, name))
305
336
  continue;
306
- variants[name] = Object.hasOwn(variants, name) ? joined(variants[name], facts) : facts;
337
+ conditional[name] = Object.hasOwn(conditional, name)
338
+ ? joined(conditional[name], facts)
339
+ : facts;
307
340
  }
308
341
  }
309
- for (const [name, facts] of Object.entries(variants))
342
+ for (const [name, facts] of Object.entries(conditional))
310
343
  properties[name] = { ...facts, conditional: true };
311
344
  return Object.keys(properties).length === 0 ? undefined : properties;
312
345
  }
346
+ function nullOnly(facts) {
347
+ return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
348
+ }
349
+ function alternativesOf(held, variants) {
350
+ return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
351
+ if (!Array.isArray(branches))
352
+ return [];
353
+ const kept = branches
354
+ .flatMap((branch) => {
355
+ const facts = isRecord(branch) ? variants.get(branch) : undefined;
356
+ return facts === undefined ? [] : [facts];
357
+ })
358
+ .filter((facts) => !nullOnly(facts));
359
+ return kept.length === 0 ? [] : [kept];
360
+ }));
361
+ }
362
+ function inheritedOf(held) {
363
+ return held.flatMap((node) => {
364
+ const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
365
+ return Object.keys(kept).length === 0 ? [] : [kept];
366
+ });
367
+ }
313
368
  function factsOf(nodes, defs, ancestry) {
314
369
  const { held, ancestry: reached } = conjoined(nodes, defs, ancestry);
315
- const listed = held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []);
370
+ const inherited = inheritedOf(held);
371
+ const variants = new Map(held
372
+ .flatMap(variantsOf)
373
+ .map((branch) => [branch, factsOf([branch, ...inherited], defs, reached)]));
374
+ const unions = alternativesOf(held, variants);
375
+ const alternatives = unions.map((kept) => kept.reduce(joined));
376
+ const listed = [
377
+ ...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
378
+ ...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
379
+ ];
316
380
  const values = listed.length === 0
317
381
  ? undefined
318
382
  : listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
319
383
  const type = firstOf(held, (node) => singleType(node.type)) ??
320
- (values === undefined ? undefined : sharedType(values));
384
+ (values === undefined ? undefined : sharedType(values)) ??
385
+ alternatives.find((facts) => facts.type !== undefined)?.type;
321
386
  const reference = firstOf(held, (node) => typeof node.reference === 'string'
322
387
  ? [node.reference]
323
388
  : Array.isArray(node.reference)
324
389
  ? node.reference
325
- : undefined);
326
- const format = firstOf(held, (node) => typeof node.format === 'string' ? node.format : undefined);
390
+ : undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
391
+ const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
392
+ alternatives.find((facts) => facts.format !== undefined)?.format;
327
393
  const prose = type === 'string' &&
328
394
  values === undefined &&
329
395
  format === undefined &&
330
396
  reference === undefined &&
331
- held.every((node) => node.pattern === undefined);
397
+ held.every((node) => node.pattern === undefined) &&
398
+ unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
332
399
  const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
333
- const items = type === 'array' && listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined;
334
- const prefix = type === 'array'
335
- ? firstOf(held, (node) => Array.isArray(node.prefixItems)
336
- ? node.prefixItems.map((schema) => factsOf([schema], defs, reached))
337
- : undefined)
338
- : undefined;
400
+ const items = type !== 'array'
401
+ ? undefined
402
+ : (alternatives.find((facts) => facts.items !== undefined)?.items ??
403
+ (listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
404
+ const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
405
+ const prefix = type !== 'array'
406
+ ? undefined
407
+ : (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
408
+ (tuples.length === 0
409
+ ? undefined
410
+ : Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
339
411
  const mapped = type === 'object' || type === undefined;
340
- const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
412
+ const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
341
413
  const patterns = mapped
342
414
  ? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
343
415
  : [];
@@ -478,21 +550,134 @@ function deepFreeze(value) {
478
550
  }
479
551
  return value;
480
552
  }
553
+ function ruleValue(value) {
554
+ return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
555
+ }
556
+ function roleNames(value) {
557
+ return strings(value) && value.every((name) => name !== '');
558
+ }
559
+ function compositesOf(value) {
560
+ return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
561
+ }
562
+ function typed(type) {
563
+ const types = typeof type === 'string' ? [type] : type;
564
+ return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
565
+ }
566
+ function admittedWhole(node) {
567
+ if (node === true)
568
+ return COMPOSITES;
569
+ if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
570
+ return [];
571
+ return typed(node.type) ?? COMPOSITES;
572
+ }
573
+ function composites(node, defs, seen) {
574
+ if (node === false)
575
+ return [];
576
+ if (!isRecord(node))
577
+ return COMPOSITES;
578
+ const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
579
+ const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
580
+ const conditioned = () => {
581
+ const met = composites(node.then ?? true, defs, seen);
582
+ return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
583
+ composites(node.else ?? true, defs, seen).includes(kind));
584
+ };
585
+ const bounds = [
586
+ typed(node.type),
587
+ Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
588
+ Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
589
+ target === undefined || seen.has(target)
590
+ ? undefined
591
+ : composites(target, defs, new Set([...seen, target])),
592
+ ...each(node.allOf),
593
+ ...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
594
+ Object.hasOwn(node, 'if') ? conditioned() : undefined,
595
+ Object.hasOwn(node, 'not')
596
+ ? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
597
+ : undefined,
598
+ ];
599
+ return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
600
+ }
601
+ function transitionOf(value) {
602
+ if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
603
+ return undefined;
604
+ const { from, to, roles, ...rest } = value;
605
+ if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
606
+ return undefined;
607
+ if (roles === undefined)
608
+ return { from, to };
609
+ return roleNames(roles) ? { from, to, roles } : undefined;
610
+ }
611
+ function fieldRules(written, field, at, defs) {
612
+ const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
613
+ if (changeRoles !== undefined && !roleNames(changeRoles))
614
+ return refuse('change_roles', `${at}/change_roles`);
615
+ if (initialRoles !== undefined && !roleNames(initialRoles))
616
+ return refuse('initial_roles', `${at}/initial_roles`);
617
+ if (transitions === undefined)
618
+ return {
619
+ ...(changeRoles === undefined ? {} : { changeRoles }),
620
+ ...(initialRoles === undefined ? {} : { initialRoles }),
621
+ };
622
+ if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
623
+ return refuse('transitions', `${at}/transitions`);
624
+ const listed = [];
625
+ for (const [index, held] of transitions.entries()) {
626
+ const transition = transitionOf(held);
627
+ if (transition === undefined)
628
+ return refuse('transitions', `${at}/transitions/${index}`);
629
+ listed.push(transition);
630
+ }
631
+ return {
632
+ ...(changeRoles === undefined ? {} : { changeRoles }),
633
+ ...(initialRoles === undefined ? {} : { initialRoles }),
634
+ transitions: listed,
635
+ };
636
+ }
637
+ function unruled(schema) {
638
+ const written = new Map();
639
+ if (!isRecord(schema.properties))
640
+ return { schema, written };
641
+ const properties = Object.create(null);
642
+ for (const [field, node] of Object.entries(schema.properties)) {
643
+ if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
644
+ properties[field] = node;
645
+ continue;
646
+ }
647
+ written.set(field, node);
648
+ properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
649
+ }
650
+ return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
651
+ }
481
652
  function readType(name, value, context) {
482
653
  const at = `/${escapePointer(name)}`;
483
654
  if (!isRecord(value))
484
655
  return refuse('schema', at);
485
- const { sections: declared, member_document: mark, ...schema } = value;
656
+ const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
486
657
  if (mark !== undefined && typeof mark !== 'boolean')
487
658
  return refuse('member_document', `${at}/member_document`);
659
+ if (createRoles !== undefined && !roleNames(createRoles))
660
+ return refuse('create_roles', `${at}/create_roles`);
661
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
662
+ return refuse('delete_roles', `${at}/delete_roles`);
488
663
  const read = declared === undefined
489
664
  ? { sections: Object.create(null) }
490
665
  : readSections(declared, `${at}/sections`, context);
491
666
  if ('failure' in read)
492
667
  return read.failure;
668
+ const { schema, written } = unruled(ruled);
493
669
  const failure = schemaFailure(schema, at, context);
494
670
  if (failure !== undefined)
495
671
  return failure;
672
+ const rules = Object.create(null);
673
+ for (const [field, keywords] of written) {
674
+ const properties = schema.properties;
675
+ const where = `${at}/properties/${escapePointer(field)}`;
676
+ const ruling = fieldRules(keywords, properties[field], where, context.defs);
677
+ if ('rule' in ruling)
678
+ return ruling;
679
+ rules[field] = ruling;
680
+ }
496
681
  const memberDocument = mark === true;
497
682
  const root = valueFacts(schema, context.defs);
498
683
  const fields = Object.assign(Object.create(null), root.properties);
@@ -500,13 +685,20 @@ function readType(name, value, context) {
500
685
  fields[MEMBER_FIELD] = { type: 'string', prose: false };
501
686
  const defs = Object.create(null);
502
687
  reachedDefs(value, context.defs, defs);
688
+ const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
503
689
  return {
504
690
  name,
505
691
  memberDocument,
506
692
  frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
507
693
  fields,
508
694
  sections: read.sections,
509
- shape: { schema: value, defs },
695
+ rules,
696
+ ...(createRoles === undefined ? {} : { createRoles }),
697
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
698
+ shape: {
699
+ schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
700
+ defs,
701
+ },
510
702
  };
511
703
  }
512
704
  function lineAt(text, offset) {
@@ -1,13 +1,16 @@
1
1
  import { type Definition } from './definition.js';
2
- import type { ApplyResult, BodyResult, Change, Document, Link, ParseResult } from './types.js';
2
+ import type { ApplyResult, BodyResult, FrontmatterResult, Change, Document, Link, LinkOccurrence, ParseResult } from './types.js';
3
3
  import { type YamlMap } from './yaml.js';
4
+ export declare function parseFrontmatter(content: string, file?: string): FrontmatterResult;
4
5
  export declare function parse(content: string, file?: string): ParseResult;
5
6
  export declare function relativize(document: Document, file: string, handle: string, definition?: Definition): ApplyResult;
6
7
  export declare function relativizeBody(body: string, file: string, handle: string): BodyResult;
7
8
  export declare function relinkBody(body: string, file: string, moves: ReadonlyMap<string, string>): BodyResult;
8
9
  export declare function links(document: Document, file: string): readonly Link[];
10
+ export declare function linkOccurrences(document: Document, file: string): readonly LinkOccurrence[];
9
11
  export declare function bodyLinks(body: string, file: string): readonly Link[];
10
12
  export declare function apply(document: Document, change: Change): ApplyResult;
11
13
  export declare function serialize(document: Document): string;
14
+ export declare function fieldStart(document: Document, pointer: string): number | undefined;
12
15
  export declare function frontmatter(document: Document): YamlMap | null;
13
16
  //# sourceMappingURL=document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMhF,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,WAAW,EAEZ,MAAM,YAAY,CAAC;AAC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IAAI,CAE9D"}
package/dist/document.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ARRAY_INDEX, pointerSegments } from './definition.js';
2
2
  import { hrefOccurrences } from './links.js';
3
- import { relative, retarget, SHELL_ROOMS, shellTarget, target } from './paths.js';
3
+ import { destinationPath, relative, retarget, SHELL_ROOMS, shellTarget, target } from './paths.js';
4
4
  import { references } from './references.js';
5
5
  import { headingSpans, sectionsRecord } from './sections.js';
6
6
  import { refusal } from './refuse.js';
@@ -28,19 +28,10 @@ function declaredType(fields) {
28
28
  return undefined;
29
29
  return value;
30
30
  }
31
- export function parse(content, file = '') {
31
+ function opened(content, file) {
32
32
  const fence = extractFrontmatter(content);
33
- if (fence.kind === 'none') {
34
- const spans = headingSpans(content, 0);
35
- return {
36
- ok: true,
37
- document: freezeDocument(content, undefined, {}, content.slice(0, spans[0]?.headingStart), sectionsRecord(spans, content), {
38
- root: null,
39
- yamlEnd: 0,
40
- bodyStart: 0,
41
- }),
42
- };
43
- }
33
+ if (fence.kind === 'none')
34
+ return { ok: true, root: null, fields: {}, yamlEnd: 0 };
44
35
  if (fence.kind === 'unclosed')
45
36
  return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
46
37
  try {
@@ -49,17 +40,7 @@ export function parse(content, file = '') {
49
40
  if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {
50
41
  return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
51
42
  }
52
- const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);
53
- const spans = headingSpans(content, bodyStart);
54
- const record = fields;
55
- return {
56
- ok: true,
57
- document: freezeDocument(content, declaredType(record), record, content.slice(bodyStart, spans[0]?.headingStart), sectionsRecord(spans, content), {
58
- root,
59
- yamlEnd: fence.yamlEnd,
60
- bodyStart,
61
- }),
62
- };
43
+ return { ok: true, root, fields: fields, yamlEnd: fence.yamlEnd };
63
44
  }
64
45
  catch (error) {
65
46
  if (error instanceof YamlError)
@@ -67,6 +48,30 @@ export function parse(content, file = '') {
67
48
  throw error;
68
49
  }
69
50
  }
51
+ export function parseFrontmatter(content, file = '') {
52
+ const read = opened(content, file);
53
+ if (!read.ok)
54
+ return read;
55
+ return {
56
+ ok: true,
57
+ frontmatter: Object.freeze({
58
+ content,
59
+ type: declaredType(read.fields),
60
+ fields: Object.freeze(read.fields),
61
+ }),
62
+ };
63
+ }
64
+ export function parse(content, file = '') {
65
+ const read = opened(content, file);
66
+ if (!read.ok)
67
+ return read;
68
+ const bodyStart = read.root === null ? 0 : bodyStartAfterYaml(content, read.yamlEnd);
69
+ const spans = headingSpans(content, bodyStart);
70
+ return {
71
+ ok: true,
72
+ document: freezeDocument(content, declaredType(read.fields), read.fields, content.slice(bodyStart, spans[0]?.headingStart), sectionsRecord(spans, content), { root: read.root, yamlEnd: read.yamlEnd, bodyStart }),
73
+ };
74
+ }
70
75
  function splice(content, start, end, insert) {
71
76
  return content.slice(0, start) + insert + content.slice(end);
72
77
  }
@@ -119,16 +124,30 @@ function applySection(document, name, value, prior) {
119
124
  const current = document.content.slice(span.bodyStart, span.bodyEnd);
120
125
  if (current !== prior)
121
126
  return { outcome: 'stale', document };
122
- const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));
123
- if (!parsed.ok)
124
- return { outcome: 'refuse', refusal: parsed.refusal };
125
- return { outcome: 'applied', document: parsed.document };
127
+ return replaced(document, internal.bodyStart, span.bodyStart, span.bodyEnd, value);
126
128
  }
127
129
  function applyPreamble(document, value, prior) {
128
130
  if (document.preamble !== prior)
129
131
  return { outcome: 'stale', document };
130
132
  const start = bodyStartOf(document.content);
131
- const parsed = parse(splice(document.content, start, start + document.preamble.length, value));
133
+ return replaced(document, start, start, start + document.preamble.length, value);
134
+ }
135
+ function firstHeadings(content, bodyStart) {
136
+ const first = new Map();
137
+ for (const span of headingSpans(content, bodyStart)) {
138
+ if (!first.has(span.name))
139
+ first.set(span.name, span.headingStart);
140
+ }
141
+ return first;
142
+ }
143
+ function replaced(document, bodyStart, start, end, value) {
144
+ const content = splice(document.content, start, end, value);
145
+ const after = firstHeadings(content, bodyStartOf(content));
146
+ for (const [name, at] of firstHeadings(document.content, bodyStart)) {
147
+ if (after.get(name) !== (at < start ? at : at + value.length - (end - start)))
148
+ return { outcome: 'refuse', refusal: refuse('', 'overlapping-section', name) };
149
+ }
150
+ const parsed = parse(content);
132
151
  if (!parsed.ok)
133
152
  return { outcome: 'refuse', refusal: parsed.refusal };
134
153
  return { outcome: 'applied', document: parsed.document };
@@ -256,7 +275,7 @@ export function relativizeBody(body, file, handle) {
256
275
  const relinkedBody = shellRelinked(body, 0, file, handle);
257
276
  if (typeof relinkedBody !== 'string')
258
277
  return { outcome: 'refuse', refusal: relinkedBody };
259
- const elsewhere = hrefOccurrences(relinkedBody).find(({ href }) => href.startsWith(SHELL_ROOMS));
278
+ const elsewhere = hrefOccurrences(relinkedBody).find(({ href }) => destinationPath(href)?.startsWith(SHELL_ROOMS) === true);
260
279
  if (elsewhere !== undefined)
261
280
  return { outcome: 'refuse', refusal: refuse(file, 'unresolved-link', elsewhere.href) };
262
281
  return { outcome: 'applied', body: relinkedBody };
@@ -278,23 +297,33 @@ export function relinkBody(body, file, moves) {
278
297
  }
279
298
  return { outcome: 'applied', body: rewritten + body.slice(cursor) };
280
299
  }
300
+ function occurrencesIn(text, file, offset) {
301
+ const found = [];
302
+ for (const occurrence of hrefOccurrences(text)) {
303
+ const resolved = target(file, occurrence.href);
304
+ if (resolved !== null)
305
+ found.push({ href: occurrence.href, target: resolved, start: offset + occurrence.start });
306
+ }
307
+ return found;
308
+ }
281
309
  function linksIn(text, file) {
282
310
  const found = [];
283
311
  const seen = new Set();
284
- for (const occurrence of hrefOccurrences(text)) {
312
+ for (const occurrence of occurrencesIn(text, file, 0)) {
285
313
  if (seen.has(occurrence.href))
286
314
  continue;
287
- const resolved = target(file, occurrence.href);
288
- if (resolved === null)
289
- continue;
290
315
  seen.add(occurrence.href);
291
- found.push({ href: occurrence.href, target: resolved });
316
+ found.push({ href: occurrence.href, target: occurrence.target });
292
317
  }
293
318
  return found;
294
319
  }
295
320
  export function links(document, file) {
296
321
  return linksIn(document.content.slice(bodyStartOf(document.content)), file);
297
322
  }
323
+ export function linkOccurrences(document, file) {
324
+ const bodyStart = bodyStartOf(document.content);
325
+ return occurrencesIn(document.content.slice(bodyStart), file, bodyStart);
326
+ }
298
327
  export function bodyLinks(body, file) {
299
328
  return linksIn(body, file);
300
329
  }
@@ -312,6 +341,10 @@ export function apply(document, change) {
312
341
  export function serialize(document) {
313
342
  return document.content;
314
343
  }
344
+ export function fieldStart(document, pointer) {
345
+ const root = internals.get(document)?.root;
346
+ return root === null || root === undefined ? undefined : nodeAt(root, pointer)?.start;
347
+ }
315
348
  export function frontmatter(document) {
316
349
  return internals.get(document)?.root ?? null;
317
350
  }
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
2
2
  export type { Actor, Condition, ConditionScope, ConditionTest, ConditionValue, CronCondition, DateCondition, DocumentCondition, DocumentEvent, DocumentFacts, Fact, FactKind, ItemCondition, ItemFacts, Resolved, WriteDoor, } from './condition.js';
3
+ export { headingLines } from './blocks.js';
4
+ export type { HeadingLine } from './blocks.js';
3
5
  export { divide } from './divide.js';
4
- export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
6
+ export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
5
7
  export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
6
8
  export { relative, retarget, target } from './paths.js';
7
9
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
8
10
  export { project } from './project.js';
9
11
  export { references } from './references.js';
10
12
  export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
11
- export type { Definition, JsonType, PatternFacts, PointerFacts, SectionSpec, Shape, ValueFacts, } from './definition.js';
12
- export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Reference, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
13
- export { validate, verify } from './validate.js';
13
+ export type { Definition, FieldRules, JsonType, PatternFacts, PointerFacts, RuleValue, SectionSpec, Shape, Transition, ValueFacts, } from './definition.js';
14
+ export type { ApplyResult, BodyResult, Change, Division, DivisionContext, Document, DocumentCheck, Frontmatter, FrontmatterResult, Library, ModelVerification, Link, LinkOccurrence, ParseResult, Projection, ProjectionContext, Reached, Reference, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
15
+ export { checkDocument, resolves, sectionReferences, validate, verify } from './validate.js';
14
16
  export { VERSION } from './version.js';
15
- export { equalValue, frontmatterValue } from './yaml.js';
17
+ export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
16
18
  export type { FrontmatterValue } from './yaml.js';
17
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,KAAK,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAA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AM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,cAAc,EACd,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  export { dated, datePointers, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
2
+ export { headingLines } from './blocks.js';
2
3
  export { divide } from './divide.js';
3
- export { apply, bodyLinks, links, parse, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
4
+ export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
4
5
  export { HOUSE_FIELDS, MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
5
6
  export { relative, retarget, target } from './paths.js';
6
7
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
7
8
  export { project } from './project.js';
8
9
  export { references } from './references.js';
9
10
  export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
10
- export { validate, verify } from './validate.js';
11
+ export { checkDocument, resolves, sectionReferences, validate, verify } from './validate.js';
11
12
  export { VERSION } from './version.js';
12
- export { equalValue, frontmatterValue } from './yaml.js';
13
+ export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
package/dist/links.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare function escapes(text: string, index: number): boolean;
1
2
  export type HrefOccurrence = {
2
3
  readonly href: string;
3
4
  readonly start: number;
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AA0sBA,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,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AAC,CAAC,EAAE,CAe/E;AAYD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA2DzD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAIvE"}
package/dist/links.js CHANGED
@@ -504,7 +504,7 @@ function structure(text) {
504
504
  }
505
505
  return { joins, raw };
506
506
  }
507
- function escapes(text, index) {
507
+ export function escapes(text, index) {
508
508
  return text[index] === '\\' && PUNCTUATION.test(text[index + 1] ?? '');
509
509
  }
510
510
  function referenceEnd(text, start, joins) {
package/dist/paths.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export declare function dirname(path: string): string;
2
2
  export declare function join(base: string, relative: string): string;
3
3
  export declare function normalize(path: string): string | null;
4
+ export declare function destinationPath(href: string): string | null;
4
5
  export declare function classifyHref(from: string, href: string): {
5
6
  kind: 'skip';
6
7
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAUzE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED,wBAAgB,QAAQ,CAAC,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