@agentshouse/mdmodel 0.1.0-c64dbada0730d → 0.1.0-c679f403bf3fb

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.
Files changed (53) hide show
  1. package/API.md +230 -216
  2. package/README.md +15 -18
  3. package/dist/blocks.d.ts.map +1 -1
  4. package/dist/blocks.js +7 -14
  5. package/dist/condition.d.ts +21 -8
  6. package/dist/condition.d.ts.map +1 -1
  7. package/dist/condition.js +208 -89
  8. package/dist/definition.d.ts +16 -1
  9. package/dist/definition.d.ts.map +1 -1
  10. package/dist/definition.js +255 -29
  11. package/dist/divide.d.ts.map +1 -1
  12. package/dist/divide.js +27 -17
  13. package/dist/document.d.ts +6 -3
  14. package/dist/document.d.ts.map +1 -1
  15. package/dist/document.js +315 -167
  16. package/dist/fields.d.ts +2 -0
  17. package/dist/fields.d.ts.map +1 -1
  18. package/dist/fields.js +7 -0
  19. package/dist/index.d.ts +14 -8
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +7 -5
  22. package/dist/links.d.ts +3 -0
  23. package/dist/links.d.ts.map +1 -1
  24. package/dist/links.js +66 -40
  25. package/dist/paths.d.ts +10 -1
  26. package/dist/paths.d.ts.map +1 -1
  27. package/dist/paths.js +115 -12
  28. package/dist/project.d.ts +1 -0
  29. package/dist/project.d.ts.map +1 -1
  30. package/dist/project.js +38 -15
  31. package/dist/references.d.ts +2 -2
  32. package/dist/references.d.ts.map +1 -1
  33. package/dist/references.js +6 -1
  34. package/dist/schema.js +2 -2
  35. package/dist/types.d.ts +49 -2
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/validate.d.ts +30 -2
  38. package/dist/validate.d.ts.map +1 -1
  39. package/dist/validate.js +290 -115
  40. package/dist/yaml.d.ts +7 -3
  41. package/dist/yaml.d.ts.map +1 -1
  42. package/dist/yaml.js +72 -43
  43. package/fixtures/README.md +6 -5
  44. package/fixtures/cases/cross-room-link/context.json +1 -0
  45. package/fixtures/cases/cross-room-link/expected.json +1 -0
  46. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  47. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  48. package/fixtures/cases/cross-room-reference/context.json +1 -0
  49. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  50. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  51. package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
  52. package/fixtures/division.json +26 -26
  53. package/package.json +4 -2
@@ -5,6 +5,7 @@ export type ValueFacts = {
5
5
  readonly format?: string;
6
6
  readonly values?: readonly unknown[];
7
7
  readonly reference?: readonly string[];
8
+ readonly crossRoom?: true;
8
9
  readonly prose: boolean;
9
10
  readonly conditional?: true;
10
11
  readonly prefix?: readonly ValueFacts[];
@@ -29,12 +30,26 @@ export type Shape = {
29
30
  readonly schema: Readonly<Record<string, unknown>>;
30
31
  readonly defs: Readonly<Record<string, unknown>>;
31
32
  };
33
+ export type RuleValue = string | number | boolean | null;
34
+ export type Transition = {
35
+ readonly from: RuleValue;
36
+ readonly to: RuleValue;
37
+ readonly roles?: readonly string[];
38
+ };
39
+ export type FieldRules = {
40
+ readonly changeRoles?: readonly string[];
41
+ readonly initialRoles?: readonly string[];
42
+ readonly transitions?: readonly Transition[];
43
+ };
32
44
  export type Definition = {
33
45
  readonly name: string;
34
46
  readonly memberDocument: boolean;
35
47
  readonly frontmatter: ValueFacts;
36
48
  readonly fields: Readonly<Record<string, ValueFacts>>;
37
49
  readonly sections: Readonly<Record<string, SectionSpec>>;
50
+ readonly rules: Readonly<Record<string, FieldRules>>;
51
+ readonly createRoles?: readonly string[];
52
+ readonly deleteRoles?: readonly string[];
38
53
  readonly shape: Shape;
39
54
  };
40
55
  export type Failure = {
@@ -62,5 +77,5 @@ export type PointerFacts = {
62
77
  export declare function crossedFacts(facts: ValueFacts): ValueFacts[];
63
78
  export declare function fieldFacts(definition: Definition, key: string): ValueFacts | undefined;
64
79
  export declare function pointerFacts(definition: Definition, pointer: string): PointerFacts | undefined;
65
- export declare function readSchema(text: string): VerifiedModel | Failure;
80
+ export declare function readSchema(text: string, provided?: VerifiedModel): VerifiedModel | Failure;
66
81
  //# sourceMappingURL=definition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,WAAW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,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CAK5D;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAItF;AAqBD,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAc9F;AAuQD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,aAAwB,GACjC,aAAa,GAAG,OAAO,CAsCzB"}
@@ -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,25 @@ 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'];
27
+ const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
28
+ const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
15
29
  const DEFS_REFERENCE = '#/$defs/';
16
30
  const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
17
31
  export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
18
32
  const HOUSE_KEYS = {
19
- type: { prose: false },
33
+ [TYPE_FIELD]: { prose: false },
20
34
  [SITE_FIELD]: { prose: false },
21
35
  [RECEIVED_FIELD]: { prose: false },
22
36
  };
@@ -204,8 +218,12 @@ const KEYWORDS = {
204
218
  return (Array.isArray(named) &&
205
219
  named.length > 0 &&
206
220
  strings(named) &&
207
- named.every((name) => name === BUILT_IN_TYPE || name === ATTACHMENT || context.types.has(name)));
221
+ named.every((name) => name === BUILT_IN_TYPE ||
222
+ name === ATTACHMENT ||
223
+ context.types.has(name) ||
224
+ node.cross_room === true));
208
225
  },
226
+ cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
209
227
  };
210
228
  function sharedType(values) {
211
229
  if (values.length === 0)
@@ -270,24 +288,45 @@ function united(left, right) {
270
288
  return undefined;
271
289
  return [...left, ...right.filter((value) => !left.some((held) => equalValue(held, value)))];
272
290
  }
291
+ function both(left, right) {
292
+ return left !== undefined && right !== undefined ? joined(left, right) : undefined;
293
+ }
273
294
  function joined(left, right) {
274
295
  const type = left.type === right.type ? left.type : undefined;
275
296
  const format = left.format === right.format ? left.format : undefined;
276
297
  const values = united(left.values, right.values);
277
298
  const reference = united(left.reference, right.reference);
278
- const items = left.items !== undefined && right.items !== undefined
279
- ? joined(left.items, right.items)
280
- : undefined;
299
+ const crossRoom = left.crossRoom === true || right.crossRoom === true;
300
+ const items = both(left.items, right.items);
301
+ const prefix = left.prefix === undefined && right.prefix === undefined
302
+ ? undefined
303
+ : Array.from({ length: Math.max(left.prefix?.length ?? 0, right.prefix?.length ?? 0) }, (_, index) => both(itemFacts(left, index), itemFacts(right, index)) ?? { prose: false });
304
+ const properties = Object.create(null);
305
+ for (const [name, facts] of Object.entries(left.properties ?? {})) {
306
+ const shared = both(facts, right.properties?.[name]);
307
+ if (shared !== undefined)
308
+ properties[name] = shared;
309
+ }
310
+ const patterns = (left.patterns ?? []).flatMap(({ pattern, facts }) => {
311
+ const shared = both(facts, right.patterns?.find((one) => one.pattern === pattern)?.facts);
312
+ return shared === undefined ? [] : [{ pattern, facts: shared }];
313
+ });
314
+ const additional = both(left.additional, right.additional);
281
315
  return {
282
316
  ...(type === undefined ? {} : { type }),
283
317
  ...(format === undefined ? {} : { format }),
284
318
  ...(values === undefined ? {} : { values }),
285
319
  ...(reference === undefined ? {} : { reference }),
320
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
286
321
  prose: left.prose && right.prose,
322
+ ...(prefix === undefined ? {} : { prefix }),
287
323
  ...(items === undefined ? {} : { items }),
324
+ ...(Object.keys(properties).length === 0 ? {} : { properties }),
325
+ ...(patterns.length === 0 ? {} : { patterns }),
326
+ ...(additional === undefined ? {} : { additional }),
288
327
  };
289
328
  }
290
- function propertiesOf(held, defs, ancestry) {
329
+ function propertiesOf(held, variants, defs, ancestry) {
291
330
  const declared = new Map();
292
331
  for (const node of held) {
293
332
  if (!isRecord(node.properties))
@@ -298,46 +337,88 @@ function propertiesOf(held, defs, ancestry) {
298
337
  const properties = Object.create(null);
299
338
  for (const [name, schemas] of declared)
300
339
  properties[name] = factsOf(schemas, defs, ancestry);
301
- const variants = Object.create(null);
302
- for (const branch of held.flatMap(variantsOf)) {
303
- for (const [name, facts] of Object.entries(factsOf([branch], defs, ancestry).properties ?? {})) {
340
+ const conditional = Object.create(null);
341
+ for (const branch of variants.values()) {
342
+ for (const [name, facts] of Object.entries(branch.properties ?? {})) {
304
343
  if (Object.hasOwn(properties, name))
305
344
  continue;
306
- variants[name] = Object.hasOwn(variants, name) ? joined(variants[name], facts) : facts;
345
+ conditional[name] = Object.hasOwn(conditional, name)
346
+ ? joined(conditional[name], facts)
347
+ : facts;
307
348
  }
308
349
  }
309
- for (const [name, facts] of Object.entries(variants))
350
+ for (const [name, facts] of Object.entries(conditional))
310
351
  properties[name] = { ...facts, conditional: true };
311
352
  return Object.keys(properties).length === 0 ? undefined : properties;
312
353
  }
354
+ function nullOnly(facts) {
355
+ return facts.type === 'null' || (facts.values?.every((value) => value === null) ?? false);
356
+ }
357
+ function alternativesOf(held, variants) {
358
+ return held.flatMap((node) => [node.anyOf, node.oneOf].flatMap((branches) => {
359
+ if (!Array.isArray(branches))
360
+ return [];
361
+ const kept = branches
362
+ .flatMap((branch) => {
363
+ const facts = isRecord(branch) ? variants.get(branch) : undefined;
364
+ return facts === undefined ? [] : [facts];
365
+ })
366
+ .filter((facts) => !nullOnly(facts));
367
+ return kept.length === 0 ? [] : [kept];
368
+ }));
369
+ }
370
+ function inheritedOf(held) {
371
+ return held.flatMap((node) => {
372
+ const kept = Object.fromEntries(['type', 'items', 'prefixItems'].flatMap((key) => node[key] === undefined ? [] : [[key, node[key]]]));
373
+ return Object.keys(kept).length === 0 ? [] : [kept];
374
+ });
375
+ }
313
376
  function factsOf(nodes, defs, ancestry) {
314
377
  const { held, ancestry: reached } = conjoined(nodes, defs, ancestry);
315
- const listed = held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []);
378
+ const inherited = inheritedOf(held);
379
+ const variants = new Map(held
380
+ .flatMap(variantsOf)
381
+ .map((branch) => [branch, factsOf([branch, ...inherited], defs, reached)]));
382
+ const unions = alternativesOf(held, variants);
383
+ const alternatives = unions.map((kept) => kept.reduce(joined));
384
+ const listed = [
385
+ ...held.flatMap((node) => Array.isArray(node.enum) ? [node.enum] : node.const !== undefined ? [[node.const]] : []),
386
+ ...alternatives.flatMap((facts) => (facts.values === undefined ? [] : [facts.values])),
387
+ ];
316
388
  const values = listed.length === 0
317
389
  ? undefined
318
390
  : listed.reduce((kept, list) => kept.filter((value) => list.some((other) => equalValue(other, value))));
319
391
  const type = firstOf(held, (node) => singleType(node.type)) ??
320
- (values === undefined ? undefined : sharedType(values));
392
+ (values === undefined ? undefined : sharedType(values)) ??
393
+ alternatives.find((facts) => facts.type !== undefined)?.type;
321
394
  const reference = firstOf(held, (node) => typeof node.reference === 'string'
322
395
  ? [node.reference]
323
396
  : Array.isArray(node.reference)
324
397
  ? node.reference
325
- : undefined);
326
- const format = firstOf(held, (node) => typeof node.format === 'string' ? node.format : undefined);
398
+ : undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
399
+ const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
400
+ const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
401
+ alternatives.find((facts) => facts.format !== undefined)?.format;
327
402
  const prose = type === 'string' &&
328
403
  values === undefined &&
329
404
  format === undefined &&
330
405
  reference === undefined &&
331
- held.every((node) => node.pattern === undefined);
406
+ held.every((node) => node.pattern === undefined) &&
407
+ unions.every((kept) => kept.every((facts) => facts.type !== 'string' || facts.prose));
332
408
  const listedItems = held.flatMap((node) => (node.items === undefined ? [] : [node.items]));
333
- const items = type === 'array' && listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined;
334
- const prefix = type === 'array'
335
- ? firstOf(held, (node) => Array.isArray(node.prefixItems)
336
- ? node.prefixItems.map((schema) => factsOf([schema], defs, reached))
337
- : undefined)
338
- : undefined;
409
+ const items = type !== 'array'
410
+ ? undefined
411
+ : (alternatives.find((facts) => facts.items !== undefined)?.items ??
412
+ (listedItems.length > 0 ? factsOf(listedItems, defs, reached) : undefined));
413
+ const tuples = held.flatMap((node) => Array.isArray(node.prefixItems) ? [node.prefixItems] : []);
414
+ const prefix = type !== 'array'
415
+ ? undefined
416
+ : (alternatives.find((facts) => facts.prefix !== undefined)?.prefix ??
417
+ (tuples.length === 0
418
+ ? undefined
419
+ : Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
339
420
  const mapped = type === 'object' || type === undefined;
340
- const properties = mapped ? propertiesOf(held, defs, reached) : undefined;
421
+ const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
341
422
  const patterns = mapped
342
423
  ? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
343
424
  : [];
@@ -350,6 +431,7 @@ function factsOf(nodes, defs, ancestry) {
350
431
  ...(format === undefined ? {} : { format }),
351
432
  ...(values === undefined ? {} : { values }),
352
433
  ...(reference === undefined ? {} : { reference }),
434
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
353
435
  prose,
354
436
  ...(prefix === undefined ? {} : { prefix }),
355
437
  ...(items === undefined ? {} : { items }),
@@ -478,21 +560,152 @@ function deepFreeze(value) {
478
560
  }
479
561
  return value;
480
562
  }
563
+ function ruleValue(value) {
564
+ return value === null || typeof value === 'string' || typeof value === 'boolean' || finite(value);
565
+ }
566
+ function roleNames(value) {
567
+ return strings(value) && value.every((name) => name !== '');
568
+ }
569
+ function compositesOf(value) {
570
+ return Array.isArray(value) ? ['array'] : isRecord(value) ? ['object'] : [];
571
+ }
572
+ function typed(type) {
573
+ const types = typeof type === 'string' ? [type] : type;
574
+ return Array.isArray(types) ? COMPOSITES.filter((kind) => types.includes(kind)) : undefined;
575
+ }
576
+ function admittedWhole(node) {
577
+ if (node === true)
578
+ return COMPOSITES;
579
+ if (!isRecord(node) || Object.keys(node).some((key) => key !== 'type' && !ANNOTATIONS.has(key)))
580
+ return [];
581
+ return typed(node.type) ?? COMPOSITES;
582
+ }
583
+ function composites(node, defs, seen) {
584
+ if (node === false)
585
+ return [];
586
+ if (!isRecord(node))
587
+ return COMPOSITES;
588
+ const each = (nodes) => Array.isArray(nodes) ? nodes.map((one) => composites(one, defs, seen)) : [];
589
+ const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
590
+ const conditioned = () => {
591
+ const met = composites(node.then ?? true, defs, seen);
592
+ return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
593
+ composites(node.else ?? true, defs, seen).includes(kind));
594
+ };
595
+ const bounds = [
596
+ typed(node.type),
597
+ Array.isArray(node.enum) ? node.enum.flatMap(compositesOf) : undefined,
598
+ Object.hasOwn(node, 'const') ? compositesOf(node.const) : undefined,
599
+ target === undefined || seen.has(target)
600
+ ? undefined
601
+ : composites(target, defs, new Set([...seen, target])),
602
+ ...each(node.allOf),
603
+ ...[node.anyOf, node.oneOf].filter(Array.isArray).map((branches) => each(branches).flat()),
604
+ Object.hasOwn(node, 'if') ? conditioned() : undefined,
605
+ Object.hasOwn(node, 'not')
606
+ ? COMPOSITES.filter((kind) => !admittedWhole(node.not).includes(kind))
607
+ : undefined,
608
+ ];
609
+ return COMPOSITES.filter((kind) => bounds.every((bound) => bound?.includes(kind) ?? true));
610
+ }
611
+ function transitionOf(value) {
612
+ if (!isRecord(value) || !Object.hasOwn(value, 'from') || !Object.hasOwn(value, 'to'))
613
+ return undefined;
614
+ const { from, to, roles, ...rest } = value;
615
+ if (Object.keys(rest).length > 0 || !ruleValue(from) || !ruleValue(to))
616
+ return undefined;
617
+ if (roles === undefined)
618
+ return { from, to };
619
+ return roleNames(roles) ? { from, to, roles } : undefined;
620
+ }
621
+ function fieldRules(written, field, at, defs) {
622
+ const { change_roles: changeRoles, initial_roles: initialRoles, transitions } = written;
623
+ if (changeRoles !== undefined && !roleNames(changeRoles))
624
+ return refuse('change_roles', `${at}/change_roles`);
625
+ if (initialRoles !== undefined && !roleNames(initialRoles))
626
+ return refuse('initial_roles', `${at}/initial_roles`);
627
+ if (transitions === undefined)
628
+ return {
629
+ ...(changeRoles === undefined ? {} : { changeRoles }),
630
+ ...(initialRoles === undefined ? {} : { initialRoles }),
631
+ };
632
+ if (!Array.isArray(transitions) || composites(field, defs, new Set()).length > 0)
633
+ return refuse('transitions', `${at}/transitions`);
634
+ const listed = [];
635
+ for (const [index, held] of transitions.entries()) {
636
+ const transition = transitionOf(held);
637
+ if (transition === undefined)
638
+ return refuse('transitions', `${at}/transitions/${index}`);
639
+ listed.push(transition);
640
+ }
641
+ return {
642
+ ...(changeRoles === undefined ? {} : { changeRoles }),
643
+ ...(initialRoles === undefined ? {} : { initialRoles }),
644
+ transitions: listed,
645
+ };
646
+ }
647
+ function unruled(schema) {
648
+ const written = new Map();
649
+ if (!isRecord(schema.properties))
650
+ return { schema, written };
651
+ const properties = Object.create(null);
652
+ for (const [field, node] of Object.entries(schema.properties)) {
653
+ if (!isRecord(node) || !FIELD_RULES.some((keyword) => Object.hasOwn(node, keyword))) {
654
+ properties[field] = node;
655
+ continue;
656
+ }
657
+ written.set(field, node);
658
+ properties[field] = Object.fromEntries(Object.entries(node).filter(([keyword]) => !FIELD_RULES.includes(keyword)));
659
+ }
660
+ return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
661
+ }
662
+ function providedType(name, value, provided) {
663
+ const at = `/${escapePointer(name)}`;
664
+ if (!isRecord(value))
665
+ return refuse('schema', at);
666
+ const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
667
+ if (declared !== undefined)
668
+ return refuse('provided-type', `${at}/${escapePointer(declared)}`);
669
+ const { create_roles: createRoles, delete_roles: deleteRoles } = value;
670
+ if (createRoles !== undefined && !roleNames(createRoles))
671
+ return refuse('create_roles', `${at}/create_roles`);
672
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
673
+ return refuse('delete_roles', `${at}/delete_roles`);
674
+ return {
675
+ ...provided,
676
+ ...(createRoles === undefined ? {} : { createRoles }),
677
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
678
+ };
679
+ }
481
680
  function readType(name, value, context) {
482
681
  const at = `/${escapePointer(name)}`;
483
682
  if (!isRecord(value))
484
683
  return refuse('schema', at);
485
- const { sections: declared, member_document: mark, ...schema } = value;
684
+ const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
486
685
  if (mark !== undefined && typeof mark !== 'boolean')
487
686
  return refuse('member_document', `${at}/member_document`);
687
+ if (createRoles !== undefined && !roleNames(createRoles))
688
+ return refuse('create_roles', `${at}/create_roles`);
689
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
690
+ return refuse('delete_roles', `${at}/delete_roles`);
488
691
  const read = declared === undefined
489
692
  ? { sections: Object.create(null) }
490
693
  : readSections(declared, `${at}/sections`, context);
491
694
  if ('failure' in read)
492
695
  return read.failure;
696
+ const { schema, written } = unruled(ruled);
493
697
  const failure = schemaFailure(schema, at, context);
494
698
  if (failure !== undefined)
495
699
  return failure;
700
+ const rules = Object.create(null);
701
+ for (const [field, keywords] of written) {
702
+ const properties = schema.properties;
703
+ const where = `${at}/properties/${escapePointer(field)}`;
704
+ const ruling = fieldRules(keywords, properties[field], where, context.defs);
705
+ if ('rule' in ruling)
706
+ return ruling;
707
+ rules[field] = ruling;
708
+ }
496
709
  const memberDocument = mark === true;
497
710
  const root = valueFacts(schema, context.defs);
498
711
  const fields = Object.assign(Object.create(null), root.properties);
@@ -500,19 +713,26 @@ function readType(name, value, context) {
500
713
  fields[MEMBER_FIELD] = { type: 'string', prose: false };
501
714
  const defs = Object.create(null);
502
715
  reachedDefs(value, context.defs, defs);
716
+ const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
503
717
  return {
504
718
  name,
505
719
  memberDocument,
506
720
  frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
507
721
  fields,
508
722
  sections: read.sections,
509
- shape: { schema: value, defs },
723
+ rules,
724
+ ...(createRoles === undefined ? {} : { createRoles }),
725
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
726
+ shape: {
727
+ schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
728
+ defs,
729
+ },
510
730
  };
511
731
  }
512
732
  function lineAt(text, offset) {
513
733
  return text.slice(0, offset).split(/\r\n|\r|\n/).length;
514
734
  }
515
- export function readSchema(text) {
735
+ export function readSchema(text, provided = NO_TYPES) {
516
736
  let root;
517
737
  try {
518
738
  root = jsValue(parseYamlMapping(text, 0, text.length));
@@ -530,7 +750,7 @@ export function readSchema(text) {
530
750
  if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
531
751
  return refuse('schema-type-name', `/${escapePointer(name)}`);
532
752
  }
533
- const context = { defs, types: new Set(names) };
753
+ const context = { defs, types: new Set([...names, ...Object.keys(provided.types)]) };
534
754
  for (const [name, def] of Object.entries(defs)) {
535
755
  const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
536
756
  if (failure !== undefined)
@@ -539,7 +759,9 @@ export function readSchema(text) {
539
759
  const types = Object.create(null);
540
760
  let marked = false;
541
761
  for (const name of names) {
542
- const definition = readType(name, root[name], context);
762
+ const definition = Object.hasOwn(provided.types, name)
763
+ ? providedType(name, root[name], provided.types[name])
764
+ : readType(name, root[name], context);
543
765
  if ('rule' in definition)
544
766
  return definition;
545
767
  if (definition.memberDocument) {
@@ -549,5 +771,9 @@ export function readSchema(text) {
549
771
  }
550
772
  types[name] = deepFreeze(definition);
551
773
  }
774
+ for (const [name, definition] of Object.entries(provided.types)) {
775
+ if (!Object.hasOwn(types, name))
776
+ types[name] = definition;
777
+ }
552
778
  return Object.freeze({ types: Object.freeze(types) });
553
779
  }
@@ -1 +1 @@
1
- {"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AA4WpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAc3F"}
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,7 +1,7 @@
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
- const SMALLEST_BUDGET = 2;
4
+ const SMALLEST_BOUND = 2;
5
5
  function node(draft) {
6
6
  return {
7
7
  start: draft.start,
@@ -86,8 +86,8 @@ function isTrailingSurrogate(text, index) {
86
86
  function characterLength(text, index) {
87
87
  return isTrailingSurrogate(text, index + 1) ? 2 : 1;
88
88
  }
89
- function boundOf(cutting, from, to, budget) {
90
- const limit = from + budget;
89
+ function boundOf(cutting, from, to, bound) {
90
+ const limit = from + bound;
91
91
  if (limit >= to)
92
92
  return to;
93
93
  for (let index = limit; index > from + 1; index -= 1) {
@@ -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
- let text = state.content.slice(extent.start, extent.end);
134
+ const source = state.content.slice(extent.start, extent.end);
135
135
  const masks = [];
136
- for (const edit of state.edits) {
137
- if (edit.start < extent.start || edit.end > extent.end)
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
- const from = edit.start - extent.start;
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,
@@ -158,12 +168,12 @@ function valueCutting(value) {
158
168
  };
159
169
  }
160
170
  function prefixOf(state, body) {
161
- if (body.emitted === 0 || body.heading.length >= state.budget)
171
+ if (body.emitted === 0 || body.heading.length >= state.bound)
162
172
  return '';
163
173
  return body.heading;
164
174
  }
165
175
  function available(state, body) {
166
- return state.budget - prefixOf(state, body).length;
176
+ return state.bound - prefixOf(state, body).length;
167
177
  }
168
178
  function emit(state, body, piece, bare = false) {
169
179
  if (piece.text.trim() === '')
@@ -206,7 +216,7 @@ function divideBound(state, body, cutting, range) {
206
216
  let start = range.start;
207
217
  while (start < range.end) {
208
218
  const bare = available(state, body) < characterLength(cutting.text, start);
209
- const room = bare ? state.budget : available(state, body);
219
+ const room = bare ? state.bound : available(state, body);
210
220
  const stop = boundOf(cutting, start, range.end, room);
211
221
  const piece = cutting.piece(start, stop);
212
222
  if (cutting.masks.length === 0 || piece.text.length <= room) {
@@ -293,8 +303,8 @@ function divideInput(state, input) {
293
303
  ]);
294
304
  }
295
305
  export function divide(document, file, context) {
296
- if (!Number.isInteger(context.budget) || context.budget < SMALLEST_BUDGET) {
297
- return { ok: false, refusal: refusal(file, 'division-budget') };
306
+ if (!Number.isInteger(context.bound) || context.bound < SMALLEST_BOUND) {
307
+ return { ok: false, refusal: refusal(file, 'division-bound') };
298
308
  }
299
309
  const result = projectionInput(document, file, context);
300
310
  if (!result.ok)
@@ -302,7 +312,7 @@ export function divide(document, file, context) {
302
312
  const state = {
303
313
  content: document.content,
304
314
  edits: result.input.edits,
305
- budget: context.budget,
315
+ bound: context.bound,
306
316
  spans: [],
307
317
  };
308
318
  divideInput(state, result.input);
@@ -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 LinkInventory } from './links.js';
3
+ import type { ApplyResult, BodyResult, FrontmatterResult, Change, Document, Link, ParseResult } from './types.js';
3
4
  import { type YamlMap } from './yaml.js';
5
+ export declare function inventoryOf(document: Document): LinkInventory;
6
+ export declare function parseFrontmatter(content: string, file?: string): FrontmatterResult;
4
7
  export declare function parse(content: string, file?: string): ParseResult;
5
- export declare function relativize(document: Document, file: string, handle: string, definition?: Definition): ApplyResult;
8
+ export declare function relativize(document: Document, file: string, handle: string, definition?: Definition, kept?: ReadonlySet<string>): ApplyResult;
6
9
  export declare function relativizeBody(body: string, file: string, handle: string): BodyResult;
7
10
  export declare function relinkBody(body: string, file: string, moves: ReadonlyMap<string, string>): BodyResult;
8
11
  export declare function links(document: Document, file: string): readonly Link[];
9
12
  export declare function bodyLinks(body: string, file: string): readonly Link[];
10
- export declare function apply(document: Document, change: Change): ApplyResult;
13
+ export declare function apply(document: Document, changes: readonly Change[]): ApplyResult;
11
14
  export declare function serialize(document: Document): string;
12
15
  export declare function frontmatter(document: Document): YamlMap | null;
13
16
  //# sourceMappingURL=document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMhF,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAYL,KAAK,OAAO,EAEb,MAAM,WAAW,CAAC;AAwCnB,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAkD7D;AA2KD,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,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