@agentshouse/mdmodel 0.1.0-alpha.3 → 0.1.0-alpha.5
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/README.md +74 -3
- package/dist/document.d.ts +2 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +92 -4
- package/dist/document.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +7 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +259 -48
- package/dist/links.js.map +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +5 -0
- package/dist/paths.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate.js +3 -3
- package/dist/validate.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +5 -3
- package/dist/yaml.js.map +1 -1
- package/fixtures/README.md +18 -0
- package/fixtures/cases/bracketed-link-definition/context.json +1 -0
- package/fixtures/cases/bracketed-link-definition/expected.json +1 -0
- package/fixtures/cases/bracketed-link-definition/library/item.md +10 -0
- package/fixtures/cases/bracketed-link-definition/library/types/task.md +7 -0
- package/fixtures/cases/duplicate-link-definition/context.json +1 -0
- package/fixtures/cases/duplicate-link-definition/expected.json +1 -0
- package/fixtures/cases/duplicate-link-definition/library/item.md +11 -0
- package/fixtures/cases/duplicate-link-definition/library/types/task.md +7 -0
- package/fixtures/cases/fenced-link-definition/context.json +1 -0
- package/fixtures/cases/fenced-link-definition/expected.json +1 -0
- package/fixtures/cases/fenced-link-definition/library/item.md +12 -0
- package/fixtures/cases/fenced-link-definition/library/types/task.md +7 -0
- package/fixtures/cases/interrupted-link-definition/context.json +1 -0
- package/fixtures/cases/interrupted-link-definition/expected.json +1 -0
- package/fixtures/cases/interrupted-link-definition/library/notes/draft.md +8 -0
- package/fixtures/cases/interrupted-link-definition/library/types/note.md +3 -0
- package/fixtures/cases/long-fence-link-definition/context.json +1 -0
- package/fixtures/cases/long-fence-link-definition/expected.json +1 -0
- package/fixtures/cases/long-fence-link-definition/library/notes/draft.md +9 -0
- package/fixtures/cases/long-fence-link-definition/library/types/note.md +3 -0
- package/fixtures/cases/paragraph-link-definition/context.json +5 -0
- package/fixtures/cases/paragraph-link-definition/expected.json +1 -0
- package/fixtures/cases/paragraph-link-definition/library/notes/draft.md +10 -0
- package/fixtures/cases/paragraph-link-definition/library/types/note.md +3 -0
- package/fixtures/cases/quoted-link-definition/context.json +1 -0
- package/fixtures/cases/quoted-link-definition/expected.json +6 -0
- package/fixtures/cases/quoted-link-definition/library/notes/draft.md +7 -0
- package/fixtures/cases/quoted-link-definition/library/types/note.md +3 -0
- package/fixtures/cases/truncated-link-definition/context.json +1 -0
- package/fixtures/cases/truncated-link-definition/expected.json +6 -0
- package/fixtures/cases/truncated-link-definition/library/notes/draft.md +7 -0
- package/fixtures/cases/truncated-link-definition/library/notes/other.md +5 -0
- package/fixtures/cases/truncated-link-definition/library/types/note.md +3 -0
- package/fixtures/cases/wide-item-fence-link/context.json +1 -0
- package/fixtures/cases/wide-item-fence-link/expected.json +1 -0
- package/fixtures/cases/wide-item-fence-link/library/notes/draft.md +7 -0
- package/fixtures/cases/wide-item-fence-link/library/types/note.md +3 -0
- package/fixtures/preamble.json +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ Package releases are published after the User confirms.
|
|
|
23
23
|
```ts
|
|
24
24
|
import {
|
|
25
25
|
apply,
|
|
26
|
+
links,
|
|
26
27
|
MARKDOWN_SYNTAX_PROFILE,
|
|
27
28
|
parse,
|
|
28
29
|
serialize,
|
|
@@ -47,6 +48,15 @@ if (parsed.ok) {
|
|
|
47
48
|
prior: 'Hello',
|
|
48
49
|
});
|
|
49
50
|
if (next.outcome === 'applied') serialize(next.document);
|
|
51
|
+
for (const link of links(parsed.document, 'tasks/two.md')) {
|
|
52
|
+
if (link.target !== 'data/export.csv') continue;
|
|
53
|
+
const moved = apply(parsed.document, {
|
|
54
|
+
kind: 'link',
|
|
55
|
+
href: link.href,
|
|
56
|
+
to: '../files/export.csv',
|
|
57
|
+
});
|
|
58
|
+
if (moved.outcome === 'applied') serialize(moved.document);
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
```
|
|
52
62
|
|
|
@@ -65,9 +75,70 @@ section, the violated rule, and `VERSION`. Every caller operation that validates
|
|
|
65
75
|
a resulting collection supplies that collection's context to this same
|
|
66
76
|
`validate` function. `parse`, `apply`, and `serialize` operate on a single text
|
|
67
77
|
Document; they do not validate collection membership or consume binary bytes.
|
|
68
|
-
`apply` sets one typed field, including a list field as a whole,
|
|
69
|
-
one
|
|
70
|
-
|
|
78
|
+
`apply` sets one typed field, including a list field as a whole, replaces
|
|
79
|
+
one existing section body or the preamble against that value's prior content,
|
|
80
|
+
or rewrites one Markdown link destination. A section need not be declared by
|
|
81
|
+
the Document's MD Type to be replaced. A field change does not reformat the rest of the file.
|
|
82
|
+
|
|
83
|
+
`Document.preamble` is a readonly string containing the exact source after
|
|
84
|
+
frontmatter and before the first section heading recognized by the existing
|
|
85
|
+
section parser. Without a section it is the entire post-frontmatter body;
|
|
86
|
+
without frontmatter it starts at the beginning of the Document. An empty span
|
|
87
|
+
is `''`. It includes whitespace, newlines, a leading H1, and any fenced text
|
|
88
|
+
before the first section. The closing frontmatter delimiter and its line ending
|
|
89
|
+
belong to frontmatter. Section recognition and the syntax profile are unchanged.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const parsed = parse(content);
|
|
93
|
+
if (parsed.ok) {
|
|
94
|
+
const change = {
|
|
95
|
+
kind: 'preamble' as const,
|
|
96
|
+
prior: parsed.document.preamble,
|
|
97
|
+
value: 'Updated introduction.\n\n',
|
|
98
|
+
};
|
|
99
|
+
const result = apply(parsed.document, change);
|
|
100
|
+
if (result.outcome === 'applied') serialize(result.document);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`apply(document, { kind: 'preamble', prior, value })` compares `prior` to the
|
|
105
|
+
current preamble exactly. A mismatch returns `{ outcome: 'stale', document }`
|
|
106
|
+
with the unchanged current Document. A match replaces only that source span,
|
|
107
|
+
then parses a new immutable Document; the original is unchanged. Frontmatter
|
|
108
|
+
and section source outside the span retain their exact bytes, including newline
|
|
109
|
+
and heading syntax. As with section replacement, `value` is literal source:
|
|
110
|
+
no newline or separator is inserted, and the resulting source is parsed again.
|
|
111
|
+
An invalid frontmatter result receives the existing parse refusal. Independent
|
|
112
|
+
field, section, and preamble edits keep their own prior values valid.
|
|
113
|
+
|
|
114
|
+
For a moved link, use `links` and the `link` change below to obtain the rewritten
|
|
115
|
+
Document, then compare its public `preamble` and `sections` to the original.
|
|
116
|
+
Submit the changed values with their original priors. Consumers need no source
|
|
117
|
+
span calculation or private Model import. Collection validation remains a
|
|
118
|
+
separate call against the resulting Library.
|
|
119
|
+
|
|
120
|
+
`links(document, file)` is the inventory of that Document's ordinary link and
|
|
121
|
+
image destinations that resolve to a collection Path, each with the destination
|
|
122
|
+
`href` exactly as written and the `target` Path it resolves to relative to
|
|
123
|
+
`file`. A `?query` or `#fragment` the destination carries is part of `href` and
|
|
124
|
+
not part of `target`. Entries are ordered by the position of the destination
|
|
125
|
+
text a rewrite would change, and one destination written the same way appears
|
|
126
|
+
once however many times it occurs. A destination that the syntax profile does not read as a
|
|
127
|
+
link, one that is empty, a bare fragment, or carries a URL scheme, and one that
|
|
128
|
+
leaves the collection are not in the inventory. Frontmatter field values,
|
|
129
|
+
including typed references, are not link destinations and are never enumerated.
|
|
130
|
+
|
|
131
|
+
`apply(document, { kind: 'link', href, to })` rewrites every body occurrence of
|
|
132
|
+
that written destination and changes nothing else, so a caller that moves a Path
|
|
133
|
+
rewrites its referring Documents without a second Markdown parser. `to` is the
|
|
134
|
+
Path the destination must resolve to instead; the `?query` or `#fragment` the
|
|
135
|
+
written destination carried is not part of that Path and is kept. A Document
|
|
136
|
+
that does not carry the destination is `stale`. A reference definition is
|
|
137
|
+
rewritten once however many uses name it. The destination is
|
|
138
|
+
written in the form the syntax profile reads back: bare when it carries no
|
|
139
|
+
whitespace, does not open with `<`, and balances its parentheses, otherwise
|
|
140
|
+
inside angle brackets, which the original form is kept in when it still fits. A
|
|
141
|
+
destination that neither form can carry is refused as `unwritable-link`.
|
|
71
142
|
|
|
72
143
|
## Fixtures
|
|
73
144
|
|
package/dist/document.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ApplyResult, Change, Document, ParseResult } from './types.js';
|
|
1
|
+
import type { ApplyResult, Change, Document, Link, ParseResult } from './types.js';
|
|
2
2
|
export declare function parse(content: string, file?: string): ParseResult;
|
|
3
|
+
export declare function links(document: Document, file: string): readonly Link[];
|
|
3
4
|
export declare function apply(document: Document, change: Change): ApplyResult;
|
|
4
5
|
export declare function serialize(document: Document): string;
|
|
5
6
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsDnF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAkD7D;AAyGD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAWvE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAarE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD"}
|
package/dist/document.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { hrefOccurrences } from './links.js';
|
|
2
|
+
import { classifyHref, hrefSuffix } from './paths.js';
|
|
1
3
|
import { headingSpans, sectionsRecord } from './sections.js';
|
|
2
4
|
import { refusal } from './refuse.js';
|
|
3
|
-
import { bodyStartAfterYaml, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError } from './yaml.js';
|
|
5
|
+
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError } from './yaml.js';
|
|
4
6
|
const internals = new WeakMap();
|
|
5
7
|
function refuse(file, rule, location) {
|
|
6
8
|
return location === undefined ? refusal(file, rule) : refusal(file, rule, {
|
|
7
9
|
location
|
|
8
10
|
});
|
|
9
11
|
}
|
|
10
|
-
function freezeDocument(content, type, fields, sections, internal) {
|
|
12
|
+
function freezeDocument(content, type, fields, preamble, sections, internal) {
|
|
11
13
|
const document = Object.freeze({
|
|
12
14
|
content,
|
|
13
15
|
type,
|
|
14
16
|
fields: Object.freeze(fields),
|
|
17
|
+
preamble,
|
|
15
18
|
sections: Object.freeze(sections)
|
|
16
19
|
});
|
|
17
20
|
internals.set(document, internal);
|
|
@@ -29,7 +32,7 @@ export function parse(content, file = '') {
|
|
|
29
32
|
const spans = headingSpans(content, 0);
|
|
30
33
|
return {
|
|
31
34
|
ok: true,
|
|
32
|
-
document: freezeDocument(content, undefined, {}, sectionsRecord(spans, content), {
|
|
35
|
+
document: freezeDocument(content, undefined, {}, content.slice(0, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
33
36
|
root: null,
|
|
34
37
|
yamlEnd: 0,
|
|
35
38
|
bodyStart: 0
|
|
@@ -54,7 +57,7 @@ export function parse(content, file = '') {
|
|
|
54
57
|
const record = fields;
|
|
55
58
|
return {
|
|
56
59
|
ok: true,
|
|
57
|
-
document: freezeDocument(content, declaredType(record), record, sectionsRecord(spans, content), {
|
|
60
|
+
document: freezeDocument(content, declaredType(record), record, content.slice(bodyStart, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
58
61
|
root,
|
|
59
62
|
yamlEnd: fence.yamlEnd,
|
|
60
63
|
bodyStart
|
|
@@ -133,7 +136,92 @@ function applySection(document, name, value, prior) {
|
|
|
133
136
|
document: parsed.document
|
|
134
137
|
};
|
|
135
138
|
}
|
|
139
|
+
function applyPreamble(document, value, prior) {
|
|
140
|
+
if (document.preamble !== prior) return {
|
|
141
|
+
outcome: 'stale',
|
|
142
|
+
document
|
|
143
|
+
};
|
|
144
|
+
const start = bodyStartOf(document.content);
|
|
145
|
+
const parsed = parse(splice(document.content, start, start + document.preamble.length, value));
|
|
146
|
+
if (!parsed.ok) return {
|
|
147
|
+
outcome: 'refuse',
|
|
148
|
+
refusal: parsed.refusal
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
outcome: 'applied',
|
|
152
|
+
document: parsed.document
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function fitsBare(to) {
|
|
156
|
+
if (to === '' || to.startsWith('<')) return false;
|
|
157
|
+
let depth = 0;
|
|
158
|
+
for (const character of to){
|
|
159
|
+
if (/[\s\u0000-\u001f\u007f]/.test(character)) return false;
|
|
160
|
+
if (character === '(') depth += 1;
|
|
161
|
+
else if (character === ')') {
|
|
162
|
+
if (depth === 0) return false;
|
|
163
|
+
depth -= 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return depth === 0;
|
|
167
|
+
}
|
|
168
|
+
function fitsBrackets(to) {
|
|
169
|
+
return to !== '' && !/[<>\n\r]/.test(to);
|
|
170
|
+
}
|
|
171
|
+
function destinationText(to, bracketed) {
|
|
172
|
+
if (fitsBare(to)) return bracketed && fitsBrackets(to) ? `<${to}>` : to;
|
|
173
|
+
if (fitsBrackets(to)) return `<${to}>`;
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
function applyLink(document, href, to) {
|
|
177
|
+
const content = document.content;
|
|
178
|
+
const bodyStart = bodyStartOf(content);
|
|
179
|
+
const matches = hrefOccurrences(content.slice(bodyStart)).filter((occurrence)=>occurrence.href === href);
|
|
180
|
+
if (matches.length === 0) return {
|
|
181
|
+
outcome: 'stale',
|
|
182
|
+
document
|
|
183
|
+
};
|
|
184
|
+
const written = to + hrefSuffix(href);
|
|
185
|
+
let rewritten = '';
|
|
186
|
+
let cursor = 0;
|
|
187
|
+
for (const match of matches){
|
|
188
|
+
const text = destinationText(written, match.bracketed);
|
|
189
|
+
if (text === null) return {
|
|
190
|
+
outcome: 'refuse',
|
|
191
|
+
refusal: refuse('', 'unwritable-link', written)
|
|
192
|
+
};
|
|
193
|
+
rewritten += content.slice(cursor, bodyStart + match.start);
|
|
194
|
+
rewritten += text;
|
|
195
|
+
cursor = bodyStart + match.end;
|
|
196
|
+
}
|
|
197
|
+
const parsed = parse(rewritten + content.slice(cursor));
|
|
198
|
+
if (!parsed.ok) return {
|
|
199
|
+
outcome: 'refuse',
|
|
200
|
+
refusal: parsed.refusal
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
outcome: 'applied',
|
|
204
|
+
document: parsed.document
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export function links(document, file) {
|
|
208
|
+
const found = [];
|
|
209
|
+
const seen = new Set();
|
|
210
|
+
for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))){
|
|
211
|
+
if (seen.has(occurrence.href)) continue;
|
|
212
|
+
const resolved = classifyHref(file, occurrence.href);
|
|
213
|
+
if (resolved.kind !== 'path') continue;
|
|
214
|
+
seen.add(occurrence.href);
|
|
215
|
+
found.push({
|
|
216
|
+
href: occurrence.href,
|
|
217
|
+
target: resolved.path
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return found;
|
|
221
|
+
}
|
|
136
222
|
export function apply(document, change) {
|
|
223
|
+
if (change.kind === 'link') return applyLink(document, change.href, change.to);
|
|
224
|
+
if (change.kind === 'preamble') return applyPreamble(document, change.value, change.prior);
|
|
137
225
|
try {
|
|
138
226
|
if (change.kind === 'field') return applyField(document, change.name, change.value, change.prior);
|
|
139
227
|
return applySection(document, change.name, change.value, change.prior);
|
package/dist/document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/document.ts"],"sourcesContent":["import { headingSpans, sectionsRecord } from './sections.js';\nimport { refusal } from './refuse.js';\nimport type { ApplyResult, Change, Document, ParseResult } from './types.js';\nimport {\n bodyStartAfterYaml,\n equalValue,\n extractFrontmatter,\n jsValue,\n lineEnding,\n mapEntry,\n parseYamlMapping,\n serializeJs,\n serializeKey,\n YamlError,\n type YamlMap,\n} from './yaml.js';\n\ntype Internal = {\n readonly root: YamlMap | null;\n readonly yamlEnd: number;\n readonly bodyStart: number;\n};\n\nconst internals = new WeakMap<Document, Internal>();\n\nfunction refuse(file: string, rule: string, location?: string) {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction freezeDocument(\n content: string,\n type: string | undefined,\n fields: Record<string, unknown>,\n sections: Record<string, string>,\n internal: Internal,\n): Document {\n const document: Document = Object.freeze({\n content,\n type,\n fields: Object.freeze(fields),\n sections: Object.freeze(sections),\n });\n internals.set(document, internal);\n return document;\n}\n\nfunction declaredType(fields: Record<string, unknown>): string | undefined {\n const value = fields.type;\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'string' || value === '') return undefined;\n return value;\n}\n\nexport function parse(content: string, file = ''): ParseResult {\n const fence = extractFrontmatter(content);\n if (fence.kind === 'none') {\n const spans = headingSpans(content, 0);\n return {\n ok: true,\n document: freezeDocument(content, undefined, {}, sectionsRecord(spans, content), {\n root: null,\n yamlEnd: 0,\n bodyStart: 0,\n }),\n };\n }\n if (fence.kind === 'unclosed') return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n try {\n const root = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);\n const fields = jsValue(root);\n if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n }\n const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);\n const spans = headingSpans(content, bodyStart);\n const record = fields as Record<string, unknown>;\n return {\n ok: true,\n document: freezeDocument(\n content,\n declaredType(record),\n record,\n sectionsRecord(spans, content),\n {\n root,\n yamlEnd: fence.yamlEnd,\n bodyStart,\n },\n ),\n };\n } catch (error) {\n if (error instanceof YamlError)\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n throw error;\n }\n}\n\nfunction splice(content: string, start: number, end: number, insert: string): string {\n return content.slice(0, start) + insert + content.slice(end);\n}\n\nfunction applyField(document: Document, name: string, value: unknown, prior: unknown): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined || internal.root === null) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };\n }\n if (!equalValue(document.fields[name], prior)) {\n return { outcome: 'stale', document };\n }\n let nextContent: string;\n const existing = mapEntry(internal.root, name);\n if (existing !== undefined) {\n nextContent = splice(\n document.content,\n existing.value.start,\n existing.value.end,\n serializeJs(value),\n );\n } else {\n const nl = lineEnding(document.content);\n const line = `${serializeKey(name)}: ${serializeJs(value)}${nl}`;\n const before = document.content.slice(0, internal.yamlEnd);\n const prefix = before.endsWith('\\n') || before.endsWith('\\r\\n') ? '' : nl;\n nextContent = splice(document.content, internal.yamlEnd, internal.yamlEnd, `${prefix}${line}`);\n }\n const parsed = parse(nextContent);\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applySection(document: Document, name: string, value: string, prior: string): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const spans = headingSpans(document.content, internal.bodyStart);\n const span = spans.find((item) => item.name === name);\n if (span === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const current = document.content.slice(span.bodyStart, span.bodyEnd);\n if (current !== prior) return { outcome: 'stale', document };\n const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nexport function apply(document: Document, change: Change): ApplyResult {\n try {\n if (change.kind === 'field')\n return applyField(document, change.name, change.value, change.prior);\n return applySection(document, change.name, change.value, change.prior);\n } catch (error) {\n if (error instanceof YamlError) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };\n }\n throw error;\n }\n}\n\nexport function serialize(document: Document): string {\n return document.content;\n}\n"],"names":["headingSpans","sectionsRecord","refusal","bodyStartAfterYaml","equalValue","extractFrontmatter","jsValue","lineEnding","mapEntry","parseYamlMapping","serializeJs","serializeKey","YamlError","internals","WeakMap","refuse","file","rule","location","undefined","freezeDocument","content","type","fields","sections","internal","document","Object","freeze","set","declaredType","value","parse","fence","kind","spans","ok","root","yamlEnd","bodyStart","yamlStart","Array","isArray","record","error","splice","start","end","insert","slice","applyField","name","prior","get","outcome","nextContent","existing","nl","line","before","prefix","endsWith","parsed","applySection","span","find","item","current","bodyEnd","apply","change","serialize"],"mappings":"AAAA,SAASA,YAAY,EAAEC,cAAc,QAAQ,gBAAgB;AAC7D,SAASC,OAAO,QAAQ,cAAc;AAEtC,SACEC,kBAAkB,EAClBC,UAAU,EACVC,kBAAkB,EAClBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,EACZC,SAAS,QAEJ,YAAY;AAQnB,MAAMC,YAAY,IAAIC;AAEtB,SAASC,OAAOC,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AAS4D,OAAO5D,OAAO;IAAC;IACpE,OAAO;QAAEoD,SAAS;QAAW5B,UAAUoC,OAAOpC,QAAQ;IAAC;AACzD;AAEA,OAAO,SAAS2C,MAAM3C,QAAkB,EAAE4C,MAAc;IACtD,IAAI;QACF,IAAIA,OAAOpC,IAAI,KAAK,SAClB,OAAOgB,WAAWxB,UAAU4C,OAAOnB,IAAI,EAAEmB,OAAOvC,KAAK,EAAEuC,OAAOlB,KAAK;QACrE,OAAOW,aAAarC,UAAU4C,OAAOnB,IAAI,EAAEmB,OAAOvC,KAAK,EAAEuC,OAAOlB,KAAK;IACvE,EAAE,OAAOR,OAAO;QACd,IAAIA,iBAAiBhC,WAAW;YAC9B,OAAO;gBAAE0C,SAAS;gBAAUpD,SAASa,OAAO,IAAI,qBAAqBuD,OAAOnB,IAAI;YAAE;QACpF;QACA,MAAMP;IACR;AACF;AAEA,OAAO,SAAS2B,UAAU7C,QAAkB;IAC1C,OAAOA,SAASL,OAAO;AACzB"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/document.ts"],"sourcesContent":["import { hrefOccurrences } from './links.js';\nimport { classifyHref, hrefSuffix } from './paths.js';\nimport { headingSpans, sectionsRecord } from './sections.js';\nimport { refusal } from './refuse.js';\nimport type { ApplyResult, Change, Document, Link, ParseResult } from './types.js';\nimport {\n bodyStartAfterYaml,\n bodyStartOf,\n equalValue,\n extractFrontmatter,\n jsValue,\n lineEnding,\n mapEntry,\n parseYamlMapping,\n serializeJs,\n serializeKey,\n YamlError,\n type YamlMap,\n} from './yaml.js';\n\ntype Internal = {\n readonly root: YamlMap | null;\n readonly yamlEnd: number;\n readonly bodyStart: number;\n};\n\nconst internals = new WeakMap<Document, Internal>();\n\nfunction refuse(file: string, rule: string, location?: string) {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction freezeDocument(\n content: string,\n type: string | undefined,\n fields: Record<string, unknown>,\n preamble: string,\n sections: Record<string, string>,\n internal: Internal,\n): Document {\n const document: Document = Object.freeze({\n content,\n type,\n fields: Object.freeze(fields),\n preamble,\n sections: Object.freeze(sections),\n });\n internals.set(document, internal);\n return document;\n}\n\nfunction declaredType(fields: Record<string, unknown>): string | undefined {\n const value = fields.type;\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'string' || value === '') return undefined;\n return value;\n}\n\nexport function parse(content: string, file = ''): ParseResult {\n const fence = extractFrontmatter(content);\n if (fence.kind === 'none') {\n const spans = headingSpans(content, 0);\n return {\n ok: true,\n document: freezeDocument(\n content,\n undefined,\n {},\n content.slice(0, spans[0]?.headingStart),\n sectionsRecord(spans, content),\n {\n root: null,\n yamlEnd: 0,\n bodyStart: 0,\n },\n ),\n };\n }\n if (fence.kind === 'unclosed') return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n try {\n const root = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);\n const fields = jsValue(root);\n if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n }\n const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);\n const spans = headingSpans(content, bodyStart);\n const record = fields as Record<string, unknown>;\n return {\n ok: true,\n document: freezeDocument(\n content,\n declaredType(record),\n record,\n content.slice(bodyStart, spans[0]?.headingStart),\n sectionsRecord(spans, content),\n {\n root,\n yamlEnd: fence.yamlEnd,\n bodyStart,\n },\n ),\n };\n } catch (error) {\n if (error instanceof YamlError)\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n throw error;\n }\n}\n\nfunction splice(content: string, start: number, end: number, insert: string): string {\n return content.slice(0, start) + insert + content.slice(end);\n}\n\nfunction applyField(document: Document, name: string, value: unknown, prior: unknown): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined || internal.root === null) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };\n }\n if (!equalValue(document.fields[name], prior)) {\n return { outcome: 'stale', document };\n }\n let nextContent: string;\n const existing = mapEntry(internal.root, name);\n if (existing !== undefined) {\n nextContent = splice(\n document.content,\n existing.value.start,\n existing.value.end,\n serializeJs(value),\n );\n } else {\n const nl = lineEnding(document.content);\n const line = `${serializeKey(name)}: ${serializeJs(value)}${nl}`;\n const before = document.content.slice(0, internal.yamlEnd);\n const prefix = before.endsWith('\\n') || before.endsWith('\\r\\n') ? '' : nl;\n nextContent = splice(document.content, internal.yamlEnd, internal.yamlEnd, `${prefix}${line}`);\n }\n const parsed = parse(nextContent);\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applySection(document: Document, name: string, value: string, prior: string): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const spans = headingSpans(document.content, internal.bodyStart);\n const span = spans.find((item) => item.name === name);\n if (span === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const current = document.content.slice(span.bodyStart, span.bodyEnd);\n if (current !== prior) return { outcome: 'stale', document };\n const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applyPreamble(document: Document, value: string, prior: string): ApplyResult {\n if (document.preamble !== prior) return { outcome: 'stale', document };\n const start = bodyStartOf(document.content);\n const parsed = parse(splice(document.content, start, start + document.preamble.length, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction fitsBare(to: string): boolean {\n if (to === '' || to.startsWith('<')) return false;\n let depth = 0;\n for (const character of to) {\n if (/[\\s\\u0000-\\u001f\\u007f]/.test(character)) return false;\n if (character === '(') depth += 1;\n else if (character === ')') {\n if (depth === 0) return false;\n depth -= 1;\n }\n }\n return depth === 0;\n}\n\nfunction fitsBrackets(to: string): boolean {\n return to !== '' && !/[<>\\n\\r]/.test(to);\n}\n\nfunction destinationText(to: string, bracketed: boolean): string | null {\n if (fitsBare(to)) return bracketed && fitsBrackets(to) ? `<${to}>` : to;\n if (fitsBrackets(to)) return `<${to}>`;\n return null;\n}\n\nfunction applyLink(document: Document, href: string, to: string): ApplyResult {\n const content = document.content;\n const bodyStart = bodyStartOf(content);\n const matches = hrefOccurrences(content.slice(bodyStart)).filter(\n (occurrence) => occurrence.href === href,\n );\n if (matches.length === 0) return { outcome: 'stale', document };\n const written = to + hrefSuffix(href);\n let rewritten = '';\n let cursor = 0;\n for (const match of matches) {\n const text = destinationText(written, match.bracketed);\n if (text === null)\n return { outcome: 'refuse', refusal: refuse('', 'unwritable-link', written) };\n rewritten += content.slice(cursor, bodyStart + match.start);\n rewritten += text;\n cursor = bodyStart + match.end;\n }\n const parsed = parse(rewritten + content.slice(cursor));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nexport function links(document: Document, file: string): readonly Link[] {\n const found: Link[] = [];\n const seen = new Set<string>();\n for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))) {\n if (seen.has(occurrence.href)) continue;\n const resolved = classifyHref(file, occurrence.href);\n if (resolved.kind !== 'path') continue;\n seen.add(occurrence.href);\n found.push({ href: occurrence.href, target: resolved.path });\n }\n return found;\n}\n\nexport function apply(document: Document, change: Change): ApplyResult {\n if (change.kind === 'link') return applyLink(document, change.href, change.to);\n if (change.kind === 'preamble') return applyPreamble(document, change.value, change.prior);\n try {\n if (change.kind === 'field')\n return applyField(document, change.name, change.value, change.prior);\n return applySection(document, change.name, change.value, change.prior);\n } catch (error) {\n if (error instanceof YamlError) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };\n }\n throw error;\n }\n}\n\nexport function serialize(document: Document): string {\n return document.content;\n}\n"],"names":["hrefOccurrences","classifyHref","hrefSuffix","headingSpans","sectionsRecord","refusal","bodyStartAfterYaml","bodyStartOf","equalValue","extractFrontmatter","jsValue","lineEnding","mapEntry","parseYamlMapping","serializeJs","serializeKey","YamlError","internals","WeakMap","refuse","file","rule","location","undefined","freezeDocument","content","type","fields","preamble","sections","internal","document","Object","freeze","set","declaredType","value","parse","fence","kind","spans","ok","slice","headingStart","root","yamlEnd","bodyStart","yamlStart","Array","isArray","record","error","splice","start","end","insert","applyField","name","prior","get","outcome","nextContent","existing","nl","line","before","prefix","endsWith","parsed","applySection","span","find","item","current","bodyEnd","applyPreamble","length","fitsBare","to","startsWith","depth","character","test","fitsBrackets","destinationText","bracketed","applyLink","href","matches","filter","occurrence","written","rewritten","cursor","match","text","links","found","seen","Set","has","resolved","add","push","target","path","apply","change","serialize"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAC7C,SAASC,YAAY,EAAEC,UAAU,QAAQ,aAAa;AACtD,SAASC,YAAY,EAAEC,cAAc,QAAQ,gBAAgB;AAC7D,SAASC,OAAO,QAAQ,cAAc;AAEtC,SACEC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,EACZC,SAAS,QAEJ,YAAY;AAQnB,MAAMC,YAAY,IAAIC;AAEtB,SAASC,OAAOC,IAAY,EAAEC,IAAY,EAAEC,QAAiB;IAC3D,OAAOA,aAAaC,YAAYlB,QAAQe,MAAMC,QAAQhB,QAAQe,MAAMC,MAAM;QAAEC;IAAS;AACvF;AAEA,SAASE,eACPC,OAAe,EACfC,IAAwB,EACxBC,MAA+B,EAC/BC,QAAgB,EAChBC,QAAgC,EAChCC,QAAkB;IAElB,MAAMC,WAAqBC,OAAOC,MAAM,CAAC;QACvCR;QACAC;QACAC,QAAQK,OAAOC,MAAM,CAACN;QACtBC;QACAC,UAAUG,OAAOC,MAAM,CAACJ;IAC1B;IACAZ,UAAUiB,GAAG,CAACH,UAAUD;IACxB,OAAOC;AACT;AAEA,SAASI,aAAaR,M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C7E,IAAI6B,OAAOpE,IAAI,KAAK,YAAY,OAAOoC,cAAc5C,UAAU4E,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;IACzF,IAAI;QACF,IAAIiD,OAAOpE,IAAI,KAAK,SAClB,OAAOiB,WAAWzB,UAAU4E,OAAOlD,IAAI,EAAEkD,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;QACrE,OAAOW,aAAatC,UAAU4E,OAAOlD,IAAI,EAAEkD,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;IACvE,EAAE,OAAOP,OAAO;QACd,IAAIA,iBAAiBnC,WAAW;YAC9B,OAAO;gBAAE4C,SAAS;gBAAUvD,SAASc,OAAO,IAAI,qBAAqBwF,OAAOlD,IAAI;YAAE;QACpF;QACA,MAAMN;IACR;AACF;AAEA,OAAO,SAASyD,UAAU7E,QAAkB;IAC1C,OAAOA,SAASN,OAAO;AACzB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { apply, parse, serialize } from './document.js';
|
|
1
|
+
export { apply, links, parse, serialize } from './document.js';
|
|
2
2
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
3
|
-
export type { ApplyResult, Change, Document, Library, ParseResult, Refusal, Validation, ValidationContext, } from './types.js';
|
|
3
|
+
export type { ApplyResult, Change, Document, Library, Link, ParseResult, Refusal, Validation, ValidationContext, } from './types.js';
|
|
4
4
|
export { validate } from './validate.js';
|
|
5
5
|
export { VERSION } from './version.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/index.ts"],"sourcesContent":["export { apply, parse, serialize } from './document.js';\nexport { MARKDOWN_SYNTAX_PROFILE } from './profile.js';\nexport type {\n ApplyResult,\n Change,\n Document,\n Library,\n ParseResult,\n Refusal,\n Validation,\n ValidationContext,\n} from './types.js';\nexport { validate } from './validate.js';\nexport { VERSION } from './version.js';\n"],"names":["apply","parse","serialize","MARKDOWN_SYNTAX_PROFILE","validate","VERSION"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/index.ts"],"sourcesContent":["export { apply, links, parse, serialize } from './document.js';\nexport { MARKDOWN_SYNTAX_PROFILE } from './profile.js';\nexport type {\n ApplyResult,\n Change,\n Document,\n Library,\n Link,\n ParseResult,\n Refusal,\n Validation,\n ValidationContext,\n} from './types.js';\nexport { validate } from './validate.js';\nexport { VERSION } from './version.js';\n"],"names":["apply","links","parse","serialize","MARKDOWN_SYNTAX_PROFILE","validate","VERSION"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC/D,SAASC,uBAAuB,QAAQ,eAAe;AAYvD,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,OAAO,QAAQ,eAAe"}
|
package/dist/links.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type HrefOccurrence = {
|
|
2
|
+
readonly href: string;
|
|
3
|
+
readonly start: number;
|
|
4
|
+
readonly end: number;
|
|
5
|
+
readonly bracketed: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function hrefOccurrences(body: string): readonly HrefOccurrence[];
|
|
2
8
|
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AA4VA,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,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CA2BvE"}
|