@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/definition.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
1
|
+
import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
2
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
3
3
|
export const JSON_TYPES = [
|
|
4
4
|
'string',
|
|
@@ -12,11 +12,23 @@ export const JSON_TYPES = [
|
|
|
12
12
|
export const BUILT_IN_TYPE = 'any';
|
|
13
13
|
export const ATTACHMENT = 'attachment';
|
|
14
14
|
const SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean']);
|
|
15
|
+
const COMPOSITES = ['array', 'object'];
|
|
16
|
+
const ANNOTATIONS = new Set([
|
|
17
|
+
'$comment',
|
|
18
|
+
'title',
|
|
19
|
+
'description',
|
|
20
|
+
'default',
|
|
21
|
+
'examples',
|
|
22
|
+
'deprecated',
|
|
23
|
+
'readOnly',
|
|
24
|
+
'writeOnly',
|
|
25
|
+
]);
|
|
26
|
+
const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
|
|
15
27
|
const DEFS_REFERENCE = '#/$defs/';
|
|
16
28
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
17
29
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
18
30
|
const HOUSE_KEYS = {
|
|
19
|
-
|
|
31
|
+
[TYPE_FIELD]: { prose: false },
|
|
20
32
|
[SITE_FIELD]: { prose: false },
|
|
21
33
|
[RECEIVED_FIELD]: { prose: false },
|
|
22
34
|
};
|
|
@@ -270,24 +282,43 @@ function united(left, right) {
|
|
|
270
282
|
return undefined;
|
|
271
283
|
return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
|
|
272
284
|
}
|
|
285
|
+
function both(left, right) {
|
|
286
|
+
return left !== undefined && right !== undefined ? joined(left, right) : undefined;
|
|
287
|
+
}
|
|
273
288
|
function joined(left, right) {
|
|
274
289
|
const type = left.type === right.type ? left.type : undefined;
|
|
275
290
|
const format = left.format === right.format ? left.format : undefined;
|
|
276
291
|
const values = united(left.values, right.values);
|
|
277
292
|
const reference = united(left.reference, right.reference);
|
|
278
|
-
const items = left.items
|
|
279
|
-
|
|
280
|
-
|
|
293
|
+
const items = both(left.items, right.items);
|
|
294
|
+
const prefix = left.prefix === undefined && right.prefix === undefined
|
|
295
|
+
? undefined
|
|
296
|
+
: Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
|
|
297
|
+
const properties = Object.create(null);
|
|
298
|
+
for (const [name, facts] of Object.entries(left.properties ?? {})) {
|
|
299
|
+
const shared = both(facts, right.properties?.[name]);
|
|
300
|
+
if (shared !== undefined)
|
|
301
|
+
properties[name] = shared;
|
|
302
|
+
}
|
|
303
|
+
const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
|
|
304
|
+
const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
|
|
305
|
+
return shared === undefined ? [] : [{ pattern, facts: shared }];
|
|
306
|
+
});
|
|
307
|
+
const additional = both(left.additional, right.additional);
|
|
281
308
|
return {
|
|
282
309
|
...(type === undefined ? {} : { type }),
|
|
283
310
|
...(format === undefined ? {} : { format }),
|
|
284
311
|
...(values === undefined ? {} : { values }),
|
|
285
312
|
...(reference === undefined ? {} : { reference }),
|
|
286
313
|
prose: left.prose && right.prose,
|
|
314
|
+
...(prefix === undefined ? {} : { prefix }),
|
|
287
315
|
...(items === undefined ? {} : { items }),
|
|
316
|
+
...(Object.keys(properties).length === 0 ? {} : { properties }),
|
|
317
|
+
...(patterns.length === 0 ? {} : { patterns }),
|
|
318
|
+
...(additional === undefined ? {} : { additional }),
|
|
288
319
|
};
|
|
289
320
|
}
|
|
290
|
-
function propertiesOf(held, defs, ancestry) {
|
|
321
|
+
function propertiesOf(held, variants, defs, ancestry) {
|
|
291
322
|
const declared = new Map();
|
|
292
323
|
for (const node of held) {
|
|
293
324
|
if (!isRecord(node.properties))
|
|
@@ -298,46 +329,87 @@ function propertiesOf(held, defs, ancestry) {
|
|
|
298
329
|
const properties = Object.create(null);
|
|
299
330
|
for (const [name, schemas] of declared)
|
|
300
331
|
properties[name] = factsOf(schemas, defs, ancestry);
|
|
301
|
-
const
|
|
302
|
-
for (const branch of
|
|
303
|
-
for (const [name, facts] of Object.entries(
|
|
332
|
+
const conditional = Object.create(null);
|
|
333
|
+
for (const branch of variants.values()) {
|
|
334
|
+
for (const [name, facts] of Object.entries(branch.properties ?? {})) {
|
|
304
335
|
if (Object.hasOwn(properties, name))
|
|
305
336
|
continue;
|
|
306
|
-
|
|
337
|
+
conditional[name] = Object.hasOwn(conditional, name)
|
|
338
|
+
? joined(conditional[name], facts)
|
|
339
|
+
: facts;
|
|
307
340
|
}
|
|
308
341
|
}
|
|
309
|
-
for (const [name, facts] of Object.entries(
|
|
342
|
+
for (const [name, facts] of Object.entries(conditional))
|
|
310
343
|
properties[name] = { ...facts, conditional: true };
|
|
311
344
|
return Object.keys(properties).length === 0 ? undefined : properties;
|
|
312
345
|
}
|
|
346
|
+
function nullOnly(facts) {
|
|
347
|
+
return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
|
|
348
|
+
}
|
|
349
|
+
function alternativesOf(held, variants) {
|
|
350
|
+
return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
|
|
351
|
+
if (!Array.isArray(branches))
|
|
352
|
+
return [];
|
|
353
|
+
const kept = branches
|
|
354
|
+
.flatMap((branch) => {
|
|
355
|
+
const facts = isRecord(branch) ? variants.get(branch) : undefined;
|
|
356
|
+
return facts === undefined ? [] : [facts];
|
|
357
|
+
})
|
|
358
|
+
.filter((facts) => !nullOnly(facts));
|
|
359
|
+
return kept.length === 0 ? [] : [kept];
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
function inheritedOf(held) {
|
|
363
|
+
return held.flatMap((node) => {
|
|
364
|
+
const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
|
|
365
|
+
return Object.keys(kept).length === 0 ? [] : [kept];
|
|
366
|
+
});
|
|
367
|
+
}
|
|
313
368
|
function factsOf(nodes, defs, ancestry) {
|
|
314
369
|
const { held, ancestry: reached } = conjoined(nodes, defs, ancestry);
|
|
315
|
-
const
|
|
370
|
+
const inherited = inheritedOf(held);
|
|
371
|
+
const variants = new Map(held
|
|
372
|
+
.flatMap(variantsOf)
|
|
373
|
+
.map((branch) => [branch, factsOf([branch, ...inherited], defs, reached)]));
|
|
374
|
+
const unions = alternativesOf(held, variants);
|
|
375
|
+
const alternatives = unions.map((kept) => kept.reduce(joined));
|
|
376
|
+
const listed = [
|
|
377
|
+
...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
|
|
378
|
+
...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
|
|
379
|
+
];
|
|
316
380
|
const values = listed.length === 0
|
|
317
381
|
? undefined
|
|
318
382
|
: listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
|
|
319
383
|
const type = firstOf(held, (node) => singleType(node.type)) ??
|
|
320
|
-
(values === undefined ? undefined : sharedType(values))
|
|
384
|
+
(values === undefined ? undefined : sharedType(values)) ??
|
|
385
|
+
alternatives.find((facts) => facts.type !== undefined)?.type;
|
|
321
386
|
const reference = firstOf(held, (node) => typeof node.reference === 'string'
|
|
322
387
|
? [node.reference]
|
|
323
388
|
: Array.isArray(node.reference)
|
|
324
389
|
? node.reference
|
|
325
|
-
: undefined);
|
|
326
|
-
const format = firstOf(held, (node) => typeof node.format === 'string' ? node.format : undefined)
|
|
390
|
+
: undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
|
|
391
|
+
const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
|
|
392
|
+
alternatives.find((facts) => facts.format !== undefined)?.format;
|
|
327
393
|
const prose = type === 'string' &&
|
|
328
394
|
values === undefined &&
|
|
329
395
|
format === undefined &&
|
|
330
396
|
reference === undefined &&
|
|
331
|
-
held.every((node) => node.pattern === undefined)
|
|
397
|
+
held.every((node) => node.pattern === undefined) &&
|
|
398
|
+
unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
|
|
332
399
|
const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
|
|
333
|
-
const items = type
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
400
|
+
const items = type !== 'array'
|
|
401
|
+
? undefined
|
|
402
|
+
: (alternatives.find((facts) => facts.items !== undefined)?.items ??
|
|
403
|
+
(listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
|
|
404
|
+
const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
|
|
405
|
+
const prefix = type !== 'array'
|
|
406
|
+
? undefined
|
|
407
|
+
: (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
|
|
408
|
+
(tuples.length === 0
|
|
409
|
+
? undefined
|
|
410
|
+
: Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
|
|
339
411
|
const mapped = type === 'object' || type === undefined;
|
|
340
|
-
const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
|
|
412
|
+
const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
|
|
341
413
|
const patterns = mapped
|
|
342
414
|
? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
|
|
343
415
|
: [];
|
|
@@ -478,21 +550,134 @@ function deepFreeze(value) {
|
|
|
478
550
|
}
|
|
479
551
|
return value;
|
|
480
552
|
}
|
|
553
|
+
function ruleValue(value) {
|
|
554
|
+
return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
|
|
555
|
+
}
|
|
556
|
+
function roleNames(value) {
|
|
557
|
+
return strings(value) && value.every((name) => name !== '');
|
|
558
|
+
}
|
|
559
|
+
function compositesOf(value) {
|
|
560
|
+
return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
|
|
561
|
+
}
|
|
562
|
+
function typed(type) {
|
|
563
|
+
const types = typeof type === 'string' ? [type] : type;
|
|
564
|
+
return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
|
|
565
|
+
}
|
|
566
|
+
function admittedWhole(node) {
|
|
567
|
+
if (node === true)
|
|
568
|
+
return COMPOSITES;
|
|
569
|
+
if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
|
|
570
|
+
return [];
|
|
571
|
+
return typed(node.type) ?? COMPOSITES;
|
|
572
|
+
}
|
|
573
|
+
function composites(node, defs, seen) {
|
|
574
|
+
if (node === false)
|
|
575
|
+
return [];
|
|
576
|
+
if (!isRecord(node))
|
|
577
|
+
return COMPOSITES;
|
|
578
|
+
const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
|
|
579
|
+
const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
|
|
580
|
+
const conditioned = () => {
|
|
581
|
+
const met = composites(node.then ?? true, defs, seen);
|
|
582
|
+
return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
|
|
583
|
+
composites(node.else ?? true, defs, seen).includes(kind));
|
|
584
|
+
};
|
|
585
|
+
const bounds = [
|
|
586
|
+
typed(node.type),
|
|
587
|
+
Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
|
|
588
|
+
Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
|
|
589
|
+
target === undefined || seen.has(target)
|
|
590
|
+
? undefined
|
|
591
|
+
: composites(target, defs, new Set([...seen, target])),
|
|
592
|
+
...each(node.allOf),
|
|
593
|
+
...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
|
|
594
|
+
Object.hasOwn(node, 'if') ? conditioned() : undefined,
|
|
595
|
+
Object.hasOwn(node, 'not')
|
|
596
|
+
? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
|
|
597
|
+
: undefined,
|
|
598
|
+
];
|
|
599
|
+
return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
|
|
600
|
+
}
|
|
601
|
+
function transitionOf(value) {
|
|
602
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
|
|
603
|
+
return undefined;
|
|
604
|
+
const { from, to, roles, ...rest } = value;
|
|
605
|
+
if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
|
|
606
|
+
return undefined;
|
|
607
|
+
if (roles === undefined)
|
|
608
|
+
return { from, to };
|
|
609
|
+
return roleNames(roles) ? { from, to, roles } : undefined;
|
|
610
|
+
}
|
|
611
|
+
function fieldRules(written, field, at, defs) {
|
|
612
|
+
const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
|
|
613
|
+
if (changeRoles !== undefined && !roleNames(changeRoles))
|
|
614
|
+
return refuse('change_roles', `${at}/change_roles`);
|
|
615
|
+
if (initialRoles !== undefined && !roleNames(initialRoles))
|
|
616
|
+
return refuse('initial_roles', `${at}/initial_roles`);
|
|
617
|
+
if (transitions === undefined)
|
|
618
|
+
return {
|
|
619
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
620
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
621
|
+
};
|
|
622
|
+
if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
|
|
623
|
+
return refuse('transitions', `${at}/transitions`);
|
|
624
|
+
const listed = [];
|
|
625
|
+
for (const [index, held] of transitions.entries()) {
|
|
626
|
+
const transition = transitionOf(held);
|
|
627
|
+
if (transition === undefined)
|
|
628
|
+
return refuse('transitions', `${at}/transitions/${index}`);
|
|
629
|
+
listed.push(transition);
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
...(changeRoles === undefined ? {} : { changeRoles }),
|
|
633
|
+
...(initialRoles === undefined ? {} : { initialRoles }),
|
|
634
|
+
transitions: listed,
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
function unruled(schema) {
|
|
638
|
+
const written = new Map();
|
|
639
|
+
if (!isRecord(schema.properties))
|
|
640
|
+
return { schema, written };
|
|
641
|
+
const properties = Object.create(null);
|
|
642
|
+
for (const [field, node] of Object.entries(schema.properties)) {
|
|
643
|
+
if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
|
|
644
|
+
properties[field] = node;
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
written.set(field, node);
|
|
648
|
+
properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
|
|
649
|
+
}
|
|
650
|
+
return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
|
|
651
|
+
}
|
|
481
652
|
function readType(name, value, context) {
|
|
482
653
|
const at = `/${escapePointer(name)}`;
|
|
483
654
|
if (!isRecord(value))
|
|
484
655
|
return refuse('schema', at);
|
|
485
|
-
const { sections: declared, member_document: mark, ...
|
|
656
|
+
const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
|
|
486
657
|
if (mark !== undefined && typeof mark !== 'boolean')
|
|
487
658
|
return refuse('member_document', `${at}/member_document`);
|
|
659
|
+
if (createRoles !== undefined && !roleNames(createRoles))
|
|
660
|
+
return refuse('create_roles', `${at}/create_roles`);
|
|
661
|
+
if (deleteRoles !== undefined && !roleNames(deleteRoles))
|
|
662
|
+
return refuse('delete_roles', `${at}/delete_roles`);
|
|
488
663
|
const read = declared === undefined
|
|
489
664
|
? { sections: Object.create(null) }
|
|
490
665
|
: readSections(declared, `${at}/sections`, context);
|
|
491
666
|
if ('failure' in read)
|
|
492
667
|
return read.failure;
|
|
668
|
+
const { schema, written } = unruled(ruled);
|
|
493
669
|
const failure = schemaFailure(schema, at, context);
|
|
494
670
|
if (failure !== undefined)
|
|
495
671
|
return failure;
|
|
672
|
+
const rules = Object.create(null);
|
|
673
|
+
for (const [field, keywords] of written) {
|
|
674
|
+
const properties = schema.properties;
|
|
675
|
+
const where = `${at}/properties/${escapePointer(field)}`;
|
|
676
|
+
const ruling = fieldRules(keywords, properties[field], where, context.defs);
|
|
677
|
+
if ('rule' in ruling)
|
|
678
|
+
return ruling;
|
|
679
|
+
rules[field] = ruling;
|
|
680
|
+
}
|
|
496
681
|
const memberDocument = mark === true;
|
|
497
682
|
const root = valueFacts(schema, context.defs);
|
|
498
683
|
const fields = Object.assign(Object.create(null), root.properties);
|
|
@@ -500,13 +685,20 @@ function readType(name, value, context) {
|
|
|
500
685
|
fields[MEMBER_FIELD] = { type: 'string', prose: false };
|
|
501
686
|
const defs = Object.create(null);
|
|
502
687
|
reachedDefs(value, context.defs, defs);
|
|
688
|
+
const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
|
|
503
689
|
return {
|
|
504
690
|
name,
|
|
505
691
|
memberDocument,
|
|
506
692
|
frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
507
693
|
fields,
|
|
508
694
|
sections: read.sections,
|
|
509
|
-
|
|
695
|
+
rules,
|
|
696
|
+
...(createRoles === undefined ? {} : { createRoles }),
|
|
697
|
+
...(deleteRoles === undefined ? {} : { deleteRoles }),
|
|
698
|
+
shape: {
|
|
699
|
+
schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
|
|
700
|
+
defs,
|
|
701
|
+
},
|
|
510
702
|
};
|
|
511
703
|
}
|
|
512
704
|
function lineAt(text, offset) {
|
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":"AAUA,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,CAc3F"}
|
package/dist/divide.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blockRanges, headingLines } from './blocks.js';
|
|
2
|
-
import { projectionInput, rangeText } from './project.js';
|
|
2
|
+
import { firstEditFrom, projectionInput, rangeText, } from './project.js';
|
|
3
3
|
import { refusal } from './refuse.js';
|
|
4
4
|
const SMALLEST_BUDGET = 2;
|
|
5
5
|
function node(draft) {
|
|
@@ -131,16 +131,26 @@ function textOf(state, extent) {
|
|
|
131
131
|
return rangeText(state.content, extent, state.edits);
|
|
132
132
|
}
|
|
133
133
|
function sourceCutting(state, extent) {
|
|
134
|
-
|
|
134
|
+
const source = state.content.slice(extent.start, extent.end);
|
|
135
135
|
const masks = [];
|
|
136
|
-
for (
|
|
137
|
-
|
|
136
|
+
for (let index = firstEditFrom(state.edits, extent.start); index < state.edits.length; index += 1) {
|
|
137
|
+
const edit = state.edits[index];
|
|
138
|
+
if (edit.start > extent.end)
|
|
139
|
+
break;
|
|
140
|
+
if (edit.end > extent.end)
|
|
138
141
|
continue;
|
|
139
|
-
|
|
140
|
-
const to = edit.end - extent.start;
|
|
141
|
-
text = `${text.slice(0, from)}${'x'.repeat(to - from)}${text.slice(to)}`;
|
|
142
|
-
masks.push({ start: from, end: to });
|
|
142
|
+
masks.push({ start: edit.start - extent.start, end: edit.end - extent.start });
|
|
143
143
|
}
|
|
144
|
+
let text = '';
|
|
145
|
+
let cursor = 0;
|
|
146
|
+
for (const mask of masks) {
|
|
147
|
+
if (mask.end <= cursor)
|
|
148
|
+
continue;
|
|
149
|
+
const from = Math.max(mask.start, cursor);
|
|
150
|
+
text += `${source.slice(cursor, from)}${'x'.repeat(mask.end - from)}`;
|
|
151
|
+
cursor = mask.end;
|
|
152
|
+
}
|
|
153
|
+
text += source.slice(cursor);
|
|
144
154
|
return {
|
|
145
155
|
text,
|
|
146
156
|
masks,
|
package/dist/document.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { type Definition } from './definition.js';
|
|
2
|
-
import type { ApplyResult, BodyResult, Change, Document, Link, ParseResult } from './types.js';
|
|
2
|
+
import type { ApplyResult, BodyResult, FrontmatterResult, Change, Document, Link, LinkOccurrence, ParseResult } from './types.js';
|
|
3
3
|
import { type YamlMap } from './yaml.js';
|
|
4
|
+
export declare function parseFrontmatter(content: string, file?: string): FrontmatterResult;
|
|
4
5
|
export declare function parse(content: string, file?: string): ParseResult;
|
|
5
6
|
export declare function relativize(document: Document, file: string, handle: string, definition?: Definition): ApplyResult;
|
|
6
7
|
export declare function relativizeBody(body: string, file: string, handle: string): BodyResult;
|
|
7
8
|
export declare function relinkBody(body: string, file: string, moves: ReadonlyMap<string, string>): BodyResult;
|
|
8
9
|
export declare function links(document: Document, file: string): readonly Link[];
|
|
10
|
+
export declare function linkOccurrences(document: Document, file: string): readonly LinkOccurrence[];
|
|
9
11
|
export declare function bodyLinks(body: string, file: string): readonly Link[];
|
|
10
12
|
export declare function apply(document: Document, change: Change): ApplyResult;
|
|
11
13
|
export declare function serialize(document: Document): string;
|
|
14
|
+
export declare function fieldStart(document: Document, pointer: string): number | undefined;
|
|
12
15
|
export declare function frontmatter(document: Document): YamlMap | null;
|
|
13
16
|
//# sourceMappingURL=document.d.ts.map
|
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;AAMhF,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMhF,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,cAAc,EACd,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAaL,KAAK,OAAO,EAEb,MAAM,WAAW,CAAC;AAmEnB,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,iBAAiB,CAW9E;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAgB7D;AAkND,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,UAAU,GACtB,WAAW,CAYb;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CASrF;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,UAAU,CAeZ;AAuBD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAEvE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAG3F;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAErE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAOrE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGlF;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE9D"}
|