@agentshouse/mdmodel 0.1.0-c896b3d9398b1 → 0.1.0-cbce4f1da228f
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 +137 -133
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +33 -26
- package/dist/condition.d.ts +1 -1
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +16 -13
- package/dist/definition.d.ts +14 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +217 -25
- package/dist/divide.d.ts.map +1 -1
- package/dist/divide.js +18 -8
- package/dist/document.d.ts +4 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +105 -68
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +7 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/links.d.ts +2 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +23 -12
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +92 -12
- package/dist/project.d.ts +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +32 -9
- package/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/schema.js +2 -2
- package/dist/types.d.ts +25 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +6 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +163 -111
- package/dist/yaml.d.ts +7 -3
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +72 -43
- package/fixtures/README.md +1 -1
- package/package.json +4 -2
package/dist/document.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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';
|
|
7
|
-
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
|
|
7
|
+
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, frontmatterValue, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
|
|
8
8
|
const internals = new WeakMap();
|
|
9
9
|
function refuse(file, rule, location) {
|
|
10
10
|
return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });
|
|
@@ -28,19 +28,10 @@ function declaredType(fields) {
|
|
|
28
28
|
return undefined;
|
|
29
29
|
return value;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
function opened(content, file) {
|
|
32
32
|
const fence = extractFrontmatter(content);
|
|
33
|
-
if (fence.kind === 'none')
|
|
34
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -78,10 +83,18 @@ function applyField(document, name, value, prior) {
|
|
|
78
83
|
if (!equalValue(document.fields[name], prior)) {
|
|
79
84
|
return { outcome: 'stale', document };
|
|
80
85
|
}
|
|
86
|
+
if (!frontmatterValue(value)) {
|
|
87
|
+
return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };
|
|
88
|
+
}
|
|
81
89
|
let nextContent;
|
|
82
90
|
const existing = mapEntry(internal.root, name);
|
|
83
91
|
if (existing !== undefined) {
|
|
84
|
-
|
|
92
|
+
const held = existing.value;
|
|
93
|
+
const inline = held.start > existing.after &&
|
|
94
|
+
!/[\r\n]/.test(document.content.slice(existing.after, held.start));
|
|
95
|
+
nextContent = inline
|
|
96
|
+
? splice(document.content, held.start, held.end, serializeJs(value))
|
|
97
|
+
: splice(document.content, existing.after, held.end, ` ${serializeJs(value)}`);
|
|
85
98
|
}
|
|
86
99
|
else if (document.content[internal.root.start] === '{') {
|
|
87
100
|
nextContent = splice(document.content, internal.root.end - 1, internal.root.end - 1, `${internal.root.entries.length === 0 ? '' : ', '}${serializeKey(name)}: ${serializeJs(value)}`);
|
|
@@ -111,16 +124,30 @@ function applySection(document, name, value, prior) {
|
|
|
111
124
|
const current = document.content.slice(span.bodyStart, span.bodyEnd);
|
|
112
125
|
if (current !== prior)
|
|
113
126
|
return { outcome: 'stale', document };
|
|
114
|
-
|
|
115
|
-
if (!parsed.ok)
|
|
116
|
-
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
117
|
-
return { outcome: 'applied', document: parsed.document };
|
|
127
|
+
return replaced(document, internal.bodyStart, span.bodyStart, span.bodyEnd, value);
|
|
118
128
|
}
|
|
119
129
|
function applyPreamble(document, value, prior) {
|
|
120
130
|
if (document.preamble !== prior)
|
|
121
131
|
return { outcome: 'stale', document };
|
|
122
132
|
const start = bodyStartOf(document.content);
|
|
123
|
-
|
|
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);
|
|
124
151
|
if (!parsed.ok)
|
|
125
152
|
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
126
153
|
return { outcome: 'applied', document: parsed.document };
|
|
@@ -152,35 +179,38 @@ function destinationText(to, bracketed) {
|
|
|
152
179
|
return `<${to}>`;
|
|
153
180
|
return null;
|
|
154
181
|
}
|
|
155
|
-
function relinked(content, bodyStart,
|
|
156
|
-
const
|
|
182
|
+
function relinked(content, bodyStart, occurrences, written) {
|
|
183
|
+
const unwritable = new Set();
|
|
184
|
+
for (const match of occurrences) {
|
|
185
|
+
const to = written.get(match.href);
|
|
186
|
+
if (to !== undefined && destinationText(to, match.bracketed) === null)
|
|
187
|
+
unwritable.add(match.href);
|
|
188
|
+
}
|
|
189
|
+
for (const [href, to] of written) {
|
|
190
|
+
if (unwritable.has(href))
|
|
191
|
+
return refuse('', 'unwritable-link', to);
|
|
192
|
+
}
|
|
157
193
|
let rewritten = '';
|
|
158
194
|
let cursor = 0;
|
|
159
|
-
for (const match of
|
|
160
|
-
|
|
195
|
+
for (const match of occurrences) {
|
|
196
|
+
const to = written.get(match.href);
|
|
197
|
+
if (to === undefined)
|
|
161
198
|
continue;
|
|
162
|
-
const text = destinationText(written, match.bracketed);
|
|
163
|
-
if (text === null)
|
|
164
|
-
return refuse('', 'unwritable-link', written);
|
|
165
199
|
rewritten += content.slice(cursor, bodyStart + match.start);
|
|
166
|
-
rewritten +=
|
|
200
|
+
rewritten += destinationText(to, match.bracketed);
|
|
167
201
|
cursor = bodyStart + match.end;
|
|
168
202
|
}
|
|
169
203
|
return rewritten + content.slice(cursor);
|
|
170
204
|
}
|
|
171
205
|
function shellRelinked(content, bodyStart, file, handle) {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
for (const href of
|
|
206
|
+
const occurrences = hrefOccurrences(content.slice(bodyStart));
|
|
207
|
+
const written = new Map();
|
|
208
|
+
for (const href of new Set(occurrences.map((occurrence) => occurrence.href))) {
|
|
175
209
|
const path = shellTarget(href, handle);
|
|
176
|
-
if (path
|
|
177
|
-
|
|
178
|
-
const text = relinked(held, bodyStart, href, relative(file, path));
|
|
179
|
-
if (typeof text !== 'string')
|
|
180
|
-
return text;
|
|
181
|
-
held = text;
|
|
210
|
+
if (path !== null)
|
|
211
|
+
written.set(href, retarget(href, relative(file, path)));
|
|
182
212
|
}
|
|
183
|
-
return
|
|
213
|
+
return relinked(content, bodyStart, occurrences, written);
|
|
184
214
|
}
|
|
185
215
|
function reparsed(document, content) {
|
|
186
216
|
if (typeof content !== 'string')
|
|
@@ -195,9 +225,10 @@ function reparsed(document, content) {
|
|
|
195
225
|
function applyLink(document, href, to) {
|
|
196
226
|
const content = document.content;
|
|
197
227
|
const bodyStart = bodyStartOf(content);
|
|
198
|
-
|
|
228
|
+
const occurrences = hrefOccurrences(content.slice(bodyStart));
|
|
229
|
+
if (!occurrences.some((occurrence) => occurrence.href === href))
|
|
199
230
|
return { outcome: 'stale', document };
|
|
200
|
-
return reparsed(document, relinked(content, bodyStart, href, to));
|
|
231
|
+
return reparsed(document, relinked(content, bodyStart, occurrences, new Map([[href, retarget(href, to)]])));
|
|
201
232
|
}
|
|
202
233
|
function nodeAt(root, pointer) {
|
|
203
234
|
let node = root;
|
|
@@ -248,7 +279,7 @@ export function relativizeBody(body, file, handle) {
|
|
|
248
279
|
const relinkedBody = shellRelinked(body, 0, file, handle);
|
|
249
280
|
if (typeof relinkedBody !== 'string')
|
|
250
281
|
return { outcome: 'refuse', refusal: relinkedBody };
|
|
251
|
-
const elsewhere = hrefOccurrences(relinkedBody).find(({ href }) => href
|
|
282
|
+
const elsewhere = hrefOccurrences(relinkedBody).find(({ href }) => destinationPath(href)?.startsWith(SHELL_ROOMS) === true);
|
|
252
283
|
if (elsewhere !== undefined)
|
|
253
284
|
return { outcome: 'refuse', refusal: refuse(file, 'unresolved-link', elsewhere.href) };
|
|
254
285
|
return { outcome: 'applied', body: relinkedBody };
|
|
@@ -270,23 +301,33 @@ export function relinkBody(body, file, moves) {
|
|
|
270
301
|
}
|
|
271
302
|
return { outcome: 'applied', body: rewritten + body.slice(cursor) };
|
|
272
303
|
}
|
|
304
|
+
function occurrencesIn(text, file, offset) {
|
|
305
|
+
const found = [];
|
|
306
|
+
for (const occurrence of hrefOccurrences(text)) {
|
|
307
|
+
const resolved = target(file, occurrence.href);
|
|
308
|
+
if (resolved !== null)
|
|
309
|
+
found.push({ href: occurrence.href, target: resolved, start: offset + occurrence.start });
|
|
310
|
+
}
|
|
311
|
+
return found;
|
|
312
|
+
}
|
|
273
313
|
function linksIn(text, file) {
|
|
274
314
|
const found = [];
|
|
275
315
|
const seen = new Set();
|
|
276
|
-
for (const occurrence of
|
|
316
|
+
for (const occurrence of occurrencesIn(text, file, 0)) {
|
|
277
317
|
if (seen.has(occurrence.href))
|
|
278
318
|
continue;
|
|
279
|
-
const resolved = target(file, occurrence.href);
|
|
280
|
-
if (resolved === null)
|
|
281
|
-
continue;
|
|
282
319
|
seen.add(occurrence.href);
|
|
283
|
-
found.push({ href: occurrence.href, target:
|
|
320
|
+
found.push({ href: occurrence.href, target: occurrence.target });
|
|
284
321
|
}
|
|
285
322
|
return found;
|
|
286
323
|
}
|
|
287
324
|
export function links(document, file) {
|
|
288
325
|
return linksIn(document.content.slice(bodyStartOf(document.content)), file);
|
|
289
326
|
}
|
|
327
|
+
export function linkOccurrences(document, file) {
|
|
328
|
+
const bodyStart = bodyStartOf(document.content);
|
|
329
|
+
return occurrencesIn(document.content.slice(bodyStart), file, bodyStart);
|
|
330
|
+
}
|
|
290
331
|
export function bodyLinks(body, file) {
|
|
291
332
|
return linksIn(body, file);
|
|
292
333
|
}
|
|
@@ -297,21 +338,17 @@ export function apply(document, change) {
|
|
|
297
338
|
return applyReference(document, change.pointer, change.value, change.prior);
|
|
298
339
|
if (change.kind === 'preamble')
|
|
299
340
|
return applyPreamble(document, change.value, change.prior);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return applySection(document, change.name, change.value, change.prior);
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
if (error instanceof YamlError) {
|
|
307
|
-
return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };
|
|
308
|
-
}
|
|
309
|
-
throw error;
|
|
310
|
-
}
|
|
341
|
+
if (change.kind === 'field')
|
|
342
|
+
return applyField(document, change.name, change.value, change.prior);
|
|
343
|
+
return applySection(document, change.name, change.value, change.prior);
|
|
311
344
|
}
|
|
312
345
|
export function serialize(document) {
|
|
313
346
|
return document.content;
|
|
314
347
|
}
|
|
348
|
+
export function fieldStart(document, pointer) {
|
|
349
|
+
const root = internals.get(document)?.root;
|
|
350
|
+
return root === null || root === undefined ? undefined : nodeAt(root, pointer)?.start;
|
|
351
|
+
}
|
|
315
352
|
export function frontmatter(document) {
|
|
316
353
|
return internals.get(document)?.root ?? null;
|
|
317
354
|
}
|
package/dist/fields.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export declare const TYPE_FIELD = "type";
|
|
1
2
|
export declare const MEMBER_FIELD = "member";
|
|
2
3
|
export declare const SITE_FIELD = "site";
|
|
3
4
|
export declare const RECEIVED_FIELD = "received";
|
|
5
|
+
export declare const HOUSE_FIELDS: readonly string[];
|
|
4
6
|
//# sourceMappingURL=fields.d.ts.map
|
package/dist/fields.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAKzC,CAAC"}
|
package/dist/fields.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
export { dated, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
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';
|
|
5
|
-
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
6
|
+
export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
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, validating, verify, } from './validate.js';
|
|
14
16
|
export { VERSION } from './version.js';
|
|
17
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
|
18
|
+
export type { FrontmatterValue } from './yaml.js';
|
|
15
19
|
//# 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,EACL,KAAK,EACL,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,KAAK,EACL,SAAS,EACT,KAAK,EACL,KAAK,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
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,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,eA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CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
export { dated, factKind, facts, fires, holds, instant, itemFires, pointed, prosePaths, WRITE_DOORS, } from './condition.js';
|
|
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 { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
4
|
+
export { apply, bodyLinks, fieldStart, linkOccurrences, links, parse, parseFrontmatter, relativize, relativizeBody, relinkBody, serialize, } from './document.js';
|
|
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, validating, verify, } from './validate.js';
|
|
11
12
|
export { VERSION } from './version.js';
|
|
13
|
+
export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
|
package/dist/links.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare function escapes(text: string, index: number): boolean;
|
|
2
|
+
export declare function spanCursor(spans: readonly (readonly [number, number])[]): (index: number) => number | undefined;
|
|
1
3
|
export type HrefOccurrence = {
|
|
2
4
|
readonly href: string;
|
|
3
5
|
readonly start: number;
|
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":"AAkhBA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D;AAyLD,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAC5C,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAOvC;AAED,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,MAAM,CAAC,CAAC,EAAE,CAe/E;AAYD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA6DzD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAIvE"}
|
package/dist/links.js
CHANGED
|
@@ -155,10 +155,13 @@ function fenceSpan(text, line, open) {
|
|
|
155
155
|
}
|
|
156
156
|
return text.length;
|
|
157
157
|
}
|
|
158
|
-
function skipInlineCode(text, index, joins) {
|
|
158
|
+
function skipInlineCode(text, index, joins, unclosed) {
|
|
159
159
|
let ticks = 0;
|
|
160
160
|
while (text[index + ticks] === '`')
|
|
161
161
|
ticks += 1;
|
|
162
|
+
if (index < unclosed.stop && (unclosed.runs.get(ticks) ?? -1) <= index)
|
|
163
|
+
return index + ticks;
|
|
164
|
+
const runs = new Map();
|
|
162
165
|
let i = index + ticks;
|
|
163
166
|
while (i < text.length) {
|
|
164
167
|
const ch = text[i];
|
|
@@ -168,6 +171,7 @@ function skipInlineCode(text, index, joins) {
|
|
|
168
171
|
run += 1;
|
|
169
172
|
if (run === ticks)
|
|
170
173
|
return i + run;
|
|
174
|
+
runs.set(run, i);
|
|
171
175
|
i += run;
|
|
172
176
|
continue;
|
|
173
177
|
}
|
|
@@ -177,6 +181,8 @@ function skipInlineCode(text, index, joins) {
|
|
|
177
181
|
break;
|
|
178
182
|
i += 1;
|
|
179
183
|
}
|
|
184
|
+
unclosed.stop = i;
|
|
185
|
+
unclosed.runs = runs;
|
|
180
186
|
return index + ticks;
|
|
181
187
|
}
|
|
182
188
|
function skipLinkSpace(text, start) {
|
|
@@ -504,7 +510,7 @@ function structure(text) {
|
|
|
504
510
|
}
|
|
505
511
|
return { joins, raw };
|
|
506
512
|
}
|
|
507
|
-
function escapes(text, index) {
|
|
513
|
+
export function escapes(text, index) {
|
|
508
514
|
return text[index] === '\\' && PUNCTUATION.test(text[index + 1] ?? '');
|
|
509
515
|
}
|
|
510
516
|
function referenceEnd(text, start, joins) {
|
|
@@ -641,12 +647,13 @@ function endsBlock(content) {
|
|
|
641
647
|
}
|
|
642
648
|
function scanBlocks(text) {
|
|
643
649
|
const { joins, raw } = structure(text);
|
|
650
|
+
const rawEnd = spanCursor(raw);
|
|
644
651
|
const definitions = new Map();
|
|
645
652
|
const blocks = [];
|
|
646
653
|
let fresh = 0;
|
|
647
654
|
let i = 0;
|
|
648
655
|
while (i < text.length) {
|
|
649
|
-
const skip =
|
|
656
|
+
const skip = rawEnd(i);
|
|
650
657
|
if (skip !== undefined) {
|
|
651
658
|
i = skip;
|
|
652
659
|
continue;
|
|
@@ -667,12 +674,14 @@ function scanBlocks(text) {
|
|
|
667
674
|
}
|
|
668
675
|
return { raw, definitions, blocks, joins };
|
|
669
676
|
}
|
|
670
|
-
function
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
677
|
+
export function spanCursor(spans) {
|
|
678
|
+
let next = 0;
|
|
679
|
+
return (index) => {
|
|
680
|
+
while (next < spans.length && spans[next][1] <= index)
|
|
681
|
+
next += 1;
|
|
682
|
+
const span = spans[next];
|
|
683
|
+
return span !== undefined && span[0] <= index ? span[1] : undefined;
|
|
684
|
+
};
|
|
676
685
|
}
|
|
677
686
|
export function fenceSpans(text) {
|
|
678
687
|
const fences = [];
|
|
@@ -703,13 +712,15 @@ function paragraphEnd(text, from, joins) {
|
|
|
703
712
|
}
|
|
704
713
|
export function linkInventory(body) {
|
|
705
714
|
const { raw, definitions, blocks, joins } = scanBlocks(body);
|
|
706
|
-
const
|
|
715
|
+
const rawEnd = spanCursor(raw);
|
|
716
|
+
const blockEnd = spanCursor(blocks.map((block) => [block.start, block.end]));
|
|
707
717
|
const uses = [];
|
|
708
718
|
const openers = [];
|
|
719
|
+
const unclosed = { stop: 0, runs: new Map() };
|
|
709
720
|
let paragraph = { start: 0, end: -1, text: '' };
|
|
710
721
|
let i = 0;
|
|
711
722
|
while (i < body.length) {
|
|
712
|
-
const skipEnd =
|
|
723
|
+
const skipEnd = rawEnd(i) ?? blockEnd(i);
|
|
713
724
|
if (skipEnd !== undefined) {
|
|
714
725
|
openers.length = 0;
|
|
715
726
|
i = skipEnd;
|
|
@@ -721,7 +732,7 @@ export function linkInventory(body) {
|
|
|
721
732
|
continue;
|
|
722
733
|
}
|
|
723
734
|
if (ch === '`') {
|
|
724
|
-
i = skipInlineCode(body, i, joins);
|
|
735
|
+
i = skipInlineCode(body, i, joins, unclosed);
|
|
725
736
|
continue;
|
|
726
737
|
}
|
|
727
738
|
if (ch === '<') {
|
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
|
} | {
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAIA,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;AAoDD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAW3D;AAgBD,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,CASzE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvE"}
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { decodeNamedCharacterReference } from 'decode-named-character-reference';
|
|
2
|
+
import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
|
|
3
|
+
import { escapes } from './links.js';
|
|
1
4
|
export function dirname(path) {
|
|
2
5
|
const index = path.lastIndexOf('/');
|
|
3
6
|
return index === -1 ? '' : path.slice(0, index);
|
|
@@ -22,18 +25,95 @@ export function normalize(path) {
|
|
|
22
25
|
}
|
|
23
26
|
return parts.join('/');
|
|
24
27
|
}
|
|
28
|
+
const REFERENCE = /&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z][A-Za-z0-9]{0,31}));/y;
|
|
29
|
+
const PERCENT = /^%[0-9a-fA-F]{2}/;
|
|
30
|
+
function referenceAt(text, at) {
|
|
31
|
+
REFERENCE.lastIndex = at;
|
|
32
|
+
const match = REFERENCE.exec(text);
|
|
33
|
+
if (match === null)
|
|
34
|
+
return null;
|
|
35
|
+
const [whole, hex, decimal, name] = match;
|
|
36
|
+
const end = at + whole.length;
|
|
37
|
+
if (name !== undefined) {
|
|
38
|
+
const decoded = decodeNamedCharacterReference(name);
|
|
39
|
+
return decoded === false ? null : { text: decoded, end };
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
text: decodeNumericCharacterReference(hex ?? decimal, hex === undefined ? 10 : 16),
|
|
43
|
+
end,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function unescaped(written) {
|
|
47
|
+
let base = '';
|
|
48
|
+
let i = 0;
|
|
49
|
+
while (i < written.length) {
|
|
50
|
+
const escaped = escapes(written, i);
|
|
51
|
+
const reference = escaped || written[i] !== '&' ? null : referenceAt(written, i);
|
|
52
|
+
const text = escaped ? written[i + 1] : (reference?.text ?? written[i]);
|
|
53
|
+
if (text.startsWith('?') || text.startsWith('#'))
|
|
54
|
+
return { base, suffix: i };
|
|
55
|
+
base += text;
|
|
56
|
+
i = escaped ? i + 2 : (reference?.end ?? i + 1);
|
|
57
|
+
}
|
|
58
|
+
return { base, suffix: written.length };
|
|
59
|
+
}
|
|
60
|
+
function located(href) {
|
|
61
|
+
const written = href.trim();
|
|
62
|
+
const { base, suffix } = unescaped(written);
|
|
63
|
+
const url = base.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, '');
|
|
64
|
+
return { base: suffix === written.length ? url.replace(/[\u0000-\u0020]+$/, '') : url, suffix };
|
|
65
|
+
}
|
|
66
|
+
const ENCODED = /(?:%[0-9a-fA-F]{2})+/g;
|
|
67
|
+
function decodedRun(run) {
|
|
68
|
+
try {
|
|
69
|
+
return decodeURIComponent(run);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function destinationPath(href) {
|
|
76
|
+
const base = located(href).base;
|
|
77
|
+
let path = '';
|
|
78
|
+
let cursor = 0;
|
|
79
|
+
for (const match of base.matchAll(ENCODED)) {
|
|
80
|
+
const decoded = decodedRun(match[0]);
|
|
81
|
+
if (decoded === null)
|
|
82
|
+
return null;
|
|
83
|
+
path += base.slice(cursor, match.index) + decoded;
|
|
84
|
+
cursor = match.index + match[0].length;
|
|
85
|
+
}
|
|
86
|
+
return path + base.slice(cursor);
|
|
87
|
+
}
|
|
88
|
+
function written(path) {
|
|
89
|
+
let text = '';
|
|
90
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
91
|
+
const char = path[i];
|
|
92
|
+
if (char === '?' || char === '#' || char < ' ')
|
|
93
|
+
text += encodeURIComponent(char);
|
|
94
|
+
else if (char === ' ' && (i === 0 || i === path.length - 1))
|
|
95
|
+
text += '%20';
|
|
96
|
+
else if (char === '%' && PERCENT.test(path.slice(i)))
|
|
97
|
+
text += '%25';
|
|
98
|
+
else if (escapes(path, i))
|
|
99
|
+
text += '%5C';
|
|
100
|
+
else if (char === '&' && referenceAt(path, i) !== null)
|
|
101
|
+
text += '%26';
|
|
102
|
+
else
|
|
103
|
+
text += char;
|
|
104
|
+
}
|
|
105
|
+
return text;
|
|
106
|
+
}
|
|
25
107
|
export function classifyHref(from, href) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
108
|
+
const base = located(href).base;
|
|
109
|
+
if (base === '')
|
|
28
110
|
return { kind: 'skip' };
|
|
29
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(
|
|
111
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(base))
|
|
30
112
|
return { kind: 'skip' };
|
|
31
|
-
|
|
113
|
+
const path = destinationPath(href);
|
|
114
|
+
if (path === null || path.startsWith('/'))
|
|
32
115
|
return { kind: 'invalid' };
|
|
33
|
-
const
|
|
34
|
-
if (bare === '')
|
|
35
|
-
return { kind: 'skip' };
|
|
36
|
-
const resolved = normalize(join(dirname(from), bare));
|
|
116
|
+
const resolved = normalize(join(dirname(from), path));
|
|
37
117
|
if (resolved === null || resolved === '')
|
|
38
118
|
return { kind: 'invalid' };
|
|
39
119
|
return { kind: 'path', path: resolved };
|
|
@@ -44,8 +124,7 @@ export function target(from, href) {
|
|
|
44
124
|
}
|
|
45
125
|
export function retarget(href, to) {
|
|
46
126
|
const trimmed = href.trim();
|
|
47
|
-
|
|
48
|
-
return match === null ? to : to + trimmed.slice(match.index);
|
|
127
|
+
return written(to) + trimmed.slice(unescaped(trimmed).suffix);
|
|
49
128
|
}
|
|
50
129
|
export function relative(from, target) {
|
|
51
130
|
const base = dirname(from)
|
|
@@ -62,8 +141,9 @@ export function relative(from, target) {
|
|
|
62
141
|
export const SHELL_ROOMS = '/rooms/';
|
|
63
142
|
export function shellTarget(href, handle) {
|
|
64
143
|
const prefix = `${SHELL_ROOMS}${handle}/`;
|
|
65
|
-
|
|
144
|
+
const decoded = destinationPath(href);
|
|
145
|
+
if (decoded === null || !decoded.startsWith(prefix))
|
|
66
146
|
return null;
|
|
67
|
-
const path = normalize(
|
|
147
|
+
const path = normalize(decoded.slice(prefix.length));
|
|
68
148
|
return path === null || path === '' ? null : path;
|
|
69
149
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type InputResult = {
|
|
|
15
15
|
readonly ok: false;
|
|
16
16
|
readonly refusal: Refusal;
|
|
17
17
|
};
|
|
18
|
+
export declare function firstEditFrom(edits: readonly Edit[], start: number): number;
|
|
18
19
|
export declare function rangeText(content: string, range: Extent, edits: readonly Edit[]): string;
|
|
19
20
|
export declare function projectionInput(document: Document, file: string, context: ProjectionContext): InputResult;
|
|
20
21
|
export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
|
package/dist/project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,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