@agentshouse/mdmodel 0.1.0-alpha.1 → 0.1.0-alpha.10

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 (156) hide show
  1. package/README.md +220 -7
  2. package/dist/blocks.d.ts +11 -0
  3. package/dist/blocks.d.ts.map +1 -0
  4. package/dist/blocks.js +63 -0
  5. package/dist/blocks.js.map +1 -0
  6. package/dist/definition.d.ts +8 -6
  7. package/dist/definition.d.ts.map +1 -1
  8. package/dist/definition.js +44 -38
  9. package/dist/definition.js.map +1 -1
  10. package/dist/divide.d.ts +3 -0
  11. package/dist/divide.d.ts.map +1 -0
  12. package/dist/divide.js +363 -0
  13. package/dist/divide.js.map +1 -0
  14. package/dist/document.d.ts +4 -1
  15. package/dist/document.d.ts.map +1 -1
  16. package/dist/document.js +95 -4
  17. package/dist/document.js.map +1 -1
  18. package/dist/index.d.ts +4 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/links.d.ts +25 -1
  23. package/dist/links.d.ts.map +1 -1
  24. package/dist/links.js +289 -48
  25. package/dist/links.js.map +1 -1
  26. package/dist/paths.d.ts +1 -0
  27. package/dist/paths.d.ts.map +1 -1
  28. package/dist/paths.js +5 -0
  29. package/dist/paths.js.map +1 -1
  30. package/dist/profile.js.map +1 -1
  31. package/dist/project.d.ts +21 -0
  32. package/dist/project.d.ts.map +1 -0
  33. package/dist/project.js +158 -0
  34. package/dist/project.js.map +1 -0
  35. package/dist/refuse.js.map +1 -1
  36. package/dist/schema.d.ts.map +1 -1
  37. package/dist/schema.js +16 -38
  38. package/dist/schema.js.map +1 -1
  39. package/dist/sections.d.ts.map +1 -1
  40. package/dist/sections.js +14 -47
  41. package/dist/sections.js.map +1 -1
  42. package/dist/types.d.ts +44 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js.map +1 -1
  45. package/dist/validate.d.ts +2 -2
  46. package/dist/validate.d.ts.map +1 -1
  47. package/dist/validate.js +17 -8
  48. package/dist/validate.js.map +1 -1
  49. package/dist/version.d.ts +1 -1
  50. package/dist/version.d.ts.map +1 -1
  51. package/dist/version.js +1 -1
  52. package/dist/version.js.map +1 -1
  53. package/dist/yaml.d.ts +1 -0
  54. package/dist/yaml.d.ts.map +1 -1
  55. package/dist/yaml.js +6 -4
  56. package/dist/yaml.js.map +1 -1
  57. package/fixtures/README.md +87 -27
  58. package/fixtures/cases/any-without-type/context.json +1 -0
  59. package/fixtures/cases/binary-any-reference/context.json +5 -0
  60. package/fixtures/cases/binary-any-reference/expected.json +7 -0
  61. package/fixtures/cases/binary-any-reference/library/notes/draft.md +6 -0
  62. package/fixtures/cases/binary-any-reference/library/types/note.md +5 -0
  63. package/fixtures/cases/binary-document-collision/context.json +5 -0
  64. package/fixtures/cases/binary-document-collision/expected.json +6 -0
  65. package/fixtures/cases/binary-document-collision/library/notes/draft.md +3 -0
  66. package/fixtures/cases/binary-document-collision/library/types/note.md +3 -0
  67. package/fixtures/cases/binary-link-outside-collection/context.json +6 -0
  68. package/fixtures/cases/binary-link-outside-collection/expected.json +6 -0
  69. package/fixtures/cases/binary-link-outside-collection/library/notes/draft.md +5 -0
  70. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +3 -0
  71. package/fixtures/cases/binary-prototype-reference/context.json +1 -0
  72. package/fixtures/cases/binary-prototype-reference/expected.json +7 -0
  73. package/fixtures/cases/binary-prototype-reference/library/notes/draft.md +6 -0
  74. package/fixtures/cases/binary-prototype-reference/library/types/note.md +5 -0
  75. package/fixtures/cases/binary-typed-reference/context.json +5 -0
  76. package/fixtures/cases/binary-typed-reference/expected.json +7 -0
  77. package/fixtures/cases/binary-typed-reference/library/notes/draft.md +6 -0
  78. package/fixtures/cases/binary-typed-reference/library/types/note.md +5 -0
  79. package/fixtures/cases/binary-typed-reference/library/types/person.md +3 -0
  80. package/fixtures/cases/bracketed-link-definition/context.json +1 -0
  81. package/fixtures/cases/bracketed-link-definition/expected.json +1 -0
  82. package/fixtures/cases/bracketed-link-definition/library/item.md +10 -0
  83. package/fixtures/cases/bracketed-link-definition/library/types/task.md +7 -0
  84. package/fixtures/cases/declared-binary-links/context.json +6 -0
  85. package/fixtures/cases/declared-binary-links/expected.json +1 -0
  86. package/fixtures/cases/declared-binary-links/library/notes/draft.md +7 -0
  87. package/fixtures/cases/declared-binary-links/library/types/note.md +3 -0
  88. package/fixtures/cases/duplicate-link-definition/context.json +1 -0
  89. package/fixtures/cases/duplicate-link-definition/expected.json +1 -0
  90. package/fixtures/cases/duplicate-link-definition/library/item.md +11 -0
  91. package/fixtures/cases/duplicate-link-definition/library/types/task.md +7 -0
  92. package/fixtures/cases/fenced-link-definition/context.json +1 -0
  93. package/fixtures/cases/fenced-link-definition/expected.json +1 -0
  94. package/fixtures/cases/fenced-link-definition/library/item.md +12 -0
  95. package/fixtures/cases/fenced-link-definition/library/types/task.md +7 -0
  96. package/fixtures/cases/field-enum/context.json +1 -0
  97. package/fixtures/cases/interrupted-link-definition/context.json +1 -0
  98. package/fixtures/cases/interrupted-link-definition/expected.json +1 -0
  99. package/fixtures/cases/interrupted-link-definition/library/notes/draft.md +8 -0
  100. package/fixtures/cases/interrupted-link-definition/library/types/note.md +3 -0
  101. package/fixtures/cases/long-fence-link-definition/context.json +1 -0
  102. package/fixtures/cases/long-fence-link-definition/expected.json +1 -0
  103. package/fixtures/cases/long-fence-link-definition/library/notes/draft.md +9 -0
  104. package/fixtures/cases/long-fence-link-definition/library/types/note.md +3 -0
  105. package/fixtures/cases/malformed-definition/context.json +1 -0
  106. package/fixtures/cases/missing-binary-image/context.json +6 -0
  107. package/fixtures/cases/missing-binary-image/expected.json +6 -0
  108. package/fixtures/cases/missing-binary-image/library/notes/draft.md +5 -0
  109. package/fixtures/cases/missing-binary-image/library/types/note.md +3 -0
  110. package/fixtures/cases/missing-binary-link/context.json +6 -0
  111. package/fixtures/cases/missing-binary-link/expected.json +6 -0
  112. package/fixtures/cases/missing-binary-link/library/notes/draft.md +5 -0
  113. package/fixtures/cases/missing-binary-link/library/types/note.md +3 -0
  114. package/fixtures/cases/missing-required-field/context.json +1 -0
  115. package/fixtures/cases/missing-section-item-kind/context.json +1 -0
  116. package/fixtures/cases/missing-section-item-kind/expected.json +7 -0
  117. package/fixtures/cases/missing-section-item-kind/library/types/task.md +7 -0
  118. package/fixtures/cases/paragraph-link-definition/context.json +5 -0
  119. package/fixtures/cases/paragraph-link-definition/expected.json +1 -0
  120. package/fixtures/cases/paragraph-link-definition/library/notes/draft.md +10 -0
  121. package/fixtures/cases/paragraph-link-definition/library/types/note.md +3 -0
  122. package/fixtures/cases/prd-definition/context.json +1 -0
  123. package/fixtures/cases/prd-definition/library/types/task.md +2 -1
  124. package/fixtures/cases/prototype-field/context.json +1 -0
  125. package/fixtures/cases/prototype-field/expected.json +7 -0
  126. package/fixtures/cases/prototype-field/library/item.md +9 -0
  127. package/fixtures/cases/prototype-field/library/types/task.md +7 -0
  128. package/fixtures/cases/quoted-link-definition/context.json +1 -0
  129. package/fixtures/cases/quoted-link-definition/expected.json +6 -0
  130. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +7 -0
  131. package/fixtures/cases/quoted-link-definition/library/types/note.md +3 -0
  132. package/fixtures/cases/referenced-missing-file/context.json +1 -0
  133. package/fixtures/cases/structured-section/context.json +1 -0
  134. package/fixtures/cases/structured-section/library/types/task.md +1 -1
  135. package/fixtures/cases/truncated-link-definition/context.json +1 -0
  136. package/fixtures/cases/truncated-link-definition/expected.json +6 -0
  137. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +7 -0
  138. package/fixtures/cases/truncated-link-definition/library/notes/other.md +5 -0
  139. package/fixtures/cases/truncated-link-definition/library/types/note.md +3 -0
  140. package/fixtures/cases/unclosed-frontmatter/context.json +1 -0
  141. package/fixtures/cases/undeclared-field/context.json +1 -0
  142. package/fixtures/cases/undeclared-field/expected.json +7 -0
  143. package/fixtures/cases/undeclared-field/library/item.md +9 -0
  144. package/fixtures/cases/undeclared-field/library/types/task.md +7 -0
  145. package/fixtures/cases/unresolved-link/context.json +1 -0
  146. package/fixtures/cases/valid-typed-document/context.json +1 -0
  147. package/fixtures/cases/valid-typed-document/library/tasks/one.md +1 -0
  148. package/fixtures/cases/valid-typed-document/library/types/task.md +2 -1
  149. package/fixtures/cases/wide-item-fence-link/context.json +1 -0
  150. package/fixtures/cases/wide-item-fence-link/expected.json +1 -0
  151. package/fixtures/cases/wide-item-fence-link/library/notes/draft.md +7 -0
  152. package/fixtures/cases/wide-item-fence-link/library/types/note.md +3 -0
  153. package/fixtures/division.json +415 -0
  154. package/fixtures/preamble.json +107 -0
  155. package/fixtures/projection.json +186 -0
  156. package/package.json +4 -5
package/README.md CHANGED
@@ -5,7 +5,10 @@ deterministic application of one structured change to Document content, the
5
5
  Markdown syntax profile, and the conformance fixtures.
6
6
 
7
7
  The package runs in a browser and in Node. It makes no network call and reads
8
- no filesystem on its own. Callers pass Library state as path-to-content.
8
+ no filesystem on its own. Callers pass text Library state as path-to-content and declare retained binary
9
+ link targets separately in a `ValidationContext`.
10
+ The public root exposes one ESM artifact. Node 24.21.0 and later can load it
11
+ through either `import` or `require`; browser bundlers consume the same artifact.
9
12
 
10
13
  ## Install
11
14
 
@@ -13,21 +16,31 @@ no filesystem on its own. Callers pass Library state as path-to-content.
13
16
  npm install @agentshouse/mdmodel
14
17
  ```
15
18
 
16
- The first prerelease is published after the User confirms.
19
+ Package releases are published after the User confirms.
17
20
 
18
21
  ## API
19
22
 
20
23
  ```ts
21
24
  import {
22
25
  apply,
26
+ divide,
27
+ links,
23
28
  MARKDOWN_SYNTAX_PROFILE,
24
29
  parse,
30
+ project,
25
31
  serialize,
26
32
  validate,
27
33
  VERSION,
28
34
  } from '@agentshouse/mdmodel';
29
35
 
30
36
  validate({ 'note.md': '# Hello\n' });
37
+ validate(
38
+ {
39
+ 'types/note.md': '---\ntype: definition\n---\n',
40
+ 'note.md': '---\ntype: note\n---\n![Figure](assets/figure.png)\n',
41
+ },
42
+ { binaryTargets: ['assets/figure.png'] },
43
+ );
31
44
  const parsed = parse(content);
32
45
  if (parsed.ok) {
33
46
  const next = apply(parsed.document, {
@@ -37,14 +50,214 @@ if (parsed.ok) {
37
50
  prior: 'Hello',
38
51
  });
39
52
  if (next.outcome === 'applied') serialize(next.document);
53
+ for (const link of links(parsed.document, 'tasks/two.md')) {
54
+ if (link.target !== 'data/export.csv') continue;
55
+ const moved = apply(parsed.document, {
56
+ kind: 'link',
57
+ href: link.href,
58
+ to: '../files/export.csv',
59
+ });
60
+ if (moved.outcome === 'applied') serialize(moved.document);
61
+ }
40
62
  }
41
63
  ```
42
64
 
43
- `validate` takes one Library state and returns acceptance or one refusal
44
- naming the file, the field or section, the violated rule, and `VERSION`.
45
- `apply` sets one typed field, including a list field as a whole, or replaces
46
- one declared section body against that value's prior content. A field change
47
- does not reformat the rest of the file.
65
+ `validate(library, context?)` takes the resulting text Library and one
66
+ `ValidationContext` containing `binaryTargets: readonly string[]`. Omitting the
67
+ context declares no binary targets. Library keys and binary targets use the
68
+ same collection-relative path namespace; callers supply canonical paths, and
69
+ a path declared as both text and binary is refused. Ordinary links and images
70
+ in typed Documents may resolve to either membership, including relative
71
+ normalization from the source Document. A binary target supplies no Document
72
+ or MD Type and cannot satisfy a typed reference, including one to `any`.
73
+ The existing `any` Document rules are unchanged.
74
+
75
+ A typed Document carries only the frontmatter fields its MD type declares, so
76
+ any other field is refused as `undeclared-field` at that field name. A field
77
+ name YAML carries to a record prototype, `__proto__` among them, is an ordinary
78
+ undeclared field and is refused as one. A declared list section is validated as
79
+ a list; its declared item kind governs projection eligibility rather than the
80
+ value of each item, which validation reads no further than that list form.
81
+ Validation returns acceptance or one refusal naming the file, the field or
82
+ section, the violated rule, and `VERSION`. Every caller operation that validates
83
+ a resulting collection supplies that collection's context to this same
84
+ `validate` function. `parse`, `apply`, and `serialize` operate on a single text
85
+ Document; they do not validate collection membership or consume binary bytes.
86
+ `apply` sets one typed field, including a list field as a whole, replaces
87
+ one existing section body or the preamble against that value's prior content,
88
+ or rewrites one Markdown link destination. A section need not be declared by
89
+ the Document's MD Type to be replaced. A field change does not reformat the rest of the file.
90
+
91
+ `Document.preamble` is a readonly string containing the exact source after
92
+ frontmatter and before the first section heading recognized by the existing
93
+ section parser. Without a section it is the entire post-frontmatter body;
94
+ without frontmatter it starts at the beginning of the Document. An empty span
95
+ is `''`. It includes whitespace, newlines, a leading H1, and any fenced text
96
+ before the first section. The closing frontmatter delimiter and its line ending
97
+ belong to frontmatter. Section recognition and the syntax profile are unchanged.
98
+
99
+ ```ts
100
+ const parsed = parse(content);
101
+ if (parsed.ok) {
102
+ const change = {
103
+ kind: 'preamble' as const,
104
+ prior: parsed.document.preamble,
105
+ value: 'Updated introduction.\n\n',
106
+ };
107
+ const result = apply(parsed.document, change);
108
+ if (result.outcome === 'applied') serialize(result.document);
109
+ }
110
+ ```
111
+
112
+ `apply(document, { kind: 'preamble', prior, value })` compares `prior` to the
113
+ current preamble exactly. A mismatch returns `{ outcome: 'stale', document }`
114
+ with the unchanged current Document. A match replaces only that source span,
115
+ then parses a new immutable Document; the original is unchanged. Frontmatter
116
+ and section source outside the span retain their exact bytes, including newline
117
+ and heading syntax. As with section replacement, `value` is literal source:
118
+ no newline or separator is inserted, and the resulting source is parsed again.
119
+ An invalid frontmatter result receives the existing parse refusal. Independent
120
+ field, section, and preamble edits keep their own prior values valid.
121
+
122
+ For a moved link, use `links` and the `link` change below to obtain the rewritten
123
+ Document, then compare its public `preamble` and `sections` to the original.
124
+ Submit the changed values with their original priors. Consumers need no source
125
+ span calculation or private Model import. Collection validation remains a
126
+ separate call against the resulting Library.
127
+
128
+ `links(document, file)` is the inventory of that Document's ordinary link and
129
+ image destinations that resolve to a collection Path, each with the destination
130
+ `href` exactly as written and the `target` Path it resolves to relative to
131
+ `file`. A `?query` or `#fragment` the destination carries is part of `href` and
132
+ not part of `target`. Entries are ordered by the position of the destination
133
+ text a rewrite would change, and one destination written the same way appears
134
+ once however many times it occurs. A destination that the syntax profile does not read as a
135
+ link, one that is empty, a bare fragment, or carries a URL scheme, and one that
136
+ leaves the collection are not in the inventory. Frontmatter field values,
137
+ including typed references, are not link destinations and are never enumerated.
138
+
139
+ `apply(document, { kind: 'link', href, to })` rewrites every body occurrence of
140
+ that written destination and changes nothing else, so a caller that moves a Path
141
+ rewrites its referring Documents without a second Markdown parser. `to` is the
142
+ Path the destination must resolve to instead; the `?query` or `#fragment` the
143
+ written destination carried is not part of that Path and is kept. A Document
144
+ that does not carry the destination is `stale`. A reference definition is
145
+ rewritten once however many uses name it. The destination is
146
+ written in the form the syntax profile reads back: bare when it carries no
147
+ whitespace, does not open with `<`, and balances its parentheses, otherwise
148
+ inside angle brackets, which the original form is kept in when it still fits. A
149
+ destination that neither form can carry is refused as `unwritable-link`.
150
+
151
+ `project(document, file, context?)` is the Embedding projection input of one
152
+ Document: the prose a consumer embeds, with every internal Markdown-document
153
+ link reduced to the label a reader sees. A Document that declares no MD type
154
+ contributes its body after the frontmatter fence. A Document that declares one
155
+ contributes its free-text field values, its preamble, and every H2 section its
156
+ MD type does not declare as structure, each section with its own heading line
157
+ and every occurrence of a repeated name, in the order the Document carries
158
+ them. A declared free-text section, a declared list section whose items are
159
+ free text, and a section the MD type does not declare at all are all inside
160
+ that input; a declared list section of any other item kind is not, so
161
+ eligibility follows the declared kind rather than the form the author wrote.
162
+ Each free-text field value is projected bare, without its field name and
163
+ followed by a blank line, in the order the MD Type declares its fields, and
164
+ every item of a free-text list field is one such value, projected as the author
165
+ wrote it: the link inventory reads the body, so link syntax inside a
166
+ frontmatter value is text like any other. The Document's Path and its typed
167
+ fields of every other kind stay outside that input.
168
+
169
+ ```ts
170
+ const parsed = parse(content);
171
+ if (parsed.ok) {
172
+ const projected = project(parsed.document, 'tasks/two.md', {
173
+ documentTargets: ['plans/q3.md', 'people/ana.md'],
174
+ definition: types['types/task.md'],
175
+ });
176
+ if (projected.ok) embed(projected.text);
177
+ }
178
+ ```
179
+
180
+ `ProjectionContext` carries `documentTargets`, the collection-relative Paths the
181
+ caller holds as Markdown documents, and `definition`, the source of the MD Type
182
+ definition Document the Document's `type` names. A Document that declares a type
183
+ the caller supplies no definition for is refused as `unknown-type`, and a
184
+ definition source the model cannot read carries its own refusal naming
185
+ `types/<type>.md`. `documentTargets` is what makes a destination internal: a
186
+ destination resolving to a supplied Path is internal, and every other
187
+ destination stays authored text, a retained binary target and a Path nobody
188
+ supplied alike. The caller supplies that membership, as it does for `validate`;
189
+ the model reads no bytes, resolves no authority, and classifies nothing it was
190
+ not given.
191
+
192
+ An internal link contributes its visible label and no destination, fragment, or
193
+ title, in the inline `[label](path)`, full `[label][id]`, and collapsed
194
+ `[label][]` forms, and the link reference definition an enumerated use resolves
195
+ through leaves the projection with it. An image at a supplied document target
196
+ contributes its alt text the same way, because a move rewrites that destination
197
+ too. External URLs, retained binary targets, unsupplied destinations, bare
198
+ fragments, code spans, fenced code, and escaped syntax stay exactly as authored,
199
+ read through the same syntax profile `links` and `validate` read. `project`
200
+ returns text and never rewrites the Document.
201
+
202
+ Because a moved Path changes destinations alone, applying a `link` change leaves
203
+ the projection of every Document it rewrites byte-identical, while a changed
204
+ visible label changes it. `fixtures/projection.json` carries every move row of
205
+ that corpus; the label change is proven at this package's own `project` seam.
206
+
207
+ `divide(document, file, context)` divides that same Embedding projection input
208
+ into ordered Spans under the budget the caller supplies. Each Span carries the
209
+ `text` to embed and the `start` and `end` of the extent it addresses in the
210
+ Document's own source, as UTF-8 byte offsets into that source and never string
211
+ positions, so a caller stores the extent and hydrates the text it shows from
212
+ the Document itself.
213
+
214
+ ```ts
215
+ const parsed = parse(content);
216
+ if (parsed.ok) {
217
+ const divided = divide(parsed.document, 'tasks/two.md', {
218
+ documentTargets: ['plans/q3.md', 'people/ana.md'],
219
+ definition: types['types/task.md'],
220
+ budget: 2000,
221
+ });
222
+ if (divided.ok) for (const span of divided.spans) embed(span.text);
223
+ }
224
+ ```
225
+
226
+ `DivisionContext` is a `ProjectionContext` and one `budget`, the greatest number
227
+ of characters a Span's embedded text may carry, counted the way JavaScript
228
+ counts a string's length and not in the bytes the extent is measured in. A
229
+ bound cut inside one sentence carries a character whole rather than dividing
230
+ it, so such a Span may run one unit past the budget. The budget is the caller's
231
+ number alone: the model holds no tokenizer, counts nothing else, and refuses no
232
+ input for being too long. A Document the caller supplies no definition for
233
+ carries the same `unknown-type` refusal `project` returns.
234
+
235
+ The division descends one level at a time, and only into the piece that does not
236
+ fit: the whole input, a heading node, adjacent sibling nodes packed under one
237
+ parent, adjacent blocks inside a node, sentences inside a block, and a bound cut
238
+ inside a single sentence. A Span covers whole heading nodes or one contiguous
239
+ piece inside a single node, never a partial node beside another. A Span that
240
+ continues a node repeats that node's own heading line, projected like any other
241
+ text and so carrying an internal link's label rather than its destination, and
242
+ never an ancestor's heading, so renaming a heading costs what editing that
243
+ heading's own body costs. A heading the budget cannot hold beside any text is
244
+ not repeated, and a heading with no body of its own leads its first child node
245
+ rather than standing as a Span of nothing but itself. Overlap exists at the
246
+ sentence level alone, where each Span after the first repeats its predecessor's
247
+ last sentence whenever the budget holds both; when it cannot hold both, the
248
+ Span carries its own sentence alone. An untyped input arrives without a
249
+ definition and descends the same ladder.
250
+
251
+ Division is total: every authored character of the input belongs to at least one
252
+ Span, and an input carrying no authored text divides into no Span at all. A
253
+ Span's extent is the smallest range of the source that contains everything the
254
+ Span covers, so it spans what the input excludes between two eligible pieces,
255
+ and the extent addresses the authored source where the embedded text carries a
256
+ repeated heading, an internal link's visible label, or a frontmatter value the
257
+ author quoted. A Span divided out of one free-text field value addresses that
258
+ whole value, because a YAML scalar's own positions are the only ones its source
259
+ has, and a Span carrying part of one internal link's label addresses that whole
260
+ link, because a cut never falls inside link syntax.
48
261
 
49
262
  ## Fixtures
50
263
 
@@ -0,0 +1,11 @@
1
+ import type { Extent } from './types.js';
2
+ export type HeadingLine = {
3
+ readonly level: number;
4
+ readonly name: string;
5
+ readonly start: number;
6
+ readonly textEnd: number;
7
+ readonly next: number;
8
+ };
9
+ export declare function headingLines(content: string, from: number, to: number): HeadingLine[];
10
+ export declare function blockRanges(content: string, from: number, to: number): Extent[];
11
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +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;AAmCF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CAiBrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
package/dist/blocks.js ADDED
@@ -0,0 +1,63 @@
1
+ import { fenceSpans } from './links.js';
2
+ const HEADING = /^(#{1,6})(?!#)[ \t]+(.+?)[ \t]*#*[ \t]*$/;
3
+ function lineAt(content, from, to) {
4
+ const nl = content.indexOf('\n', from);
5
+ const end = nl === -1 || nl >= to ? to : nl;
6
+ const raw = content.slice(from, end);
7
+ return {
8
+ text: raw.endsWith('\r') ? raw.slice(0, -1) : raw,
9
+ next: end === to ? to : end + 1
10
+ };
11
+ }
12
+ function scan(content, from, to, visit) {
13
+ const fences = fenceSpans(content.slice(from, to));
14
+ let i = from;
15
+ while(i < to){
16
+ const { text, next } = lineAt(content, i, to);
17
+ const at = i - from;
18
+ visit({
19
+ text,
20
+ start: i,
21
+ next,
22
+ fenced: fences.some(([start, end])=>at >= start && at < end)
23
+ });
24
+ if (next === i) break;
25
+ i = next;
26
+ }
27
+ }
28
+ export function headingLines(content, from, to) {
29
+ const found = [];
30
+ scan(content, from, to, (line)=>{
31
+ if (line.fenced) return;
32
+ const match = HEADING.exec(line.text);
33
+ const hashes = match?.[1];
34
+ const name = match?.[2];
35
+ if (hashes === undefined || name === undefined) return;
36
+ found.push({
37
+ level: hashes.length,
38
+ name: name.trim(),
39
+ start: line.start,
40
+ textEnd: line.start + line.text.length,
41
+ next: line.next
42
+ });
43
+ });
44
+ return found;
45
+ }
46
+ export function blockRanges(content, from, to) {
47
+ const starts = [];
48
+ let open = false;
49
+ scan(content, from, to, (line)=>{
50
+ if (!line.fenced && line.text.trim() === '') {
51
+ open = false;
52
+ return;
53
+ }
54
+ if (!open) starts.push(line.start);
55
+ open = true;
56
+ });
57
+ return starts.map((start, index)=>({
58
+ start: index === 0 ? from : start,
59
+ end: starts[index + 1] ?? to
60
+ }));
61
+ }
62
+
63
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/blocks.ts"],"sourcesContent":["import { fenceSpans } from './links.js';\nimport type { Extent } from './types.js';\n\nexport type HeadingLine = {\n readonly level: number;\n readonly name: string;\n readonly start: number;\n readonly textEnd: number;\n readonly next: number;\n};\n\ntype Line = {\n readonly text: string;\n readonly start: number;\n readonly next: number;\n readonly fenced: boolean;\n};\n\nconst HEADING = /^(#{1,6})(?!#)[ \\t]+(.+?)[ \\t]*#*[ \\t]*$/;\n\nfunction lineAt(content: string, from: number, to: number): { text: string; next: number } {\n const nl = content.indexOf('\\n', from);\n const end = nl === -1 || nl >= to ? to : nl;\n const raw = content.slice(from, end);\n return { text: raw.endsWith('\\r') ? raw.slice(0, -1) : raw, next: end === to ? to : end + 1 };\n}\n\nfunction scan(content: string, from: number, to: number, visit: (line: Line) => void): void {\n const fences = fenceSpans(content.slice(from, to));\n let i = from;\n while (i < to) {\n const { text, next } = lineAt(content, i, to);\n const at = i - from;\n visit({\n text,\n start: i,\n next,\n fenced: fences.some(([start, end]) => at >= start && at < end),\n });\n if (next === i) break;\n i = next;\n }\n}\n\nexport function headingLines(content: string, from: number, to: number): HeadingLine[] {\n const found: HeadingLine[] = [];\n scan(content, from, to, (line) => {\n if (line.fenced) return;\n const match = HEADING.exec(line.text);\n const hashes = match?.[1];\n const name = match?.[2];\n if (hashes === undefined || name === undefined) return;\n found.push({\n level: hashes.length,\n name: name.trim(),\n start: line.start,\n textEnd: line.start + line.text.length,\n next: line.next,\n });\n });\n return found;\n}\n\nexport function blockRanges(content: string, from: number, to: number): Extent[] {\n const starts: number[] = [];\n let open = false;\n scan(content, from, to, (line) => {\n if (!line.fenced && line.text.trim() === '') {\n open = false;\n return;\n }\n if (!open) starts.push(line.start);\n open = true;\n });\n return starts.map((start, index) => ({\n start: index === 0 ? from : start,\n end: starts[index + 1] ?? to,\n }));\n}\n"],"names":["fenceSpans","HEADING","lineAt","content","from","to","nl","indexOf","end","raw","slice","text","endsWith","next","scan","visit","fences","i","at","start","fenced","some","headingLines","found","line","match","exec","hashes","name","undefined","push","level","length","trim","textEnd","blockRanges","starts","open","map","index"],"mappings":"AAAA,SAASA,UAAU,QAAQ,aAAa;AAkBxC,MAAMC,UAAU;AAEhB,SAASC,OAAOC,OAAe,EAAEC,IAAY,EAAEC,EAAU;IACvD,MAAMC,KAAKH,QAAQI,OAAO,CAAC,MAAMH;IACjC,MAAMI,MAAMF,OAAO,CAAC,KAAKA,MAAMD,KAAKA,KAAKC;IACzC,MAAMG,MAAMN,QAAQO,KAAK,CAACN,MAAMI;IAChC,OAAO;QAAEG,MAAMF,IAAIG,QAAQ,CAAC,QAAQH,IAAIC,KAAK,CAAC,GAAG,CAAC,KAAKD;QAAKI,MAAML,QAAQH,KAAKA,KAAKG,MAAM;IAAE;AAC9F;AAEA,SAASM,KAAKX,OAAe,EAAEC,IAAY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AI,CAACA,MAAMD,OAAON,IAAI,CAACN,KAAKL,KAAK;QACjCkB,OAAO;IACT;IACA,OAAOD,OAAOE,GAAG,CAAC,CAACnB,OAAOoB,QAAW,CAAA;YACnCpB,OAAOoB,UAAU,IAAInC,OAAOe;YAC5BX,KAAK4B,MAAM,CAACG,QAAQ,EAAE,IAAIlC;QAC5B,CAAA;AACF"}
@@ -1,5 +1,9 @@
1
1
  import type { Document, Refusal } from './types.js';
2
- export type ScalarSpec = {
2
+ export type TextSpec = {
3
+ readonly kind: 'text';
4
+ readonly required: boolean;
5
+ };
6
+ export type ScalarSpec = TextSpec | {
3
7
  readonly kind: 'string';
4
8
  readonly required: boolean;
5
9
  } | {
@@ -17,15 +21,13 @@ export type ScalarSpec = {
17
21
  readonly required: boolean;
18
22
  readonly to: string;
19
23
  };
20
- export type FieldSpec = ScalarSpec | {
24
+ export type ListSpec = {
21
25
  readonly kind: 'list';
22
26
  readonly required: boolean;
23
27
  readonly of: ScalarSpec;
24
28
  };
25
- export type SectionSpec = {
26
- readonly kind: 'text' | 'list';
27
- readonly required: boolean;
28
- };
29
+ export type FieldSpec = ScalarSpec | ListSpec;
30
+ export type SectionSpec = TextSpec | ListSpec;
29
31
  export type Definition = {
30
32
  readonly name: string;
31
33
  readonly file: string;
@@ -1 +1 @@
1
- {"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,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CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;CAC1D,CAAC;AAsGF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CA6BrF"}
@@ -19,6 +19,7 @@ function stringList(value) {
19
19
  return value;
20
20
  }
21
21
  const SCALAR_KINDS = new Set([
22
+ 'text',
22
23
  'string',
23
24
  'number',
24
25
  'date',
@@ -27,6 +28,10 @@ const SCALAR_KINDS = new Set([
27
28
  ]);
28
29
  function parseScalar(file, location, spec, required) {
29
30
  const kind = spec.kind;
31
+ if (kind === 'text') return {
32
+ kind: 'text',
33
+ required
34
+ };
30
35
  if (kind === 'string') return {
31
36
  kind: 'string',
32
37
  required
@@ -61,41 +66,42 @@ function parseScalar(file, location, spec, required) {
61
66
  function extraKeys(spec, allowed) {
62
67
  return Object.keys(spec).some((key)=>!allowed.includes(key));
63
68
  }
69
+ function parseList(file, location, spec, required, malformed) {
70
+ if (typeof spec.of !== 'string' || !SCALAR_KINDS.has(spec.of)) {
71
+ return refuse(file, 'definition-list-of', location);
72
+ }
73
+ const allowed = spec.of === 'enum' ? [
74
+ 'kind',
75
+ 'required',
76
+ 'of',
77
+ 'values'
78
+ ] : spec.of === 'reference' ? [
79
+ 'kind',
80
+ 'required',
81
+ 'of',
82
+ 'to'
83
+ ] : [
84
+ 'kind',
85
+ 'required',
86
+ 'of'
87
+ ];
88
+ if (extraKeys(spec, allowed)) return refuse(file, malformed, location);
89
+ const inner = parseScalar(file, location, {
90
+ ...spec,
91
+ kind: spec.of
92
+ }, false);
93
+ if ('rule' in inner) return inner;
94
+ return {
95
+ kind: 'list',
96
+ required,
97
+ of: inner
98
+ };
99
+ }
64
100
  function parseField(file, location, value) {
65
101
  if (!isRecord(value) || typeof value.kind !== 'string') return refuse(file, 'definition-field', location);
66
102
  const required = requiredFlag(value.required);
67
103
  if (required === undefined) return refuse(file, 'definition-field', location);
68
- if (value.kind === 'list') {
69
- if (typeof value.of !== 'string' || !SCALAR_KINDS.has(value.of)) {
70
- return refuse(file, 'definition-list-of', location);
71
- }
72
- const allowed = value.of === 'enum' ? [
73
- 'kind',
74
- 'required',
75
- 'of',
76
- 'values'
77
- ] : value.of === 'reference' ? [
78
- 'kind',
79
- 'required',
80
- 'of',
81
- 'to'
82
- ] : [
83
- 'kind',
84
- 'required',
85
- 'of'
86
- ];
87
- if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);
88
- const inner = parseScalar(file, location, {
89
- ...value,
90
- kind: value.of
91
- }, false);
92
- if ('rule' in inner) return inner;
93
- return {
94
- kind: 'list',
95
- required,
96
- of: inner
97
- };
98
- }
104
+ if (value.kind === 'list') return parseList(file, location, value, required, 'definition-field');
99
105
  const allowed = value.kind === 'enum' ? [
100
106
  'kind',
101
107
  'required',
@@ -116,14 +122,14 @@ function parseSection(file, location, value) {
116
122
  return refuse(file, 'definition-section-kind', location);
117
123
  }
118
124
  const required = requiredFlag(value.required);
119
- if (required === undefined || extraKeys(value, [
125
+ if (required === undefined) return refuse(file, 'definition-section', location);
126
+ if (value.kind === 'list') return parseList(file, location, value, required, 'definition-section');
127
+ if (extraKeys(value, [
120
128
  'kind',
121
129
  'required'
122
- ])) {
123
- return refuse(file, 'definition-section', location);
124
- }
130
+ ])) return refuse(file, 'definition-section', location);
125
131
  return {
126
- kind: value.kind,
132
+ kind: 'text',
127
133
  required
128
134
  };
129
135
  }
@@ -142,13 +148,13 @@ export function readDefinition(file, document) {
142
148
  if (sectionsValue !== undefined && !isRecord(sectionsValue)) {
143
149
  return refuse(file, 'definition-sections', 'sections');
144
150
  }
145
- const fields = {};
151
+ const fields = Object.create(null);
146
152
  for (const [fieldName, spec] of Object.entries(fieldsValue ?? {})){
147
153
  const parsed = parseField(file, fieldName, spec);
148
154
  if ('rule' in parsed) return parsed;
149
155
  fields[fieldName] = parsed;
150
156
  }
151
- const sections = {};
157
+ const sections = Object.create(null);
152
158
  for (const [sectionName, spec] of Object.entries(sectionsValue ?? {})){
153
159
  const parsed = parseSection(file, sectionName, spec);
154
160
  if ('rule' in parsed) return parsed;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/executor/code/agents.house/mdmodel/packages/mdmodel/src/definition.ts"],"sourcesContent":["import { typeNameFromPath } from './paths.js';\nimport { refusal } from './refuse.js';\nimport type { Document, Refusal } from './types.js';\n\nexport type ScalarSpec =\n | { readonly kind: 'string'; readonly required: boolean }\n | { readonly kind: 'number'; readonly required: boolean }\n | { readonly kind: 'date'; readonly required: boolean }\n | { readonly kind: 'enum'; readonly required: boolean; readonly values: readonly string[] }\n | { readonly kind: 'reference'; readonly required: boolean; readonly to: string };\n\nexport type FieldSpec =\n | ScalarSpec\n | { readonly kind: 'list'; readonly required: boolean; readonly of: ScalarSpec };\n\nexport type SectionSpec = { readonly kind: 'text' | 'list'; readonly required: boolean };\n\nexport type Definition = {\n readonly name: string;\n readonly file: string;\n readonly fields: Readonly<Record<string, FieldSpec>>;\n readonly sections: Readonly<Record<string, SectionSpec>>;\n};\n\nfunction refuse(file: string, rule: string, location?: string): Refusal {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction requiredFlag(value: unknown): boolean | undefined {\n if (value === undefined) return false;\n if (typeof value === 'boolean') return value;\n return undefined;\n}\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value) || value.length === 0) return undefined;\n if (!value.every((item) => typeof item === 'string' && item !== '')) return undefined;\n return value;\n}\n\nconst SCALAR_KINDS = new Set(['string', 'number', 'date', 'enum', 'reference']);\n\nfunction parseScalar(\n file: string,\n location: string,\n spec: Record<string, unknown>,\n required: boolean,\n): ScalarSpec | Refusal {\n const kind = spec.kind;\n if (kind === 'string') return { kind: 'string', required };\n if (kind === 'number') return { kind: 'number', required };\n if (kind === 'date') return { kind: 'date', required };\n if (kind === 'enum') {\n const values = stringList(spec.values);\n if (values === undefined) return refuse(file, 'definition-enum-values', location);\n return { kind: 'enum', required, values };\n }\n if (kind === 'reference') {\n if (typeof spec.to !== 'string' || spec.to === '')\n return refuse(file, 'definition-reference-to', location);\n return { kind: 'reference', required, to: spec.to };\n }\n return refuse(file, 'definition-field-kind', location);\n}\n\nfunction extraKeys(spec: Record<string, unknown>, allowed: readonly string[]): boolean {\n return Object.keys(spec).some((key) => !allowed.includes(key));\n}\n\nfunction parseField(file: string, location: string, value: unknown): FieldSpec | Refusal {\n if (!isRecord(value) || typeof value.kind !== 'string')\n return refuse(file, 'definition-field', location);\n const required = requiredFlag(value.required);\n if (required === undefined) return refuse(file, 'definition-field', location);\n if (value.kind === 'list') {\n if (typeof value.of !== 'string' || !SCALAR_KINDS.has(value.of)) {\n return refuse(file, 'definition-list-of', location);\n }\n const allowed =\n value.of === 'enum'\n ? ['kind', 'required', 'of', 'values']\n : value.of === 'reference'\n ? ['kind', 'required', 'of', 'to']\n : ['kind', 'required', 'of'];\n if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);\n const inner = parseScalar(file, location, { ...value, kind: value.of }, false);\n if ('rule' in inner) return inner;\n return { kind: 'list', required, of: inner };\n }\n const allowed =\n value.kind === 'enum'\n ? ['kind', 'required', 'values']\n : value.kind === 'reference'\n ? ['kind', 'required', 'to']\n : ['kind', 'required'];\n if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);\n return parseScalar(file, location, value, required);\n}\n\nfunction parseSection(file: string, location: string, value: unknown): SectionSpec | Refusal {\n if (!isRecord(value) || (value.kind !== 'text' && value.kind !== 'list')) {\n return refuse(file, 'definition-section-kind', location);\n }\n const required = requiredFlag(value.required);\n if (required === undefined || extraKeys(value, ['kind', 'required'])) {\n return refuse(file, 'definition-section', location);\n }\n return { kind: value.kind, required };\n}\n\nexport function readDefinition(file: string, document: Document): Definition | Refusal {\n if (document.type !== 'definition') return refuse(file, 'definition-type');\n const name = typeNameFromPath(file);\n if (name === '') return refuse(file, 'definition-type');\n for (const key of Object.keys(document.fields)) {\n if (key !== 'type' && key !== 'fields' && key !== 'sections') {\n return refuse(file, 'definition-shape', key);\n }\n }\n const fieldsValue = document.fields.fields;\n const sectionsValue = document.fields.sections;\n if (fieldsValue !== undefined && !isRecord(fieldsValue))\n return refuse(file, 'definition-fields', 'fields');\n if (sectionsValue !== undefined && !isRecord(sectionsValue)) {\n return refuse(file, 'definition-sections', 'sections');\n }\n const fields: Record<string, FieldSpec> = {};\n for (const [fieldName, spec] of Object.entries(fieldsValue ?? {})) {\n const parsed = parseField(file, fieldName, spec);\n if ('rule' in parsed) return parsed;\n fields[fieldName] = parsed;\n }\n const sections: Record<string, SectionSpec> = {};\n for (const [sectionName, spec] of Object.entries(sectionsValue ?? {})) {\n const parsed = parseSection(file, sectionName, spec);\n if ('rule' in parsed) return parsed;\n sections[sectionName] = parsed;\n }\n return { name, file, fields, sections };\n}\n"],"names":["typeNameFromPath","refusal","refuse","file","rule","location","undefined","isRecord","value","Array","isArray","requiredFlag","stringList","length","every","item","SCALAR_KINDS","Set","parseScalar","spec","required","kind","values","to","extraKeys","allowed","Object","keys","some","key","includes","parseField","of","has","inner","parseSection","readDefinition","document","type","name","fields","fieldsValue","sectionsValue","sections","fieldName","entries","parsed","sectionName"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,aAAa;AAC9C,SAASC,OAAO,QAAQ,cAAc;AAuBtC,SAASC,OAAOC,IAAY,EAAEC,IAAY,EAAEC,QAAiB;IAC3D,OAAOA,aAAaC,YAAYL,QAAQE,MAAMC,QAAQH,QAAQE,MAAMC,MAAM;QAAEC;IAAS;AACvF;AAEA,SAASE,SAASC,KAAc;IAC9B,OAAOA,UAAU,QAAQ,OAAOA,UAAU,YAAY,CAACC,MAAMC,OAAO,CAACF;AACvE;AAEA,SAASG,aAAaH,KAA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OAAO,CAACH,iBAAiB,CAAC,GAAI;QACrE,MAAMI,SAASX,aAAahC,MAAM4C,aAAa5B;QAC/C,IAAI,UAAU2B,QAAQ,OAAOA;QAC7BH,QAAQ,CAACI,YAAY,GAAGD;IAC1B;IACA,OAAO;QAAEP;QAAMpC;QAAMqC;QAAQG;IAAS;AACxC"}
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/definition.ts"],"sourcesContent":["import { typeNameFromPath } from './paths.js';\nimport { refusal } from './refuse.js';\nimport type { Document, Refusal } from './types.js';\n\nexport type TextSpec = { readonly kind: 'text'; readonly required: boolean };\n\nexport type ScalarSpec =\n | TextSpec\n | { readonly kind: 'string'; readonly required: boolean }\n | { readonly kind: 'number'; readonly required: boolean }\n | { readonly kind: 'date'; readonly required: boolean }\n | { readonly kind: 'enum'; readonly required: boolean; readonly values: readonly string[] }\n | { readonly kind: 'reference'; readonly required: boolean; readonly to: string };\n\nexport type ListSpec = {\n readonly kind: 'list';\n readonly required: boolean;\n readonly of: ScalarSpec;\n};\n\nexport type FieldSpec = ScalarSpec | ListSpec;\n\nexport type SectionSpec = TextSpec | ListSpec;\n\nexport type Definition = {\n readonly name: string;\n readonly file: string;\n readonly fields: Readonly<Record<string, FieldSpec>>;\n readonly sections: Readonly<Record<string, SectionSpec>>;\n};\n\nfunction refuse(file: string, rule: string, location?: string): Refusal {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction requiredFlag(value: unknown): boolean | undefined {\n if (value === undefined) return false;\n if (typeof value === 'boolean') return value;\n return undefined;\n}\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value) || value.length === 0) return undefined;\n if (!value.every((item) => typeof item === 'string' && item !== '')) return undefined;\n return value;\n}\n\nconst SCALAR_KINDS = new Set(['text', 'string', 'number', 'date', 'enum', 'reference']);\n\nfunction parseScalar(\n file: string,\n location: string,\n spec: Record<string, unknown>,\n required: boolean,\n): ScalarSpec | Refusal {\n const kind = spec.kind;\n if (kind === 'text') return { kind: 'text', required };\n if (kind === 'string') return { kind: 'string', required };\n if (kind === 'number') return { kind: 'number', required };\n if (kind === 'date') return { kind: 'date', required };\n if (kind === 'enum') {\n const values = stringList(spec.values);\n if (values === undefined) return refuse(file, 'definition-enum-values', location);\n return { kind: 'enum', required, values };\n }\n if (kind === 'reference') {\n if (typeof spec.to !== 'string' || spec.to === '')\n return refuse(file, 'definition-reference-to', location);\n return { kind: 'reference', required, to: spec.to };\n }\n return refuse(file, 'definition-field-kind', location);\n}\n\nfunction extraKeys(spec: Record<string, unknown>, allowed: readonly string[]): boolean {\n return Object.keys(spec).some((key) => !allowed.includes(key));\n}\n\nfunction parseList(\n file: string,\n location: string,\n spec: Record<string, unknown>,\n required: boolean,\n malformed: string,\n): ListSpec | Refusal {\n if (typeof spec.of !== 'string' || !SCALAR_KINDS.has(spec.of)) {\n return refuse(file, 'definition-list-of', location);\n }\n const allowed =\n spec.of === 'enum'\n ? ['kind', 'required', 'of', 'values']\n : spec.of === 'reference'\n ? ['kind', 'required', 'of', 'to']\n : ['kind', 'required', 'of'];\n if (extraKeys(spec, allowed)) return refuse(file, malformed, location);\n const inner = parseScalar(file, location, { ...spec, kind: spec.of }, false);\n if ('rule' in inner) return inner;\n return { kind: 'list', required, of: inner };\n}\n\nfunction parseField(file: string, location: string, value: unknown): FieldSpec | Refusal {\n if (!isRecord(value) || typeof value.kind !== 'string')\n return refuse(file, 'definition-field', location);\n const required = requiredFlag(value.required);\n if (required === undefined) return refuse(file, 'definition-field', location);\n if (value.kind === 'list') return parseList(file, location, value, required, 'definition-field');\n const allowed =\n value.kind === 'enum'\n ? ['kind', 'required', 'values']\n : value.kind === 'reference'\n ? ['kind', 'required', 'to']\n : ['kind', 'required'];\n if (extraKeys(value, allowed)) return refuse(file, 'definition-field', location);\n return parseScalar(file, location, value, required);\n}\n\nfunction parseSection(file: string, location: string, value: unknown): SectionSpec | Refusal {\n if (!isRecord(value) || (value.kind !== 'text' && value.kind !== 'list')) {\n return refuse(file, 'definition-section-kind', location);\n }\n const required = requiredFlag(value.required);\n if (required === undefined) return refuse(file, 'definition-section', location);\n if (value.kind === 'list')\n return parseList(file, location, value, required, 'definition-section');\n if (extraKeys(value, ['kind', 'required'])) return refuse(file, 'definition-section', location);\n return { kind: 'text', required };\n}\n\nexport function readDefinition(file: string, document: Document): Definition | Refusal {\n if (document.type !== 'definition') return refuse(file, 'definition-type');\n const name = typeNameFromPath(file);\n if (name === '') return refuse(file, 'definition-type');\n for (const key of Object.keys(document.fields)) {\n if (key !== 'type' && key !== 'fields' && key !== 'sections') {\n return refuse(file, 'definition-shape', key);\n }\n }\n const fieldsValue = document.fields.fields;\n const sectionsValue = document.fields.sections;\n if (fieldsValue !== undefined && !isRecord(fieldsValue))\n return refuse(file, 'definition-fields', 'fields');\n if (sectionsValue !== undefined && !isRecord(sectionsValue)) {\n return refuse(file, 'definition-sections', 'sections');\n }\n const fields: Record<string, FieldSpec> = Object.create(null);\n for (const [fieldName, spec] of Object.entries(fieldsValue ?? {})) {\n const parsed = parseField(file, fieldName, spec);\n if ('rule' in parsed) return parsed;\n fields[fieldName] = parsed;\n }\n const sections: Record<string, SectionSpec> = Object.create(null);\n for (const [sectionName, spec] of Object.entries(sectionsValue ?? {})) {\n const parsed = parseSection(file, sectionName, spec);\n if ('rule' in parsed) return parsed;\n sections[sectionName] = parsed;\n }\n return { name, file, fields, sections };\n}\n"],"names":["typeNameFromPath","refusal","refuse","file","rule","location","undefined","isRecord","value","Array","isArray","requiredFlag","stringList","length","every","item","SCALAR_KINDS","Set","parseScalar","spec","required","kind","values","to","extraKeys","allowed","Object","keys","some","key","includes","parseList","malformed","of","has","inner","parseField","parseSection","readDefinition","document","type","name","fields","fieldsValue","sectionsValue","sections","create","fieldName","entries","parsed","sectionName"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,aAAa;AAC9C,SAAS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,cAAcJ,SAASG,MAAM,CAACA,MAAM;IAC1C,MAAME,gBAAgBL,SAASG,MAAM,CAACG,QAAQ;IAC9C,IAAIF,gBAAgBrC,aAAa,CAACC,SAASoC,cACzC,OAAOzC,OAAOC,MAAM,qBAAqB;IAC3C,IAAIyC,kBAAkBtC,aAAa,CAACC,SAASqC,gBAAgB;QAC3D,OAAO1C,OAAOC,MAAM,uBAAuB;IAC7C;IACA,MAAMuC,SAAoChB,OAAOoB,MAAM,CAAC;IACxD,KAAK,MAAM,CAACC,WAAW5B,KAAK,IAAIO,OAAOsB,OAAO,CAACL,eAAe,CAAC,GAAI;QACjE,MAAMM,SAASb,WAAWjC,MAAM4C,WAAW5B;QAC3C,IAAI,UAAU8B,QAAQ,OAAOA;QAC7BP,MAAM,CAACK,UAAU,GAAGE;IACtB;IACA,MAAMJ,WAAwCnB,OAAOoB,MAAM,CAAC;IAC5D,KAAK,MAAM,CAACI,aAAa/B,KAAK,IAAIO,OAAOsB,OAAO,CAACJ,iBAAiB,CAAC,GAAI;QACrE,MAAMK,SAASZ,aAAalC,MAAM+C,aAAa/B;QAC/C,IAAI,UAAU8B,QAAQ,OAAOA;QAC7BJ,QAAQ,CAACK,YAAY,GAAGD;IAC1B;IACA,OAAO;QAAER;QAAMtC;QAAMuC;QAAQG;IAAS;AACxC"}
@@ -0,0 +1,3 @@
1
+ import type { Division, DivisionContext, Document } from './types.js';
2
+ export declare function divide(document: Document, file: string, context: DivisionContext): Division;
3
+ //# sourceMappingURL=divide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAoWpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAW3F"}