@agentshouse/mdmodel 0.1.0-c04c0d681d2d4 → 0.1.0-c08b2adadd2fe
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 +150 -110
- package/README.md +8 -6
- package/dist/definition.d.ts +3 -1
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +138 -26
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +5 -4
- package/dist/document.d.ts +9 -5
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +169 -67
- package/dist/event.d.ts +78 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +201 -0
- package/dist/facts.d.ts +15 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +41 -0
- package/dist/index.d.ts +23 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/kinds.d.ts +18 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +150 -0
- package/dist/markdown.d.ts +51 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +271 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +9 -2
- package/dist/pattern.d.ts +10 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +356 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +16 -21
- package/dist/query/language.d.ts +254 -0
- package/dist/query/language.d.ts.map +1 -0
- package/dist/query/language.js +620 -0
- package/dist/query/match.d.ts +14 -0
- package/dist/query/match.d.ts.map +1 -0
- package/dist/query/match.js +150 -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 +285 -0
- package/dist/reserved.d.ts +6 -0
- package/dist/reserved.d.ts.map +1 -0
- package/dist/reserved.js +21 -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 +19 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +29 -5
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +327 -161
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +40 -14
- package/fixtures/README.md +25 -3
- 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/lazy-list-item/context.json +1 -0
- package/fixtures/cases/lazy-list-item/expected.json +3 -0
- package/fixtures/cases/lazy-list-item/library/item.md +8 -0
- package/fixtures/cases/lazy-list-item/schema.yaml +3 -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/thematic-break-in-a-list-section/context.json +1 -0
- package/fixtures/cases/thematic-break-in-a-list-section/expected.json +6 -0
- package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +7 -0
- package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +3 -0
- package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
- package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
- package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
- package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
- package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
- package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
- package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
- package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
- package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
- package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
- package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
- package/fixtures/division.json +47 -2
- package/fixtures/preamble.json +24 -3
- package/fixtures/projection.json +105 -2
- package/fixtures/queries.json +964 -0
- package/package.json +16 -2
- package/dist/blocks.d.ts +0 -11
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -69
- package/dist/condition.d.ts +0 -162
- package/dist/condition.d.ts.map +0 -1
- package/dist/condition.js +0 -616
- package/dist/links.d.ts +0 -29
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -788
- package/dist/profile.d.ts +0 -6
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -5
- package/dist/sections.d.ts +0 -11
- package/dist/sections.d.ts.map +0 -1
- package/dist/sections.js +0 -57
package/dist/definition.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
|
+
import { linearPattern } from './pattern.js';
|
|
2
3
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
3
4
|
export const JSON_TYPES = [
|
|
4
5
|
'string',
|
|
@@ -24,16 +25,20 @@ const ANNOTATIONS = new Set([
|
|
|
24
25
|
'writeOnly',
|
|
25
26
|
]);
|
|
26
27
|
const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
|
|
28
|
+
const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
|
|
29
|
+
const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
|
|
27
30
|
const DEFS_REFERENCE = '#/$defs/';
|
|
31
|
+
const UNBOUNDED_FORMAT = 'url';
|
|
28
32
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
29
33
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
34
|
+
export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
|
|
30
35
|
const HOUSE_KEYS = {
|
|
31
36
|
[TYPE_FIELD]: { prose: false },
|
|
32
37
|
[SITE_FIELD]: { prose: false },
|
|
33
38
|
[RECEIVED_FIELD]: { prose: false },
|
|
34
39
|
};
|
|
35
40
|
function refuse(rule, location) {
|
|
36
|
-
return
|
|
41
|
+
return { rule, location };
|
|
37
42
|
}
|
|
38
43
|
export function escapePointer(key) {
|
|
39
44
|
return key.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
@@ -45,12 +50,12 @@ export function pointerSegments(pointer) {
|
|
|
45
50
|
return pointer.split('/').slice(1).map(unescapePointer);
|
|
46
51
|
}
|
|
47
52
|
export function refTarget(reference, defs) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (segments.some((segment) => escapePointer(unescapePointer(segment)) !== segment))
|
|
53
|
+
const pointer = reference.slice('#'.length);
|
|
54
|
+
if (!reference.startsWith(DEFS_REFERENCE) ||
|
|
55
|
+
UNRESOLVED.test(reference) ||
|
|
56
|
+
!JSON_POINTER.test(pointer))
|
|
53
57
|
return undefined;
|
|
58
|
+
const [, name = '', ...rest] = pointerSegments(pointer);
|
|
54
59
|
if (!Object.hasOwn(defs, name))
|
|
55
60
|
return undefined;
|
|
56
61
|
let node = defs[name];
|
|
@@ -81,15 +86,7 @@ export function refTarget(reference, defs) {
|
|
|
81
86
|
return { name, node };
|
|
82
87
|
}
|
|
83
88
|
function compiles(pattern) {
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
try {
|
|
87
|
-
new RegExp(pattern, 'u');
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
89
|
+
return typeof pattern === 'string' && linearPattern(pattern) !== null;
|
|
93
90
|
}
|
|
94
91
|
function finite(value) {
|
|
95
92
|
return typeof value === 'number' && Number.isFinite(value);
|
|
@@ -103,7 +100,7 @@ function strings(value) {
|
|
|
103
100
|
new Set(value).size === value.length);
|
|
104
101
|
}
|
|
105
102
|
function schemaFailure(value, at, context) {
|
|
106
|
-
if (typeof value === 'boolean')
|
|
103
|
+
if (!context.checked || typeof value === 'boolean')
|
|
107
104
|
return undefined;
|
|
108
105
|
if (!isRecord(value))
|
|
109
106
|
return refuse('schema', at);
|
|
@@ -199,7 +196,7 @@ const KEYWORDS = {
|
|
|
199
196
|
uniqueItems: FLAG,
|
|
200
197
|
required: strings,
|
|
201
198
|
dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
|
|
202
|
-
format:
|
|
199
|
+
format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
|
|
203
200
|
contentEncoding: TEXT,
|
|
204
201
|
contentMediaType: TEXT,
|
|
205
202
|
title: TEXT,
|
|
@@ -447,7 +444,7 @@ export function itemFacts(facts, index) {
|
|
|
447
444
|
export function memberFacts(facts, key) {
|
|
448
445
|
if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
|
|
449
446
|
return facts.properties[key];
|
|
450
|
-
const pattern = facts.patterns?.find((one) =>
|
|
447
|
+
const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
|
|
451
448
|
return pattern === undefined ? facts.additional : pattern.facts;
|
|
452
449
|
}
|
|
453
450
|
export function crossedFacts(facts) {
|
|
@@ -550,6 +547,87 @@ function readSections(value, at, context) {
|
|
|
550
547
|
}
|
|
551
548
|
return { sections };
|
|
552
549
|
}
|
|
550
|
+
function branchSectionsFailure(sections, declared, where) {
|
|
551
|
+
if (!isRecord(sections))
|
|
552
|
+
return refuse('sections', where);
|
|
553
|
+
for (const [name, spec] of Object.entries(sections)) {
|
|
554
|
+
const place = `${where}/${escapePointer(name)}`;
|
|
555
|
+
const own = isRecord(declared) && Object.hasOwn(declared, name) ? declared[name] : undefined;
|
|
556
|
+
if (!isRecord(spec) || !isRecord(own))
|
|
557
|
+
return refuse('sections', place);
|
|
558
|
+
const { required, ...kind } = spec;
|
|
559
|
+
const { required: _required, ...ownKind } = own;
|
|
560
|
+
if (required !== undefined && typeof required !== 'boolean')
|
|
561
|
+
return refuse('sections', `${place}/required`);
|
|
562
|
+
if (!equalValue(kind, ownKind))
|
|
563
|
+
return refuse('sections', place);
|
|
564
|
+
}
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
function withoutBranchSections(schema, declared, at) {
|
|
568
|
+
const kept = { ...schema };
|
|
569
|
+
if (Array.isArray(schema.allOf)) {
|
|
570
|
+
const entries = [];
|
|
571
|
+
for (const [index, entry] of schema.allOf.entries()) {
|
|
572
|
+
const read = isRecord(entry)
|
|
573
|
+
? withoutBranchSections(entry, declared, `${at}/allOf/${index}`)
|
|
574
|
+
: { schema: entry };
|
|
575
|
+
if ('failure' in read)
|
|
576
|
+
return read;
|
|
577
|
+
entries.push(read.schema);
|
|
578
|
+
}
|
|
579
|
+
kept.allOf = entries;
|
|
580
|
+
}
|
|
581
|
+
if (schema.if === undefined)
|
|
582
|
+
return { schema: kept };
|
|
583
|
+
for (const branch of ['then', 'else']) {
|
|
584
|
+
const held = schema[branch];
|
|
585
|
+
if (!isRecord(held))
|
|
586
|
+
continue;
|
|
587
|
+
const { sections, ...rest } = held;
|
|
588
|
+
const failure = sections === undefined
|
|
589
|
+
? undefined
|
|
590
|
+
: branchSectionsFailure(sections, declared, `${at}/${branch}/sections`);
|
|
591
|
+
if (failure !== undefined)
|
|
592
|
+
return { failure };
|
|
593
|
+
const read = withoutBranchSections(rest, declared, `${at}/${branch}`);
|
|
594
|
+
if ('failure' in read)
|
|
595
|
+
return read;
|
|
596
|
+
kept[branch] = read.schema;
|
|
597
|
+
}
|
|
598
|
+
return { schema: kept };
|
|
599
|
+
}
|
|
600
|
+
function untitledSchema(node) {
|
|
601
|
+
if (!isRecord(node))
|
|
602
|
+
return node;
|
|
603
|
+
const kept = {};
|
|
604
|
+
for (const [key, held] of Object.entries(node)) {
|
|
605
|
+
if (key === 'title' && typeof held === 'string')
|
|
606
|
+
continue;
|
|
607
|
+
const check = Object.hasOwn(KEYWORDS, key) ? KEYWORDS[key] : undefined;
|
|
608
|
+
if (check === SCHEMA)
|
|
609
|
+
kept[key] = untitledSchema(held);
|
|
610
|
+
else if (check === SCHEMA_LIST && Array.isArray(held))
|
|
611
|
+
kept[key] = held.map(untitledSchema);
|
|
612
|
+
else if (check === SCHEMA_MAP && isRecord(held))
|
|
613
|
+
kept[key] = untitledMap(held);
|
|
614
|
+
else
|
|
615
|
+
kept[key] = held;
|
|
616
|
+
}
|
|
617
|
+
return kept;
|
|
618
|
+
}
|
|
619
|
+
function untitledMap(map) {
|
|
620
|
+
return Object.fromEntries(Object.entries(map).map(([key, held]) => [key, untitledSchema(held)]));
|
|
621
|
+
}
|
|
622
|
+
export function untitled(definition) {
|
|
623
|
+
return {
|
|
624
|
+
...definition,
|
|
625
|
+
shape: {
|
|
626
|
+
schema: untitledSchema(definition.shape.schema),
|
|
627
|
+
defs: untitledMap(definition.shape.defs),
|
|
628
|
+
},
|
|
629
|
+
};
|
|
630
|
+
}
|
|
553
631
|
function deepFreeze(value) {
|
|
554
632
|
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
555
633
|
Object.freeze(value);
|
|
@@ -587,8 +665,9 @@ function composites(node, defs, seen) {
|
|
|
587
665
|
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
588
666
|
const conditioned = () => {
|
|
589
667
|
const met = composites(node.then ?? true, defs, seen);
|
|
590
|
-
|
|
591
|
-
|
|
668
|
+
const condition = composites(node.if, defs, seen);
|
|
669
|
+
const otherwise = composites(node.else ?? true, defs, seen);
|
|
670
|
+
return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
|
|
592
671
|
};
|
|
593
672
|
const bounds = [
|
|
594
673
|
typed(node.type),
|
|
@@ -657,6 +736,26 @@ function unruled(schema) {
|
|
|
657
736
|
}
|
|
658
737
|
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
659
738
|
}
|
|
739
|
+
function providedType(name, value, provided, checked) {
|
|
740
|
+
const at = `/${escapePointer(name)}`;
|
|
741
|
+
if (checked && provided.nameable?.includes(name) !== true)
|
|
742
|
+
return refuse('provided-type', at);
|
|
743
|
+
if (!isRecord(value))
|
|
744
|
+
return refuse('schema', at);
|
|
745
|
+
const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
|
|
746
|
+
if (checked && declared !== undefined)
|
|
747
|
+
return refuse('provided-type', `${at}/${escapePointer(declared)}`);
|
|
748
|
+
const { create_roles: createRoles, delete_roles: deleteRoles } = value;
|
|
749
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
750
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
751
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
752
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
753
|
+
return {
|
|
754
|
+
...provided.types[name],
|
|
755
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
756
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
757
|
+
};
|
|
758
|
+
}
|
|
660
759
|
function readType(name, value, context) {
|
|
661
760
|
const at = `/${escapePointer(name)}`;
|
|
662
761
|
if (!isRecord(value))
|
|
@@ -673,7 +772,10 @@ function readType(name, value, context) {
|
|
|
673
772
|
: readSections(declared, `${at}/sections`, context);
|
|
674
773
|
if ('failure' in read)
|
|
675
774
|
return read.failure;
|
|
676
|
-
const
|
|
775
|
+
const unbranched = withoutBranchSections(ruled, declared, at);
|
|
776
|
+
if ('failure' in unbranched)
|
|
777
|
+
return unbranched.failure;
|
|
778
|
+
const { schema, written } = unruled(unbranched.schema);
|
|
677
779
|
const failure = schemaFailure(schema, at, context);
|
|
678
780
|
if (failure !== undefined)
|
|
679
781
|
return failure;
|
|
@@ -712,7 +814,7 @@ function readType(name, value, context) {
|
|
|
712
814
|
function lineAt(text, offset) {
|
|
713
815
|
return text.slice(0, offset).split(/\r\n|\r|\n/).length;
|
|
714
816
|
}
|
|
715
|
-
export function readSchema(text) {
|
|
817
|
+
export function readSchema(text, provided = NO_TYPES, checked = true) {
|
|
716
818
|
let root;
|
|
717
819
|
try {
|
|
718
820
|
root = jsValue(parseYamlMapping(text, 0, text.length));
|
|
@@ -726,11 +828,15 @@ export function readSchema(text) {
|
|
|
726
828
|
if (!isRecord(defs))
|
|
727
829
|
return refuse('$defs', '/$defs');
|
|
728
830
|
const names = Object.keys(root).filter((key) => key !== '$defs');
|
|
729
|
-
for (const name of names) {
|
|
831
|
+
for (const name of checked ? names : []) {
|
|
730
832
|
if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
|
|
731
833
|
return refuse('schema-type-name', `/${escapePointer(name)}`);
|
|
732
834
|
}
|
|
733
|
-
const context = {
|
|
835
|
+
const context = {
|
|
836
|
+
defs,
|
|
837
|
+
types: new Set([...names, ...Object.keys(provided.types)]),
|
|
838
|
+
checked,
|
|
839
|
+
};
|
|
734
840
|
for (const [name, def] of Object.entries(defs)) {
|
|
735
841
|
const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
|
|
736
842
|
if (failure !== undefined)
|
|
@@ -739,15 +845,21 @@ export function readSchema(text) {
|
|
|
739
845
|
const types = Object.create(null);
|
|
740
846
|
let marked = false;
|
|
741
847
|
for (const name of names) {
|
|
742
|
-
const definition =
|
|
848
|
+
const definition = Object.hasOwn(provided.types, name)
|
|
849
|
+
? providedType(name, root[name], provided, checked)
|
|
850
|
+
: readType(name, root[name], context);
|
|
743
851
|
if ('rule' in definition)
|
|
744
852
|
return definition;
|
|
745
|
-
if (definition.memberDocument) {
|
|
853
|
+
if (checked && definition.memberDocument) {
|
|
746
854
|
if (marked)
|
|
747
855
|
return refuse('member_document', `/${escapePointer(name)}/member_document`);
|
|
748
856
|
marked = true;
|
|
749
857
|
}
|
|
750
858
|
types[name] = deepFreeze(definition);
|
|
751
859
|
}
|
|
860
|
+
for (const [name, definition] of Object.entries(provided.types)) {
|
|
861
|
+
if (!Object.hasOwn(types, name))
|
|
862
|
+
types[name] = definition;
|
|
863
|
+
}
|
|
752
864
|
return Object.freeze({ types: Object.freeze(types) });
|
|
753
865
|
}
|
package/dist/divide.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAwXpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAe3F"}
|
package/dist/divide.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readingOf } from './document.js';
|
|
2
|
+
import { blockRanges, headingsIn } from './markdown.js';
|
|
2
3
|
import { firstEditFrom, projectionInput, rangeText, } from './project.js';
|
|
3
4
|
import { refusal } from './refuse.js';
|
|
4
5
|
const SMALLEST_BOUND = 2;
|
|
@@ -12,8 +13,7 @@ function node(draft) {
|
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
function forest(state, range) {
|
|
15
|
-
const
|
|
16
|
-
const headings = headingLines(content, range.start, range.end);
|
|
16
|
+
const headings = headingsIn(state.reading, range.start, range.end);
|
|
17
17
|
const roots = [];
|
|
18
18
|
const open = [];
|
|
19
19
|
const first = headings[0]?.start ?? range.end;
|
|
@@ -282,7 +282,7 @@ function ownBlocks(subject, end, blocks) {
|
|
|
282
282
|
}
|
|
283
283
|
function divideNode(state, subject) {
|
|
284
284
|
const end = subject.children[0]?.start ?? subject.end;
|
|
285
|
-
const blocks = blockRanges(state.
|
|
285
|
+
const blocks = blockRanges(state.reading, subject.bodyStart, end);
|
|
286
286
|
const children = { heading: '', emitted: 0 };
|
|
287
287
|
if (blocks.length === 0 && subject.children.length > 0) {
|
|
288
288
|
const [first, ...rest] = subject.children;
|
|
@@ -311,6 +311,7 @@ export function divide(document, file, context) {
|
|
|
311
311
|
return { ok: false, refusal: result.refusal };
|
|
312
312
|
const state = {
|
|
313
313
|
content: document.content,
|
|
314
|
+
reading: readingOf(document),
|
|
314
315
|
edits: result.input.edits,
|
|
315
316
|
bound: context.bound,
|
|
316
317
|
spans: [],
|
package/dist/document.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
|
-
import { type
|
|
3
|
-
import type { ApplyResult, BodyResult, FrontmatterResult, Change, Document, Link, ParseResult } from './types.js';
|
|
2
|
+
import { type HrefOccurrence, type Reading } from './markdown.js';
|
|
3
|
+
import type { ApplyResult, BodyResult, FrontmatterResult, Change, DefinitionOf, Document, Link, ParseResult, Span, UnlinkedBody } from './types.js';
|
|
4
4
|
import { type YamlMap } from './yaml.js';
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function readingOf(document: Document): Reading;
|
|
6
|
+
export declare function linkDestinations(document: Document): readonly HrefOccurrence[];
|
|
7
|
+
export declare function textSpans(document: Document): readonly Span[];
|
|
6
8
|
export declare function parseFrontmatter(content: string, file?: string): FrontmatterResult;
|
|
7
|
-
export declare function parse(content: string, file?: string): ParseResult;
|
|
9
|
+
export declare function parse(content: string, file?: string, definition?: Definition | DefinitionOf): ParseResult;
|
|
10
|
+
export declare function create(type: string | undefined, definition?: Definition): Document;
|
|
8
11
|
export declare function relativize(document: Document, file: string, handle: string, definition?: Definition, kept?: ReadonlySet<string>): ApplyResult;
|
|
9
12
|
export declare function relativizeBody(body: string, file: string, handle: string): BodyResult;
|
|
10
13
|
export declare function relinkBody(body: string, file: string, moves: ReadonlyMap<string, string>): BodyResult;
|
|
14
|
+
export declare function unlinkBody(body: string, hrefs: ReadonlySet<string>): UnlinkedBody;
|
|
11
15
|
export declare function links(document: Document, file: string): readonly Link[];
|
|
12
16
|
export declare function bodyLinks(body: string, file: string): readonly Link[];
|
|
13
|
-
export declare function apply(document: Document, changes: readonly Change[]): ApplyResult;
|
|
17
|
+
export declare function apply(document: Document, changes: readonly Change[], definition?: Definition): ApplyResult;
|
|
14
18
|
export declare function serialize(document: Document): string;
|
|
15
19
|
export declare function frontmatter(document: Document): YamlMap | null;
|
|
16
20
|
//# sourceMappingURL=document.d.ts.map
|
package/dist/document.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,eAAe,CAAC;AAavB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,WAAW,EAEX,IAAI,EACJ,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAcL,KAAK,OAAO,EAEb,MAAM,WAAW,CAAC;AA2BnB,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAKrD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,cAAc,EAAE,CAG9E;AAgBD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,IAAI,EAAE,CAG7D;AAwDD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,iBAAiB,CAW9E;AAED,wBAAgB,KAAK,CACnB,OAAO,EAAE,MAAM,EACf,IAAI,SAAK,EACT,UAAU,CAAC,EAAE,UAAU,GAAG,YAAY,GACrC,WAAW,CAYb;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,QAAQ,CAQlF;AAmED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,UAAU,EACvB,IAAI,GAAE,WAAW,CAAC,MAAM,CAAa,GACpC,WAAW,CAuBb;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAUrF;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,UAAU,CAkBZ;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,YAAY,CAqBjF;AAeD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAEvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAErE;AAsPD,wBAAgB,KAAK,CACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,UAAU,CAAC,EAAE,UAAU,GACtB,WAAW,CAgDb;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE9D"}
|