@agentshouse/mdmodel 0.1.0-cad192ab63d5f → 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 CHANGED
@@ -44,10 +44,14 @@ if (parsed.ok) {
44
44
  `verify(schema)` reads one schema text, the MD Types of one Room or App: one JSON Schema document
45
45
  (draft 2020-12) in the YAML subset. Every top-level key but `$defs` names an MD Type holding the
46
46
  JSON Schema of its frontmatter; `$defs` holds shapes the types reuse, reached by a `$ref` under
47
- `#/$defs/` alone. `type` and the built-in `any` are never declared. The model adds three keywords:
47
+ `#/$defs/` alone. `type` and the built-in `any` are never declared. The model adds its keywords:
48
48
  `reference` on a string names one MD Type, several, `any` or `attachment`; `sections` declares a
49
49
  type's H2 sections, each `{ kind: text }` or `{ kind: list, items }` over one string, number,
50
- integer or boolean, optionally `required: true`; `member_document: true` marks at most one type.
50
+ integer or boolean, optionally `required: true`; `member_document: true` marks at most one type. A
51
+ type alone takes `create_roles` and `delete_roles`, each a list of role names. On a field of a
52
+ type's own `properties` alone, `change_roles` and `initial_roles` each list role names, and
53
+ `transitions` lists `{ from, to, roles? }`, each end a scalar or `null`, on a field whose `type`,
54
+ `enum`, `const`, `$ref`, `allOf`, `anyOf`, `oneOf`, `if` and `not` admit no list or object.
51
55
 
52
56
  ```yaml
53
57
  $defs:
@@ -63,18 +67,19 @@ contact: { member_document: true }
63
67
  ```
64
68
 
65
69
  The model's `types` expose each MD Type's `name`, `memberDocument`, `sections`, `shape` (the type as
66
- written with every `$defs` shape it reaches), the facts of its `frontmatter` and `fields`, its
67
- top-level ones: JSON `type`, `format`, `values`, `reference` targets, `items`, `properties`, an open
68
- map's `patterns` and `additional`, and `prose`, a string with no `enum`, `const`, `format`,
69
- `pattern` or `reference`. Facts join `$ref` and `allOf` to their siblings and the variants of
70
- `anyOf`, `oneOf`, `then`, `else` and `dependentSchemas`, a variant's own keys `conditional`; a path
71
- without one `type`, `null` aside, has none. A malformed schema is refused whole, naming its `rule`,
72
- the keyword or the model's own, and the JSON Pointer `location` it concerns, such as
73
- `/plan/properties/status/enum`, or `line <n>` outside the YAML subset. `pointerFacts(definition,
74
- pointer)` reads the facts a frontmatter pointer reaches, `itemFacts` and `memberFacts` take one step
75
- and `crossedFacts` reads a list's item facts; `pointerSegments` and `escapePointer` split and write
76
- a pointer, `ARRAY_INDEX` matches an index segment, and `ATTACHMENT` is the `reference` that admits
77
- any path.
70
+ written, its rule keywords left out, with every `$defs` shape it reaches), `createRoles` and
71
+ `deleteRoles` when written, its `rules` by field as `changeRoles`, `initialRoles` and `transitions`,
72
+ the facts of its `frontmatter` and `fields`, its top-level ones: JSON `type`, `format`, `values`,
73
+ `reference` targets, `items`, `properties`, an open map's `patterns` and `additional`, and `prose`,
74
+ a string with no `enum`, `const`, `format`, `pattern` or `reference`. Facts join `$ref` and `allOf`
75
+ to their siblings and the variants of `anyOf`, `oneOf`, `then`, `else` and `dependentSchemas`, a
76
+ variant's own keys `conditional`; a path without one `type`, `null` aside, has none. A malformed
77
+ schema is refused whole, naming its `rule`, the keyword or the model's own, and the JSON Pointer
78
+ `location` it concerns, such as `/plan/properties/status/enum`, or `line <n>` outside the YAML
79
+ subset. `pointerFacts(definition, pointer)` reads the facts a frontmatter pointer reaches,
80
+ `itemFacts` and `memberFacts` take one step and `crossedFacts` reads a list's item facts;
81
+ `pointerSegments` and `escapePointer` split and write a pointer, `ARRAY_INDEX` matches an index
82
+ segment, and `ATTACHMENT` is the `reference` that admits any path.
78
83
 
79
84
  `validate(library, context?, model?)` takes the resulting text Library and one `ValidationContext`
80
85
  of `binaryTargets: readonly string[]`, none when omitted. Library keys and binary targets share one
@@ -97,7 +102,7 @@ schema, else `structured-section`; a reference item is one ordinary link alone,
97
102
  `- [Ada](ada.md)`. A reference, at any depth or a section item, reaching a URL, a binary target, or a
98
103
  Document of a type it does not name is `unresolved-reference`, and a frontmatter one reaching no
99
104
  member is `referenced-missing-file` naming its `referrers`; `attachment` admits any path, and no
100
- body link is a referrer.
105
+ body link is a referrer. `validating` yields each path `validate` reads, then returns its verdict.
101
106
 
102
107
  Validation returns acceptance or one refusal naming the file, the field or section, and the violated
103
108
  rule. `parse`, `apply`, and `serialize` operate on a single text Document; they do not validate
@@ -114,11 +119,11 @@ boolean, a finite number, a list without holes or a plain object of them, holdin
114
119
  `equalValue(left, right)` compares two by value, whatever their key order, as `apply` compares a
115
120
  field with its prior.
116
121
 
117
- `Document.preamble` is a readonly string containing the exact source after frontmatter and before
118
- the first section heading recognized by the existing section parser. Without a section it is the
119
- entire post-frontmatter body; without frontmatter it starts at the beginning of the Document. An
120
- empty span is `''`. It includes whitespace, newlines, a leading H1, and any fenced text before the
121
- first section. The closing frontmatter delimiter and its line ending belong to frontmatter.
122
+ `Document.preamble` is a readonly string holding the exact source after frontmatter and before the
123
+ first section heading the section parser recognizes, `''` when empty, whitespace, newlines, a
124
+ leading H1 and any fenced text before the first section included. The closing frontmatter
125
+ delimiter and its line ending belong to frontmatter: `bodyAfterFrontmatter(content)` is the exact
126
+ source after them, the whole text when it opens no closed fence, and the preamble begins it.
122
127
  `headingLines(content, from, to)` reads each ATX heading outside a fence, by `level` and `name`.
123
128
 
124
129
  ```ts
@@ -200,18 +205,16 @@ profile reads back: bare when it carries no whitespace, does not open with `<`,
200
205
  parentheses, otherwise inside angle brackets, which the original form is kept in when it still
201
206
  fits. A destination that neither form can carry is refused as `unwritable-link`.
202
207
 
203
- `project(document, file, context?)` is the Embedding projection input of one
204
- Document: the prose a consumer embeds, with every internal Markdown-document
205
- link reduced to the label a reader sees. A Document that declares no MD type
206
- contributes its body after the frontmatter fence. A typed one contributes its
207
- prose values, its preamble, and every H2 section its MD type does not declare as
208
- structure, each with its own heading line and every occurrence of a repeated
209
- name, in Document order: a declared text section, a list section of prose items
210
- and an undeclared section are in; a list section of any other item schema is
211
- not. A prose value is a frontmatter string at any depth whose schema is prose,
212
- projected bare and followed by a blank line, in the order the Document writes
213
- them, exactly as written. The Path and every other value stay outside, so
214
- changing them alone leaves the projection unchanged.
208
+ `project(document, file, context?)` is the Embedding projection input of one Document: the prose a
209
+ consumer embeds, with every internal Markdown-document link reduced to the label a reader sees. A
210
+ Document that declares no MD type contributes its body after the frontmatter fence. A typed one
211
+ contributes its prose values, its preamble, and every H2 section its MD type does not declare as
212
+ structure, each with its own heading line and every occurrence of a repeated name, in Document
213
+ order: a declared text section, a list section of prose items and an undeclared section are in; a
214
+ list section of any other item schema is not. A prose value is a frontmatter string at any depth
215
+ whose schema is prose, projected bare and followed by a blank line, in the order the Document writes
216
+ them, exactly as written. The Path and every other value stay outside, so changing them alone leaves
217
+ the projection unchanged.
215
218
 
216
219
  ```ts
217
220
  const parsed = parse(content);
@@ -224,16 +227,14 @@ if (parsed.ok) {
224
227
  }
225
228
  ```
226
229
 
227
- `ProjectionContext` carries `documentTargets`, the collection-relative Paths the
228
- caller holds as Markdown documents, and `definition`, the verified MD Type the
229
- Document's `type` names, taken from the model `verify` returned. A Document that
230
- declares a type the caller supplies no definition for is refused as
231
- `unknown-type`. `documentTargets` is what makes a destination internal: a
232
- destination resolving to a supplied Path is internal, and every other
233
- destination stays authored text, a binary target and a Path nobody
234
- supplied alike. The caller supplies that membership, as it does for `validate`;
235
- the model reads no bytes, resolves no authority, and classifies nothing it was
236
- not given.
230
+ `ProjectionContext` carries `documentTargets`, the collection-relative Paths the caller holds as
231
+ Markdown documents, and `definition`, the verified MD Type the Document's `type` names, taken from
232
+ the model `verify` returned. A Document that declares a type the caller supplies no definition for
233
+ is refused as `unknown-type`. `documentTargets` is what makes a destination internal: a destination
234
+ resolving to a supplied Path is internal, and every other destination stays authored text, a binary
235
+ target and a Path nobody supplied alike. The caller supplies that membership, as it does for
236
+ `validate`; the model reads no bytes, resolves no authority, and classifies nothing it was not
237
+ given.
237
238
 
238
239
  An internal link contributes its visible label and no destination, fragment, or
239
240
  title, in the inline `[label](path)`, full `[label][id]`, collapsed
@@ -248,11 +249,10 @@ and `validate` read. `project` returns text and never rewrites the Document.
248
249
  A `link` change leaves the projection of every Document it rewrites
249
250
  byte-identical, while a changed visible label changes it.
250
251
 
251
- `divide(document, file, context)` divides that same Embedding projection input
252
- into ordered Spans under the budget the caller supplies. Each Span carries the
253
- `text` to embed and the `start` and `end` of the extent it addresses in the
254
- Document's own source, as UTF-8 byte offsets into that source and never string
255
- positions, so a caller stores the extent and hydrates the text it shows from
252
+ `divide(document, file, context)` divides that same Embedding projection input into ordered Spans
253
+ under the budget the caller supplies. Each Span carries the `text` to embed and the `start` and
254
+ `end` of the extent it addresses in the Document's own source, as UTF-8 byte offsets into that
255
+ source and never string positions, so a caller stores the extent and hydrates the text it shows from
256
256
  the Document itself.
257
257
 
258
258
  ```ts
@@ -350,7 +350,7 @@ names it. A field absent on both sides never fires; `from: 'new'` admits only a
350
350
  `to: 'deleted'` only a deletion, and listed values need that side to hold `field` `in` them.
351
351
 
352
352
  `itemFires(condition, item, owner)` compares `source` and `address` where given and holds `match`
353
- over `/delivery`, `/source`, `/provider`, `/container`, `/author`, `/has_attachment`,
353
+ over `/delivery`, `/source`, `/container`, `/author`, `/has_attachment`,
354
354
  `/headers/<name>` and `/json/<pointer>`, unknown for an item with no JSON. `prosePaths(facts)` lists
355
355
  the prose and section paths whose text builds `changed`; `pointed(value, pointer)` reads a JSON
356
356
  Pointer, `undefined` where nothing is; `dated(value)` checks a `YYYY-MM-DD` date, and
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAqCF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CA+BrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AA+BF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CA8BrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
package/dist/blocks.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fenceSpans } from './links.js';
1
+ import { fenceSpans, spanCursor } from './links.js';
2
2
  const HEADING = /^(#{1,6})(?!#)[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/;
3
3
  function lineAt(content, from, to) {
4
4
  const nl = content.indexOf('\n', from);
@@ -7,17 +7,11 @@ function lineAt(content, from, to) {
7
7
  return { text: raw.endsWith('\r') ? raw.slice(0, -1) : raw, next: end === to ? to : end + 1 };
8
8
  }
9
9
  function scan(content, from, to, visit) {
10
- const fences = fenceSpans(content.slice(from, to));
10
+ const fenced = spanCursor(fenceSpans(content.slice(from, to)));
11
11
  let i = from;
12
12
  while (i < to) {
13
13
  const { text, next } = lineAt(content, i, to);
14
- const at = i - from;
15
- visit({
16
- text,
17
- start: i,
18
- next,
19
- fenced: fences.some(([start, end]) => at >= start && at < end),
20
- });
14
+ visit({ text, start: i, next, fenced: fenced(i - from) !== undefined });
21
15
  if (next === i)
22
16
  break;
23
17
  i = next;
@@ -26,16 +20,15 @@ function scan(content, from, to, visit) {
26
20
  const HASH = 0x23;
27
21
  export function headingLines(content, from, to) {
28
22
  const found = [];
29
- let fences = null;
23
+ let fenced = null;
30
24
  let i = from;
31
25
  while (i < to) {
32
26
  const nl = content.indexOf('\n', i);
33
27
  const end = nl === -1 || nl >= to ? to : nl;
34
28
  const next = end === to ? to : end + 1;
35
29
  if (content.charCodeAt(i) === HASH) {
36
- fences ??= fenceSpans(content.slice(from, to));
37
- const at = i - from;
38
- if (!fences.some(([start, stop]) => at >= start && at < stop)) {
30
+ fenced ??= spanCursor(fenceSpans(content.slice(from, to)));
31
+ if (fenced(i - from) === undefined) {
39
32
  const { text } = lineAt(content, i, to);
40
33
  const match = HEADING.exec(text);
41
34
  const hashes = match?.[1];
@@ -120,7 +120,6 @@ export type ItemFacts = {
120
120
  readonly source: string | null;
121
121
  readonly address: string | null;
122
122
  readonly has_attachment: boolean;
123
- readonly provider: string | null;
124
123
  readonly container: string | null;
125
124
  readonly author: string | null;
126
125
  readonly headers: Readonly<Record<string, string>>;
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../src/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,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,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIrD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgC1D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAehE;AAiJD,wBAAgB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAExF;AAyFD,wBAAgB,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAehG;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3F"}
package/dist/condition.js CHANGED
@@ -300,13 +300,11 @@ function readItem(item, path) {
300
300
  ? item.delivery
301
301
  : path === '/source'
302
302
  ? item.source
303
- : path === '/provider'
304
- ? item.provider
305
- : path === '/container'
306
- ? item.container
307
- : path === '/author'
308
- ? item.author
309
- : null;
303
+ : path === '/container'
304
+ ? item.container
305
+ : path === '/author'
306
+ ? item.author
307
+ : null;
310
308
  return value === null ? undefined : single({ kind: 'string', value });
311
309
  }
312
310
  function wanted(value, owner) {
@@ -29,12 +29,26 @@ export type Shape = {
29
29
  readonly schema: Readonly<Record<string, unknown>>;
30
30
  readonly defs: Readonly<Record<string, unknown>>;
31
31
  };
32
+ export type RuleValue = string | number | boolean | null;
33
+ export type Transition = {
34
+ readonly from: RuleValue;
35
+ readonly to: RuleValue;
36
+ readonly roles?: readonly string[];
37
+ };
38
+ export type FieldRules = {
39
+ readonly changeRoles?: readonly string[];
40
+ readonly initialRoles?: readonly string[];
41
+ readonly transitions?: readonly Transition[];
42
+ };
32
43
  export type Definition = {
33
44
  readonly name: string;
34
45
  readonly memberDocument: boolean;
35
46
  readonly frontmatter: ValueFacts;
36
47
  readonly fields: Readonly<Record<string, ValueFacts>>;
37
48
  readonly sections: Readonly<Record<string, SectionSpec>>;
49
+ readonly rules: Readonly<Record<string, FieldRules>>;
50
+ readonly createRoles?: readonly string[];
51
+ readonly deleteRoles?: readonly string[];
38
52
  readonly shape: Shape;
39
53
  };
40
54
  export type Failure = {
@@ -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,OA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EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAKlF;AAED,MAAM,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;AAsPD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAiChE"}
@@ -12,6 +12,18 @@ 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;
@@ -538,21 +550,134 @@ function deepFreeze(value) {
538
550
  }
539
551
  return value;
540
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
+ }
541
652
  function readType(name, value, context) {
542
653
  const at = `/${escapePointer(name)}`;
543
654
  if (!isRecord(value))
544
655
  return refuse('schema', at);
545
- const { sections: declared, member_document: mark, ...schema } = value;
656
+ const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
546
657
  if (mark !== undefined && typeof mark !== 'boolean')
547
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`);
548
663
  const read = declared === undefined
549
664
  ? { sections: Object.create(null) }
550
665
  : readSections(declared, `${at}/sections`, context);
551
666
  if ('failure' in read)
552
667
  return read.failure;
668
+ const { schema, written } = unruled(ruled);
553
669
  const failure = schemaFailure(schema, at, context);
554
670
  if (failure !== undefined)
555
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
+ }
556
681
  const memberDocument = mark === true;
557
682
  const root = valueFacts(schema, context.defs);
558
683
  const fields = Object.assign(Object.create(null), root.properties);
@@ -560,13 +685,20 @@ function readType(name, value, context) {
560
685
  fields[MEMBER_FIELD] = { type: 'string', prose: false };
561
686
  const defs = Object.create(null);
562
687
  reachedDefs(value, context.defs, defs);
688
+ const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
563
689
  return {
564
690
  name,
565
691
  memberDocument,
566
692
  frontmatter: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
567
693
  fields,
568
694
  sections: read.sections,
569
- shape: { schema: value, defs },
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
+ },
570
702
  };
571
703
  }
572
704
  function lineAt(text, offset) {
@@ -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,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
- 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,
@@ -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,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;AAqMD,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,EA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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"}
package/dist/document.js CHANGED
@@ -179,35 +179,38 @@ function destinationText(to, bracketed) {
179
179
  return `<${to}>`;
180
180
  return null;
181
181
  }
182
- function relinked(content, bodyStart, href, to) {
183
- const written = retarget(href, to);
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
+ }
184
193
  let rewritten = '';
185
194
  let cursor = 0;
186
- for (const match of hrefOccurrences(content.slice(bodyStart))) {
187
- if (match.href !== href)
195
+ for (const match of occurrences) {
196
+ const to = written.get(match.href);
197
+ if (to === undefined)
188
198
  continue;
189
- const text = destinationText(written, match.bracketed);
190
- if (text === null)
191
- return refuse('', 'unwritable-link', written);
192
199
  rewritten += content.slice(cursor, bodyStart + match.start);
193
- rewritten += text;
200
+ rewritten += destinationText(to, match.bracketed);
194
201
  cursor = bodyStart + match.end;
195
202
  }
196
203
  return rewritten + content.slice(cursor);
197
204
  }
198
205
  function shellRelinked(content, bodyStart, file, handle) {
199
- const hrefs = new Set(hrefOccurrences(content.slice(bodyStart)).map(({ href }) => href));
200
- let held = content;
201
- for (const href of hrefs) {
206
+ const occurrences = hrefOccurrences(content.slice(bodyStart));
207
+ const written = new Map();
208
+ for (const href of new Set(occurrences.map((occurrence) => occurrence.href))) {
202
209
  const path = shellTarget(href, handle);
203
- if (path === null)
204
- continue;
205
- const text = relinked(held, bodyStart, href, relative(file, path));
206
- if (typeof text !== 'string')
207
- return text;
208
- held = text;
210
+ if (path !== null)
211
+ written.set(href, retarget(href, relative(file, path)));
209
212
  }
210
- return held;
213
+ return relinked(content, bodyStart, occurrences, written);
211
214
  }
212
215
  function reparsed(document, content) {
213
216
  if (typeof content !== 'string')
@@ -222,9 +225,10 @@ function reparsed(document, content) {
222
225
  function applyLink(document, href, to) {
223
226
  const content = document.content;
224
227
  const bodyStart = bodyStartOf(content);
225
- if (!hrefOccurrences(content.slice(bodyStart)).some((occurrence) => occurrence.href === href))
228
+ const occurrences = hrefOccurrences(content.slice(bodyStart));
229
+ if (!occurrences.some((occurrence) => occurrence.href === href))
226
230
  return { outcome: 'stale', document };
227
- return reparsed(document, relinked(content, bodyStart, href, to));
231
+ return reparsed(document, relinked(content, bodyStart, occurrences, new Map([[href, retarget(href, to)]])));
228
232
  }
229
233
  function nodeAt(root, pointer) {
230
234
  let node = root;
package/dist/index.d.ts CHANGED
@@ -10,10 +10,10 @@ export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
10
10
  export { project } from './project.js';
11
11
  export { references } from './references.js';
12
12
  export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
13
- export type { Definition, JsonType, PatternFacts, PointerFacts, SectionSpec, Shape, ValueFacts, } from './definition.js';
13
+ export type { Definition, FieldRules, JsonType, PatternFacts, PointerFacts, RuleValue, SectionSpec, Shape, Transition, ValueFacts, } from './definition.js';
14
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, verify } from './validate.js';
15
+ export { checkDocument, resolves, sectionReferences, validate, validating, verify, } from './validate.js';
16
16
  export { VERSION } from './version.js';
17
- export { equalValue, frontmatterValue } from './yaml.js';
17
+ export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
18
18
  export type { FrontmatterValue } from './yaml.js';
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,EAA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EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,KAAK,EACL,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,cAAc,EACd,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,6 @@ export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
8
8
  export { project } from './project.js';
9
9
  export { references } from './references.js';
10
10
  export { ARRAY_INDEX, ATTACHMENT, crossedFacts, escapePointer, itemFacts, memberFacts, pointerFacts, pointerSegments, } from './definition.js';
11
- export { checkDocument, resolves, sectionReferences, validate, verify } from './validate.js';
11
+ export { checkDocument, resolves, sectionReferences, validate, validating, verify, } from './validate.js';
12
12
  export { VERSION } from './version.js';
13
- export { equalValue, frontmatterValue } from './yaml.js';
13
+ export { bodyAfterFrontmatter, equalValue, frontmatterValue } from './yaml.js';
package/dist/links.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare function escapes(text: string, index: number): boolean;
2
+ export declare function spanCursor(spans: readonly (readonly [number, number])[]): (index: number) => number | undefined;
2
3
  export type HrefOccurrence = {
3
4
  readonly href: string;
4
5
  readonly start: number;
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAsgBA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D;AAkMD,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,U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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) {
@@ -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 = spanEndAt(raw, i);
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 spanEndAt(spans, index) {
671
- for (const [start, end] of spans) {
672
- if (index >= start && index < end)
673
- return end;
674
- }
675
- return undefined;
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 skipped = [...raw, ...blocks.map((block) => [block.start, block.end])];
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 = spanEndAt(skipped, i);
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/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;
@@ -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,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3F,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAmCtD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,CASxF;AA4BD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,WAAW,CAyBb;AAED,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CAMZ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
@@ -8,17 +8,25 @@ import { bodyStartOf } from './yaml.js';
8
8
  function internalEdits(content, bodyStart, file, documentTargets) {
9
9
  const inventory = linkInventory(content.slice(bodyStart));
10
10
  const internal = new Set();
11
- const edits = [];
12
- const uses = [...inventory.uses].sort((left, right) => left.end - left.start - (right.end - right.start));
13
- for (const use of uses) {
11
+ const uses = inventory.uses
12
+ .filter((use) => {
14
13
  const resolved = target(file, use.destination.href);
15
- if (resolved === null || !documentTargets.has(resolved))
16
- continue;
14
+ return resolved !== null && documentTargets.has(resolved);
15
+ })
16
+ .sort((left, right) => left.start - right.start);
17
+ const edits = [];
18
+ for (let index = uses.length - 1; index >= 0; index -= 1) {
19
+ const use = uses[index];
17
20
  internal.add(use.destination.start);
18
21
  const label = { start: bodyStart + use.labelStart, end: bodyStart + use.labelEnd };
19
- const inner = edits
20
- .filter((edit) => edit.start >= label.start && edit.end <= label.end)
21
- .sort((left, right) => left.start - right.start);
22
+ const inner = [];
23
+ for (let nested = index + 1; nested < uses.length; nested += 1) {
24
+ const edit = edits[uses.length - 1 - nested];
25
+ if (edit.start >= label.end)
26
+ break;
27
+ if (edit.start >= label.start && edit.end <= label.end)
28
+ inner.push(edit);
29
+ }
22
30
  edits.push({
23
31
  start: bodyStart + use.start,
24
32
  end: bodyStart + use.end,
@@ -32,10 +40,25 @@ function internalEdits(content, bodyStart, file, documentTargets) {
32
40
  }
33
41
  return edits.sort((left, right) => left.start - right.start);
34
42
  }
43
+ export function firstEditFrom(edits, start) {
44
+ let low = 0;
45
+ let high = edits.length;
46
+ while (low < high) {
47
+ const middle = (low + high) >>> 1;
48
+ if (edits[middle].start < start)
49
+ low = middle + 1;
50
+ else
51
+ high = middle;
52
+ }
53
+ return low;
54
+ }
35
55
  export function rangeText(content, range, edits) {
36
56
  let text = '';
37
57
  let cursor = range.start;
38
- for (const edit of edits) {
58
+ for (let index = firstEditFrom(edits, range.start); index < edits.length; index += 1) {
59
+ const edit = edits[index];
60
+ if (edit.start > range.end)
61
+ break;
39
62
  if (edit.start < cursor || edit.end > range.end)
40
63
  continue;
41
64
  text += content.slice(cursor, edit.start) + edit.text;
@@ -4,5 +4,6 @@ export declare function resolves(reference: Reached, typeOf: (path: string) => s
4
4
  export declare function verify(schema: string): ModelVerification;
5
5
  export declare function checkDocument(file: string, content: string, model: VerifiedModel): DocumentCheck;
6
6
  export declare function sectionReferences(file: string, content: string, definition: Definition): readonly Reached[];
7
+ export declare function validating(library: Library, context?: ValidationContext, model?: VerifiedModel): Generator<string, Validation, void>;
7
8
  export declare function validate(library: Library, context?: ValidationContext, model?: VerifiedModel): Validation;
8
9
  //# sourceMappingURL=validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQzF,OAAO,KAAK,EAEV,aAAa,EAEb,OAAO,EACP,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AA6CpB,wBAAgB,QAAQ,CACtB,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,OAAO,CAET;AA8BD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQxD;AA2DD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAmBhG;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,UAAU,GACrB,SAAS,OAAO,EAAE,CAgBpB;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CA+DZ"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQzF,OAAO,KAAK,EAEV,aAAa,EAEb,OAAO,EACP,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AA6CpB,wBAAgB,QAAQ,CACtB,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,OAAO,CAET;AA8BD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQxD;AA2DD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAmBhG;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,UAAU,GACrB,SAAS,OAAO,EAAE,CAgBpB;AAED,wBAAiB,UAAU,CACzB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAyDrC;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,iBAAyC,EAClD,KAAK,GAAE,aAA6B,GACnC,UAAU,CAKZ"}
package/dist/validate.js CHANGED
@@ -154,7 +154,7 @@ export function sectionReferences(file, content, definition) {
154
154
  }
155
155
  return found;
156
156
  }
157
- export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
157
+ export function* validating(library, context = { binaryTargets: [] }, model = { types: {} }) {
158
158
  const binaryTargets = new Set(context.binaryTargets);
159
159
  const binary = (path) => binaryTargets.has(path);
160
160
  const files = Object.keys(library).sort();
@@ -170,6 +170,7 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
170
170
  types.set(file, parsed.document.type ?? BUILT_IN_TYPE);
171
171
  if (instanceType(parsed.document) !== BUILT_IN_TYPE)
172
172
  documents.set(file, parsed.document);
173
+ yield file;
173
174
  }
174
175
  const sectionReferences = new Map();
175
176
  for (const [file, document] of documents) {
@@ -177,8 +178,9 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
177
178
  if ('refusal' in read)
178
179
  return read.refusal;
179
180
  sectionReferences.set(file, read.sections);
181
+ yield file;
180
182
  }
181
- const named = new Map();
183
+ let least;
182
184
  for (const [file, document] of documents) {
183
185
  const definition = definitionOf(document, model);
184
186
  const fields = references(document, definition).map(({ pointer, value, to }) => ({
@@ -198,23 +200,25 @@ export function validate(library, context = { binaryTargets: [] }, model = { typ
198
200
  if (!reaches(reference, typeOf, binary))
199
201
  return refuse(file, 'unresolved-reference', { location });
200
202
  }
201
- named.set(file, [...fields, ...sections]);
202
- }
203
- const absent = new Map();
204
- for (const [file, references] of named) {
205
- for (const { reference } of references) {
203
+ for (const { reference } of [...fields, ...sections]) {
206
204
  if (!missing(reference, typeOf, binary))
207
205
  continue;
208
- const referrers = absent.get(reference.target) ?? [];
209
- referrers.push(file);
210
- absent.set(reference.target, referrers);
206
+ const path = reference.target;
207
+ if (least === undefined || path < least.path)
208
+ least = { path, referrers: [] };
209
+ if (path === least.path && least.referrers.at(-1) !== file)
210
+ least.referrers.push(file);
211
211
  }
212
+ yield file;
212
213
  }
213
- const missingPaths = [...absent.keys()].sort();
214
- if (missingPaths.length > 0) {
215
- const path = missingPaths[0];
216
- const referrers = [...new Set(absent.get(path) ?? [])].sort();
217
- return refuse(path, 'referenced-missing-file', { referrers });
218
- }
214
+ if (least !== undefined)
215
+ return refuse(least.path, 'referenced-missing-file', { referrers: least.referrers });
219
216
  return { verdict: 'accept' };
220
217
  }
218
+ export function validate(library, context = { binaryTargets: [] }, model = { types: {} }) {
219
+ const steps = validating(library, context, model);
220
+ let step = steps.next();
221
+ while (step.done !== true)
222
+ step = steps.next();
223
+ return step.value;
224
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdmodel",
3
- "version": "0.1.0-cad192ab63d5f",
3
+ "version": "0.1.0-cbce4f1da228f",
4
4
  "description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
5
5
  "license": "MIT",
6
6
  "type": "module",