@driftsys/markspec 0.3.0 → 0.5.0

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 (331) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +56 -6
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +372 -41
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +21 -8
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +16 -5
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +100 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +58 -2
  68. package/esm/model/palette.d.ts +18 -0
  69. package/esm/model/palette.d.ts.map +1 -0
  70. package/esm/model/palette.js +23 -0
  71. package/esm/model/profile.d.ts +33 -27
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/model/source_introspection.d.ts +26 -0
  74. package/esm/model/source_introspection.d.ts.map +1 -0
  75. package/esm/model/source_introspection.js +77 -0
  76. package/esm/model/type_hierarchy.d.ts +51 -0
  77. package/esm/model/type_hierarchy.d.ts.map +1 -0
  78. package/esm/model/type_hierarchy.js +126 -0
  79. package/esm/model/uri_scheme_map.d.ts +21 -0
  80. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  81. package/esm/model/uri_scheme_map.js +66 -0
  82. package/esm/parser/attributes.d.ts.map +1 -1
  83. package/esm/parser/attributes.js +9 -6
  84. package/esm/parser/entity_refs.d.ts +53 -0
  85. package/esm/parser/entity_refs.d.ts.map +1 -0
  86. package/esm/parser/entity_refs.js +151 -0
  87. package/esm/parser/glossary.d.ts +43 -0
  88. package/esm/parser/glossary.d.ts.map +1 -0
  89. package/esm/parser/glossary.js +217 -0
  90. package/esm/parser/markdown.d.ts +10 -3
  91. package/esm/parser/markdown.d.ts.map +1 -1
  92. package/esm/parser/markdown.js +241 -11
  93. package/esm/parser/mod.d.ts +1 -0
  94. package/esm/parser/mod.d.ts.map +1 -1
  95. package/esm/parser/mod.js +4 -3
  96. package/esm/parser/source.d.ts +20 -0
  97. package/esm/parser/source.d.ts.map +1 -1
  98. package/esm/parser/source.js +4 -4
  99. package/esm/profile/chain.js +3 -13
  100. package/esm/profile/colors.d.ts +26 -0
  101. package/esm/profile/colors.d.ts.map +1 -0
  102. package/esm/profile/colors.js +46 -0
  103. package/esm/profile/introspect.d.ts +135 -0
  104. package/esm/profile/introspect.d.ts.map +1 -0
  105. package/esm/profile/introspect.js +378 -0
  106. package/esm/profile/load.d.ts.map +1 -1
  107. package/esm/profile/load.js +67 -0
  108. package/esm/profile/manifest.d.ts.map +1 -1
  109. package/esm/profile/manifest.js +278 -104
  110. package/esm/profile/merge.js +139 -39
  111. package/esm/profile/mod.d.ts +3 -4
  112. package/esm/profile/mod.d.ts.map +1 -1
  113. package/esm/profile/mod.js +6 -2
  114. package/esm/reporter/mod.js +4 -4
  115. package/esm/util/fence.d.ts +30 -0
  116. package/esm/util/fence.d.ts.map +1 -0
  117. package/esm/util/fence.js +40 -0
  118. package/esm/validator/attributes.d.ts +3 -3
  119. package/esm/validator/attributes.d.ts.map +1 -1
  120. package/esm/validator/attributes.js +1 -18
  121. package/esm/validator/body_blocks.d.ts +38 -0
  122. package/esm/validator/body_blocks.d.ts.map +1 -0
  123. package/esm/validator/body_blocks.js +218 -0
  124. package/esm/validator/caption_convention.d.ts +29 -0
  125. package/esm/validator/caption_convention.d.ts.map +1 -0
  126. package/esm/validator/caption_convention.js +58 -0
  127. package/esm/validator/captions.d.ts +22 -0
  128. package/esm/validator/captions.d.ts.map +1 -0
  129. package/esm/validator/captions.js +137 -0
  130. package/esm/validator/component_schemes.d.ts +73 -0
  131. package/esm/validator/component_schemes.d.ts.map +1 -0
  132. package/esm/validator/component_schemes.js +375 -0
  133. package/esm/validator/feature_ac.d.ts +28 -0
  134. package/esm/validator/feature_ac.d.ts.map +1 -0
  135. package/esm/validator/feature_ac.js +102 -0
  136. package/esm/validator/listing.d.ts +42 -0
  137. package/esm/validator/listing.d.ts.map +1 -0
  138. package/esm/validator/listing.js +295 -0
  139. package/esm/validator/mod.d.ts +2 -0
  140. package/esm/validator/mod.d.ts.map +1 -1
  141. package/esm/validator/mod.js +253 -12
  142. package/esm/validator/modal_keywords.d.ts +23 -0
  143. package/esm/validator/modal_keywords.d.ts.map +1 -0
  144. package/esm/validator/modal_keywords.js +137 -0
  145. package/esm/validator/per_type_attrs.d.ts +29 -0
  146. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  147. package/esm/validator/per_type_attrs.js +75 -0
  148. package/esm/validator/pipeline.d.ts +7 -2
  149. package/esm/validator/pipeline.d.ts.map +1 -1
  150. package/esm/validator/pipeline.js +40 -7
  151. package/esm/validator/trace_types.d.ts +26 -0
  152. package/esm/validator/trace_types.d.ts.map +1 -0
  153. package/esm/validator/trace_types.js +232 -0
  154. package/esm/validator/traceability.d.ts +3 -4
  155. package/esm/validator/traceability.d.ts.map +1 -1
  156. package/esm/validator/traceability.js +5 -10
  157. package/esm/validator/type_resolution.d.ts +67 -0
  158. package/esm/validator/type_resolution.d.ts.map +1 -0
  159. package/esm/validator/type_resolution.js +140 -0
  160. package/esm/validator/types.d.ts +45 -0
  161. package/esm/validator/types.d.ts.map +1 -1
  162. package/esm/validator/types.js +128 -16
  163. package/esm/validator/value_types.d.ts +8 -0
  164. package/esm/validator/value_types.d.ts.map +1 -1
  165. package/esm/validator/value_types.js +8 -1
  166. package/package.json +1 -1
  167. package/script/ast/build.d.ts +70 -0
  168. package/script/ast/build.d.ts.map +1 -0
  169. package/script/ast/build.js +610 -0
  170. package/script/ast/equivalence.d.ts +18 -0
  171. package/script/ast/equivalence.d.ts.map +1 -0
  172. package/script/ast/equivalence.js +59 -0
  173. package/script/ast/nodes.d.ts +221 -0
  174. package/script/ast/nodes.d.ts.map +1 -0
  175. package/script/ast/nodes.js +13 -0
  176. package/script/ast/normalize.d.ts +67 -0
  177. package/script/ast/normalize.d.ts.map +1 -0
  178. package/script/ast/normalize.js +258 -0
  179. package/script/ast/render.d.ts +34 -0
  180. package/script/ast/render.d.ts.map +1 -0
  181. package/script/ast/render.js +218 -0
  182. package/script/compiler/inverses.d.ts +2 -8
  183. package/script/compiler/inverses.d.ts.map +1 -1
  184. package/script/compiler/inverses.js +50 -14
  185. package/script/compiler/manifest.d.ts +59 -0
  186. package/script/compiler/manifest.d.ts.map +1 -0
  187. package/script/compiler/manifest.js +51 -0
  188. package/script/compiler/mod.d.ts +9 -1
  189. package/script/compiler/mod.d.ts.map +1 -1
  190. package/script/compiler/mod.js +21 -2
  191. package/script/compiler/ndjson_writer.d.ts +50 -0
  192. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  193. package/script/compiler/ndjson_writer.js +78 -0
  194. package/script/compiler/schema.d.ts +18 -1
  195. package/script/compiler/schema.d.ts.map +1 -1
  196. package/script/compiler/schema.js +18 -8
  197. package/script/config/mod.d.ts.map +1 -1
  198. package/script/config/mod.js +54 -0
  199. package/script/formatter/mod.d.ts +56 -6
  200. package/script/formatter/mod.d.ts.map +1 -1
  201. package/script/formatter/mod.js +375 -41
  202. package/script/formatter/synth_ulid.d.ts +21 -0
  203. package/script/formatter/synth_ulid.d.ts.map +1 -0
  204. package/script/formatter/synth_ulid.js +67 -0
  205. package/script/lint/mod.d.ts +10 -0
  206. package/script/lint/mod.d.ts.map +1 -0
  207. package/script/lint/mod.js +12 -0
  208. package/script/lint/rules/lexicon.d.ts +24 -0
  209. package/script/lint/rules/lexicon.d.ts.map +1 -0
  210. package/script/lint/rules/lexicon.js +240 -0
  211. package/script/lint/rules/struct.d.ts +17 -0
  212. package/script/lint/rules/struct.d.ts.map +1 -0
  213. package/script/lint/rules/struct.js +59 -0
  214. package/script/lint/rules/suppression.d.ts +19 -0
  215. package/script/lint/rules/suppression.d.ts.map +1 -0
  216. package/script/lint/rules/suppression.js +80 -0
  217. package/script/lint/runner.d.ts +39 -0
  218. package/script/lint/runner.d.ts.map +1 -0
  219. package/script/lint/runner.js +116 -0
  220. package/script/lint/types.d.ts +19 -0
  221. package/script/lint/types.d.ts.map +1 -0
  222. package/script/lint/types.js +10 -0
  223. package/script/mod.d.ts +21 -8
  224. package/script/mod.d.ts.map +1 -1
  225. package/script/mod.js +58 -32
  226. package/script/model/attributes.d.ts.map +1 -1
  227. package/script/model/attributes.js +163 -2
  228. package/script/model/discriminating_attr.d.ts +33 -0
  229. package/script/model/discriminating_attr.d.ts.map +1 -0
  230. package/script/model/discriminating_attr.js +77 -0
  231. package/script/model/mod.d.ts +100 -3
  232. package/script/model/mod.d.ts.map +1 -1
  233. package/script/model/mod.js +67 -3
  234. package/script/model/palette.d.ts +18 -0
  235. package/script/model/palette.d.ts.map +1 -0
  236. package/script/model/palette.js +26 -0
  237. package/script/model/profile.d.ts +33 -27
  238. package/script/model/profile.d.ts.map +1 -1
  239. package/script/model/source_introspection.d.ts +26 -0
  240. package/script/model/source_introspection.d.ts.map +1 -0
  241. package/script/model/source_introspection.js +80 -0
  242. package/script/model/type_hierarchy.d.ts +51 -0
  243. package/script/model/type_hierarchy.d.ts.map +1 -0
  244. package/script/model/type_hierarchy.js +130 -0
  245. package/script/model/uri_scheme_map.d.ts +21 -0
  246. package/script/model/uri_scheme_map.d.ts.map +1 -0
  247. package/script/model/uri_scheme_map.js +69 -0
  248. package/script/parser/attributes.d.ts.map +1 -1
  249. package/script/parser/attributes.js +9 -6
  250. package/script/parser/entity_refs.d.ts +53 -0
  251. package/script/parser/entity_refs.d.ts.map +1 -0
  252. package/script/parser/entity_refs.js +155 -0
  253. package/script/parser/glossary.d.ts +43 -0
  254. package/script/parser/glossary.d.ts.map +1 -0
  255. package/script/parser/glossary.js +221 -0
  256. package/script/parser/markdown.d.ts +10 -3
  257. package/script/parser/markdown.d.ts.map +1 -1
  258. package/script/parser/markdown.js +240 -10
  259. package/script/parser/mod.d.ts +1 -0
  260. package/script/parser/mod.d.ts.map +1 -1
  261. package/script/parser/mod.js +8 -4
  262. package/script/parser/source.d.ts +20 -0
  263. package/script/parser/source.d.ts.map +1 -1
  264. package/script/parser/source.js +4 -1
  265. package/script/profile/chain.js +3 -13
  266. package/script/profile/colors.d.ts +26 -0
  267. package/script/profile/colors.d.ts.map +1 -0
  268. package/script/profile/colors.js +49 -0
  269. package/script/profile/introspect.d.ts +135 -0
  270. package/script/profile/introspect.d.ts.map +1 -0
  271. package/script/profile/introspect.js +381 -0
  272. package/script/profile/load.d.ts.map +1 -1
  273. package/script/profile/load.js +67 -0
  274. package/script/profile/manifest.d.ts.map +1 -1
  275. package/script/profile/manifest.js +280 -106
  276. package/script/profile/merge.js +139 -39
  277. package/script/profile/mod.d.ts +3 -4
  278. package/script/profile/mod.d.ts.map +1 -1
  279. package/script/profile/mod.js +9 -6
  280. package/script/reporter/mod.js +4 -4
  281. package/script/util/fence.d.ts +30 -0
  282. package/script/util/fence.d.ts.map +1 -0
  283. package/script/util/fence.js +44 -0
  284. package/script/validator/attributes.d.ts +3 -3
  285. package/script/validator/attributes.d.ts.map +1 -1
  286. package/script/validator/attributes.js +1 -18
  287. package/script/validator/body_blocks.d.ts +38 -0
  288. package/script/validator/body_blocks.d.ts.map +1 -0
  289. package/script/validator/body_blocks.js +221 -0
  290. package/script/validator/caption_convention.d.ts +29 -0
  291. package/script/validator/caption_convention.d.ts.map +1 -0
  292. package/script/validator/caption_convention.js +61 -0
  293. package/script/validator/captions.d.ts +22 -0
  294. package/script/validator/captions.d.ts.map +1 -0
  295. package/script/validator/captions.js +140 -0
  296. package/script/validator/component_schemes.d.ts +73 -0
  297. package/script/validator/component_schemes.d.ts.map +1 -0
  298. package/script/validator/component_schemes.js +384 -0
  299. package/script/validator/feature_ac.d.ts +28 -0
  300. package/script/validator/feature_ac.d.ts.map +1 -0
  301. package/script/validator/feature_ac.js +105 -0
  302. package/script/validator/listing.d.ts +42 -0
  303. package/script/validator/listing.d.ts.map +1 -0
  304. package/script/validator/listing.js +298 -0
  305. package/script/validator/mod.d.ts +2 -0
  306. package/script/validator/mod.d.ts.map +1 -1
  307. package/script/validator/mod.js +256 -14
  308. package/script/validator/modal_keywords.d.ts +23 -0
  309. package/script/validator/modal_keywords.d.ts.map +1 -0
  310. package/script/validator/modal_keywords.js +140 -0
  311. package/script/validator/per_type_attrs.d.ts +29 -0
  312. package/script/validator/per_type_attrs.d.ts.map +1 -0
  313. package/script/validator/per_type_attrs.js +78 -0
  314. package/script/validator/pipeline.d.ts +7 -2
  315. package/script/validator/pipeline.d.ts.map +1 -1
  316. package/script/validator/pipeline.js +39 -6
  317. package/script/validator/trace_types.d.ts +26 -0
  318. package/script/validator/trace_types.d.ts.map +1 -0
  319. package/script/validator/trace_types.js +235 -0
  320. package/script/validator/traceability.d.ts +3 -4
  321. package/script/validator/traceability.d.ts.map +1 -1
  322. package/script/validator/traceability.js +5 -10
  323. package/script/validator/type_resolution.d.ts +67 -0
  324. package/script/validator/type_resolution.d.ts.map +1 -0
  325. package/script/validator/type_resolution.js +146 -0
  326. package/script/validator/types.d.ts +45 -0
  327. package/script/validator/types.d.ts.map +1 -1
  328. package/script/validator/types.js +131 -16
  329. package/script/validator/value_types.d.ts +8 -0
  330. package/script/validator/value_types.d.ts.map +1 -1
  331. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/ast/render
4
+ *
5
+ * Body-AST → canonical body-string renderer. The faithful inverse of
6
+ * `buildBodyAst` on already-canonical input.
7
+ *
8
+ * Invariant: for any canonical body string `s` (i.e. after running the
9
+ * MarkSpec formatter),
10
+ *
11
+ * render(buildBodyAst(s)) === s
12
+ *
13
+ * `render` does NOT re-implement the formatter's normalisation passes
14
+ * (bullet rewriting, blank-line collapse, modal lowercasing). It assumes
15
+ * its input was produced from a body string that is already in canonical
16
+ * form and simply reverses the structural mapping that `build.ts` applied.
17
+ *
18
+ * This module is pure library code: no `Deno.*` APIs.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.render = render;
22
+ // ---------------------------------------------------------------------------
23
+ // Per-node serialisers
24
+ // ---------------------------------------------------------------------------
25
+ function renderParagraph(node) {
26
+ // The paragraph's text is stored verbatim (markers are recorded as spans
27
+ // but the text is unchanged). Emit the text directly.
28
+ return node.content.text;
29
+ }
30
+ function renderList(node) {
31
+ const itemLines = [];
32
+ for (const item of node.items) {
33
+ const rendered = renderListItem(item, node.ordered, itemLines.length + 1);
34
+ itemLines.push(rendered);
35
+ }
36
+ // Loose lists (spread=true) have blank lines between items in source;
37
+ // tight lists do not.
38
+ return itemLines.join(node.spread ? "\n\n" : "\n");
39
+ }
40
+ function renderListItem(item, ordered, index) {
41
+ if (item.blocks.length === 0) {
42
+ const bullet = ordered ? `${index}.` : "-";
43
+ return bullet;
44
+ }
45
+ const firstBlock = item.blocks[0];
46
+ const restBlocks = item.blocks.slice(1);
47
+ // The bullet prefix for the first block.
48
+ const bullet = ordered ? `${index}.` : "-";
49
+ // Render the first block. For a paragraph, the text follows the bullet
50
+ // directly. For any other block, we render it indented.
51
+ let firstLine;
52
+ let extraLines = [];
53
+ // GFM task-list checkbox, re-emitted right after the bullet. Absent for
54
+ // non-task items (`item.checked === undefined`); independent of
55
+ // `ListNode.hasTaskItems`, so MSL-B042 is unaffected.
56
+ const checkbox = item.checked === undefined
57
+ ? ""
58
+ : item.checked
59
+ ? "[x] "
60
+ : "[ ] ";
61
+ if (firstBlock.kind === "paragraph") {
62
+ // `- text` — inline with the bullet.
63
+ const text = firstBlock.content.text;
64
+ const textLines = text.split("\n");
65
+ firstLine = `${bullet} ${checkbox}${textLines[0]}`;
66
+ // Known limitation: continuation-line indent is a fixed 2 spaces and
67
+ // does not account for checkbox width, so a MULTI-LINE paragraph in a
68
+ // task-list item (`- [x] line one\n line two`) does not round-trip
69
+ // byte-identically. Task lists are an excluded construct (MSL-B042);
70
+ // the corpus only exercises single-line task items, so no canonical
71
+ // input regresses and the equivalence gate stays green.
72
+ if (textLines.length > 1) {
73
+ // Continuation lines of a multi-line paragraph are indented to align
74
+ // with the first character after the bullet (`- ` = 2 chars).
75
+ extraLines = textLines.slice(1).map((l) => (l ? ` ${l}` : ""));
76
+ }
77
+ }
78
+ else {
79
+ // Block content that isn't a paragraph: render on its own line(s),
80
+ // indented by 2 spaces.
81
+ firstLine = checkbox ? `${bullet} ${checkbox}`.trimEnd() : bullet;
82
+ const blockStr = renderBlock(firstBlock);
83
+ extraLines = blockStr.split("\n").map((l) => (l ? ` ${l}` : ""));
84
+ }
85
+ const allLines = [firstLine, ...extraLines];
86
+ // Remaining blocks in the item, indented. A "loose" item
87
+ // (`listItem.spread`, captured from mdast) separates its blocks with a
88
+ // blank line in source; a tight item (e.g. a paragraph with a nested
89
+ // list directly under it) does not. Gating on the item's own spread —
90
+ // NOT the list-level `ListNode.spread` — keeps loose multi-block items
91
+ // byte-identical while letting tight nested lists round-trip.
92
+ for (const block of restBlocks) {
93
+ if (item.spread)
94
+ allLines.push(""); // blank line before next block
95
+ const blockStr = renderBlock(block);
96
+ for (const l of blockStr.split("\n")) {
97
+ allLines.push(l ? ` ${l}` : "");
98
+ }
99
+ }
100
+ return allLines.join("\n");
101
+ }
102
+ function renderTable(node) {
103
+ // Emit the verbatim source substring captured at parse time.
104
+ // This preserves author column widths exactly (e.g. a separator row
105
+ // wider than its cell content) for byte-identical round-trip,
106
+ // matching the behaviour of CodeNode, FeatureNode, MathNode, and
107
+ // UnknownNode which also carry their raw source text.
108
+ return node.raw;
109
+ }
110
+ function renderFigure(node) {
111
+ return `![${node.alt}](${node.path})`;
112
+ }
113
+ function renderCode(node) {
114
+ const lang = node.lang ?? "";
115
+ return `\`\`\`${lang}\n${node.text}\n\`\`\``;
116
+ }
117
+ function renderFeature(node) {
118
+ return `\`\`\`gherkin\n${node.source}\n\`\`\``;
119
+ }
120
+ function renderMath(node) {
121
+ // build.ts splits on `$$…$$`. The tex field is the inner content
122
+ // (including any surrounding whitespace). Match what MATH_BLOCK_RE captured:
123
+ // the regex is /^\$\$([\s\S]*?)\$\$$/ so tex may start/end with \n.
124
+ return `$$${node.tex}$$`;
125
+ }
126
+ function renderDefinitionList(node) {
127
+ return node.items
128
+ .map((item) => `${item.term.text}\n: ${item.definition.text}`)
129
+ .join("\n\n");
130
+ }
131
+ function renderNote(node) {
132
+ // build.ts stores the content text with `\n\n` between paragraphs
133
+ // that were separated by a blank quoted line in the source. Reconstruct
134
+ // by prefixing every non-empty content line with `> ` and every empty
135
+ // line (the paragraph separator) with bare `>` (no trailing space),
136
+ // matching the canonical blank-quoted-line format.
137
+ const text = node.content.text;
138
+ if (!text)
139
+ return `> [!${node.admonition}]`;
140
+ const lines = text.split("\n");
141
+ if (node.markerInline) {
142
+ // Body began on the marker line in source — reproduce that form:
143
+ // first content line stays on `> [!KIND] …`, the rest are quoted.
144
+ const [first, ...rest] = lines;
145
+ return `> [!${node.admonition}] ${first}` +
146
+ (rest.length
147
+ ? "\n" + rest.map((l) => l ? `> ${l}` : `>`).join("\n")
148
+ : "");
149
+ }
150
+ return `> [!${node.admonition}]\n` +
151
+ lines.map((l) => l ? `> ${l}` : `>`).join("\n");
152
+ }
153
+ function renderBlockquote(node) {
154
+ // build.ts stores the content text with `\n\n` between paragraphs
155
+ // that were separated by a blank quoted line in the source. Re-add
156
+ // `> ` to every non-empty line and bare `>` to every empty line for
157
+ // byte-identical round-trip.
158
+ const text = node.content.text;
159
+ return text.split("\n").map((l) => l ? `> ${l}` : `>`).join("\n");
160
+ }
161
+ function renderCaption(node) {
162
+ return `${node.keyword}: ${node.text}`;
163
+ }
164
+ function renderUnknown(node) {
165
+ return node.raw;
166
+ }
167
+ // ---------------------------------------------------------------------------
168
+ // Block dispatcher
169
+ // ---------------------------------------------------------------------------
170
+ function renderBlock(block) {
171
+ switch (block.kind) {
172
+ case "paragraph":
173
+ return renderParagraph(block);
174
+ case "list":
175
+ return renderList(block);
176
+ case "table":
177
+ return renderTable(block);
178
+ case "figure":
179
+ return renderFigure(block);
180
+ case "code":
181
+ return renderCode(block);
182
+ case "feature":
183
+ return renderFeature(block);
184
+ case "math":
185
+ return renderMath(block);
186
+ case "definition-list":
187
+ return renderDefinitionList(block);
188
+ case "note":
189
+ return renderNote(block);
190
+ case "blockquote":
191
+ return renderBlockquote(block);
192
+ case "caption":
193
+ return renderCaption(block);
194
+ case "unknown":
195
+ return renderUnknown(block);
196
+ }
197
+ }
198
+ // ---------------------------------------------------------------------------
199
+ // Public API
200
+ // ---------------------------------------------------------------------------
201
+ /**
202
+ * Serialise a body AST back to canonical MarkSpec body text.
203
+ *
204
+ * This is the faithful inverse of `buildBodyAst` on already-canonical input:
205
+ * for any canonical body string `s`, `render(buildBodyAst(s)) === s`.
206
+ *
207
+ * `render` assumes its input was produced from body text already normalised
208
+ * by the MarkSpec formatter. It does not re-run normalisation passes.
209
+ *
210
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst`.
211
+ * @returns The canonical body string, with blocks separated by a single
212
+ * blank line (two newlines) and no trailing newline.
213
+ */
214
+ function render(blocks) {
215
+ if (blocks.length === 0)
216
+ return "";
217
+ return blocks.map(renderBlock).join("\n\n");
218
+ }
@@ -5,18 +5,12 @@
5
5
  * an `inverse:` declaration and emits synthetic back-link values on target
6
6
  * entries.
7
7
  */
8
- import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
8
+ import type { Diagnostic, EffectiveProfile, Entry, Link } from "../model/mod.js";
9
9
  /** Result of inverse generation. */
10
10
  export interface GenerateInversesResult {
11
11
  readonly entries: readonly Entry[];
12
+ readonly links: readonly Link[];
12
13
  readonly diagnostics: readonly Diagnostic[];
13
14
  }
14
- /**
15
- * Generate inverse (back-link) attributes from forward link declarations.
16
- *
17
- * Walks every identified entry's `typedAttributes` for attributes that match
18
- * an `inverse:` declaration in the effective profile, then accumulates
19
- * back-links on target entries.
20
- */
21
15
  export declare function generateInverses(entries: readonly Entry[], profile: EffectiveProfile): GenerateInversesResult;
22
16
  //# sourceMappingURL=inverses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inverses.d.ts","sourceRoot":"","sources":["../../src/compiler/inverses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAEzB,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAcD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,sBAAsB,CA4GxB"}
1
+ {"version":3,"file":"inverses.d.ts","sourceRoot":"","sources":["../../src/compiler/inverses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EAEL,IAAI,EAEL,MAAM,iBAAiB,CAAC;AAEzB,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAwCD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,sBAAsB,CA4IxB"}
@@ -15,14 +15,32 @@ exports.generateInverses = generateInverses;
15
15
  * an `inverse:` declaration in the effective profile, then accumulates
16
16
  * back-links on target entries.
17
17
  */
18
+ /**
19
+ * Attribute-name → LinkKind for forward-link attributes that may carry
20
+ * inverse declarations. Used to tag generated back-link edges with the
21
+ * forward relationship kind so consumers can reconstruct the full graph.
22
+ */
23
+ const ATTR_TO_LINK_KIND = {
24
+ "Satisfies": "satisfies",
25
+ "Derived-from": "derived-from",
26
+ "References": "references",
27
+ "Allocated-to": "allocated-to",
28
+ "Realizes": "realizes",
29
+ "Verifies": "verifies",
30
+ "Tests": "tests",
31
+ "Depends-on": "depends-on",
32
+ "Part-of": "part-of",
33
+ "Generated-from": "generated-from",
34
+ "Supersedes": "supersedes",
35
+ };
18
36
  function generateInverses(entries, profile) {
19
37
  if (entries.length === 0) {
20
- return { entries: [], diagnostics: [] };
38
+ return { entries: [], links: [], diagnostics: [] };
21
39
  }
22
40
  // Step 1: Collect all inverse declarations from the profile
23
41
  const inverseSpecs = collectInverseSpecs(profile);
24
42
  if (inverseSpecs.length === 0) {
25
- return { entries: [...entries], diagnostics: [] };
43
+ return { entries: [...entries], links: [], diagnostics: [] };
26
44
  }
27
45
  // Step 2: Index entries by id
28
46
  const byId = new Map();
@@ -34,8 +52,10 @@ function generateInverses(entries, profile) {
34
52
  // Step 3–5: Walk entries, accumulate back-links
35
53
  // Map: targetId → Map<inverseAttrName, Set<sourceId>>
36
54
  const generated = new Map();
55
+ // Parallel list of raw generated-edge data for Link emission.
56
+ const generatedEdges = [];
37
57
  for (const source of entries) {
38
- if (source.shape !== "identified" || source.id === undefined)
58
+ if (source.shape !== "Authored" || source.id === undefined)
39
59
  continue;
40
60
  const applicableSpecs = resolveApplicableSpecs(inverseSpecs, source.type);
41
61
  for (const spec of applicableSpecs) {
@@ -56,7 +76,15 @@ function generateInverses(entries, profile) {
56
76
  idSet = new Set();
57
77
  targetMap.set(spec.inverse.name, idSet);
58
78
  }
79
+ const wasNew = !idSet.has(source.id);
59
80
  idSet.add(source.id);
81
+ if (wasNew) {
82
+ generatedEdges.push({
83
+ targetUlid: targetId,
84
+ sourceUlid: source.id,
85
+ attrName: spec.attrName,
86
+ });
87
+ }
60
88
  }
61
89
  }
62
90
  }
@@ -105,7 +133,25 @@ function generateInverses(entries, profile) {
105
133
  result.push(e);
106
134
  }
107
135
  }
108
- return { entries: result, diagnostics };
136
+ // Resolve generated edges to displayId-based Link objects.
137
+ const links = [];
138
+ for (const { targetUlid, sourceUlid, attrName } of generatedEdges) {
139
+ const kind = ATTR_TO_LINK_KIND[attrName];
140
+ if (!kind)
141
+ continue;
142
+ const target = byId.get(targetUlid);
143
+ const source = byId.get(sourceUlid);
144
+ if (!target || !source)
145
+ continue;
146
+ links.push({
147
+ from: target.displayId,
148
+ to: source.displayId,
149
+ kind,
150
+ location: source.location,
151
+ origin: "generated",
152
+ });
153
+ }
154
+ return { entries: result, links, diagnostics };
109
155
  }
110
156
  /** Collect all inverse-bearing attribute declarations from the profile. */
111
157
  function collectInverseSpecs(profile) {
@@ -120,16 +166,6 @@ function collectInverseSpecs(profile) {
120
166
  });
121
167
  }
122
168
  }
123
- // Identified shape scope
124
- for (const [, entry] of profile.identified.attributes) {
125
- if (entry.value.inverse) {
126
- specs.push({
127
- attrName: entry.value.name,
128
- inverse: entry.value.inverse,
129
- sourceType: null,
130
- });
131
- }
132
- }
133
169
  // Type scopes
134
170
  for (const [typeName, typeEntry] of profile.types) {
135
171
  for (const [, attrEntry] of typeEntry.value.attributes) {
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module compiler/manifest
3
+ *
4
+ * Builds the `manifest.json` object for the nextgen `/api/` directory output.
5
+ * Tier 1 implements the small-project degenerate form: a single
6
+ * `compiled.json` file pointed to by the manifest's `entries` and `edges`
7
+ * indirection blocks.
8
+ */
9
+ import type { EffectiveProfile, ProjectConfig } from "../model/mod.js";
10
+ import type { CompileResult } from "./mod.js";
11
+ /** Entries block in `manifest.json` — inline (Tier 1) or NDJSON (Tier 2). */
12
+ export type ManifestEntriesBlock = {
13
+ readonly format: "inline";
14
+ readonly file: string;
15
+ } | {
16
+ readonly format: "ndjson";
17
+ readonly file: string;
18
+ readonly index: string;
19
+ };
20
+ /** Edges block in `manifest.json` — inline (Tier 1) or NDJSON (Tier 2). */
21
+ export type ManifestEdgesBlock = {
22
+ readonly format: "inline";
23
+ readonly file: string;
24
+ } | {
25
+ readonly format: "ndjson";
26
+ readonly file: string;
27
+ };
28
+ /** `manifest.json` schema (spec §4.2). */
29
+ export interface ManifestJson {
30
+ readonly markspecSchemaVersion: 1;
31
+ readonly generator: {
32
+ readonly release: string;
33
+ readonly coreSchema: 1;
34
+ };
35
+ readonly project: {
36
+ readonly name: string;
37
+ readonly root: string;
38
+ };
39
+ readonly counts: {
40
+ readonly entries: number;
41
+ readonly edges: number;
42
+ readonly byType: Readonly<Record<string, number>>;
43
+ };
44
+ readonly entries: ManifestEntriesBlock;
45
+ readonly edges: ManifestEdgesBlock;
46
+ readonly sqliteMirror: null;
47
+ readonly federation: readonly string[];
48
+ readonly reserved: Readonly<Record<string, never>>;
49
+ }
50
+ /**
51
+ * Build the `manifest.json` object for a compiled project.
52
+ *
53
+ * When `streaming` is false (default): emits the Tier 1 inline form —
54
+ * both `entries` and `edges` point at `compiled.json`.
55
+ * When `streaming` is true: emits the Tier 2 NDJSON form —
56
+ * entries → `entries.ndjson` + `entries.idx`, edges → `edges.ndjson`.
57
+ */
58
+ export declare function buildManifest(result: CompileResult, config: ProjectConfig, projectRoot: string, _profile: EffectiveProfile | undefined, version: string, streaming?: boolean): ManifestJson;
59
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
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AQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KACnD,CAAC;IACF,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;CACpD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,gBAAgB,GAAG,SAAS,EACtC,OAAO,EAAE,MAAM,EACf,SAAS,UAAQ,GAChB,YAAY,CAgCd"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * @module compiler/manifest
4
+ *
5
+ * Builds the `manifest.json` object for the nextgen `/api/` directory output.
6
+ * Tier 1 implements the small-project degenerate form: a single
7
+ * `compiled.json` file pointed to by the manifest's `entries` and `edges`
8
+ * indirection blocks.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.buildManifest = buildManifest;
12
+ /**
13
+ * Build the `manifest.json` object for a compiled project.
14
+ *
15
+ * When `streaming` is false (default): emits the Tier 1 inline form —
16
+ * both `entries` and `edges` point at `compiled.json`.
17
+ * When `streaming` is true: emits the Tier 2 NDJSON form —
18
+ * entries → `entries.ndjson` + `entries.idx`, edges → `edges.ndjson`.
19
+ */
20
+ function buildManifest(result, config, projectRoot, _profile, version, streaming = false) {
21
+ const byType = {};
22
+ for (const entry of result.entries.values()) {
23
+ const typeName = entry.type ?? "unknown";
24
+ byType[typeName] = (byType[typeName] ?? 0) + 1;
25
+ }
26
+ return {
27
+ markspecSchemaVersion: 1,
28
+ generator: {
29
+ release: version,
30
+ coreSchema: 1,
31
+ },
32
+ project: {
33
+ name: config.name ?? "",
34
+ root: projectRoot,
35
+ },
36
+ counts: {
37
+ entries: result.entries.size,
38
+ edges: result.links.length,
39
+ byType,
40
+ },
41
+ entries: streaming
42
+ ? { format: "ndjson", file: "entries.ndjson", index: "entries.idx" }
43
+ : { format: "inline", file: "compiled.json" },
44
+ edges: streaming
45
+ ? { format: "ndjson", file: "edges.ndjson" }
46
+ : { format: "inline", file: "compiled.json" },
47
+ sqliteMirror: null,
48
+ federation: config.parents ?? [],
49
+ reserved: {},
50
+ };
51
+ }
@@ -11,6 +11,14 @@ export interface CompileOptions {
11
11
  readonly readFile: (path: string) => Promise<string>;
12
12
  /** Active profile for inverse attribute generation. Optional — when absent, inverses are skipped. */
13
13
  readonly profile?: EffectiveProfile;
14
+ /**
15
+ * Optional. Called once per source file to obtain its mtime.
16
+ * Returns undefined when stat is unavailable (remote, test mock, etc.).
17
+ * When absent, `entry.properties.file.mtime` is left undefined.
18
+ */
19
+ readonly statFile?: (path: string) => Promise<{
20
+ mtime: Date | null;
21
+ } | undefined>;
14
22
  }
15
23
  /** Compiled project output with resolved traceability graph. */
16
24
  export interface CompileResult {
@@ -37,7 +45,7 @@ export interface CompileResult {
37
45
  */
38
46
  export declare function compile(paths: readonly string[], options: CompileOptions): Promise<CompileResult>;
39
47
  export { serializeCompileResult } from "./schema.js";
40
- export type { SerializedCompileResult } from "./schema.js";
48
+ export type { SerializedCompileResult, SerializedEntry } from "./schema.js";
41
49
  export { generateInverses } from "./inverses.js";
42
50
  export type { GenerateInversesResult } from "./inverses.js";
43
51
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK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FxB;AAmGD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
@@ -41,7 +41,23 @@ async function compile(paths, options) {
41
41
  continue;
42
42
  }
43
43
  const result = await (0, mod_js_1.parseFile)(content, { file: filePath });
44
- allEntries.push(...result.entries);
44
+ const stat = options.statFile
45
+ ? await options.statFile(filePath)
46
+ : undefined;
47
+ const mtimeStr = stat?.mtime ? stat.mtime.toISOString() : undefined;
48
+ const annotatedEntries = result.entries.map((entry) => ({
49
+ ...entry,
50
+ properties: {
51
+ ...entry.properties,
52
+ file: {
53
+ path: filePath,
54
+ line: entry.location.line,
55
+ column: entry.location.column,
56
+ mtime: mtimeStr,
57
+ },
58
+ },
59
+ }));
60
+ allEntries.push(...annotatedEntries);
45
61
  parseDiagnostics.push(...result.diagnostics);
46
62
  if (result.document)
47
63
  documents.set(filePath, result.document);
@@ -64,9 +80,11 @@ async function compile(paths, options) {
64
80
  }
65
81
  }
66
82
  // Phase 3.5: Generate inverse attributes from profile declarations.
83
+ let generatedLinks = [];
67
84
  if (options.profile) {
68
85
  const inverseResult = (0, inverses_js_1.generateInverses)([...entries.values()], options.profile);
69
86
  parseDiagnostics.push(...inverseResult.diagnostics);
87
+ generatedLinks = inverseResult.links;
70
88
  entries.clear();
71
89
  for (const entry of inverseResult.entries) {
72
90
  if (!entries.has(entry.displayId)) {
@@ -74,7 +92,8 @@ async function compile(paths, options) {
74
92
  }
75
93
  }
76
94
  }
77
- const links = extractLinks([...entries.values()]);
95
+ const authoredLinks = extractLinks([...entries.values()]);
96
+ const links = [...authoredLinks, ...generatedLinks];
78
97
  // MSL-T013: check link targets for draft/retired state.
79
98
  const linkTargetDiags = (0, link_target_js_1.checkLinkTargets)(entries, links);
80
99
  const forward = buildAdjacency(links, (l) => l.from);
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @module compiler/ndjson_writer
3
+ *
4
+ * NDJSON stream builders for the streaming compile output format.
5
+ *
6
+ * Three pure, Deno-free functions — callers perform the actual file I/O:
7
+ * - {@linkcode buildEntriesNdjson}: entries sorted by displayId
8
+ * - {@linkcode buildEdgesNdjson}: all links (authored + generated)
9
+ * - {@linkcode indexToJson}: compact byte-offset index JSON
10
+ */
11
+ import type { DisplayId, Entry, Link } from "../model/mod.js";
12
+ /** Byte-offset record for a single entry within `entries.ndjson`. */
13
+ export interface EntryOffset {
14
+ readonly offset: number;
15
+ readonly length: number;
16
+ }
17
+ /**
18
+ * Result of {@linkcode buildEntriesNdjson}.
19
+ *
20
+ * `ndjson` is a UTF-8 byte array: one JSON object per line sorted
21
+ * lexicographically by `displayId`. `index` maps each display ID to its
22
+ * byte position within `ndjson`.
23
+ */
24
+ export interface EntriesNdjsonResult {
25
+ readonly ndjson: Uint8Array;
26
+ readonly index: ReadonlyMap<DisplayId, EntryOffset>;
27
+ }
28
+ /**
29
+ * Build the `entries.ndjson` byte stream and byte-offset index.
30
+ *
31
+ * Entries are sorted by `displayId` before serialization so that the output
32
+ * is deterministic regardless of `Map` insertion order. Each line is a
33
+ * compact JSON-serialized entry terminated by `\n`. Byte offsets use
34
+ * UTF-8 byte counting, not JavaScript `.length`.
35
+ */
36
+ export declare function buildEntriesNdjson(entries: ReadonlyMap<DisplayId, Entry>): EntriesNdjsonResult;
37
+ /**
38
+ * Convert a byte-offset index to compact single-line JSON with
39
+ * lexicographically sorted keys — suitable for `entries.idx`.
40
+ */
41
+ export declare function indexToJson(index: ReadonlyMap<DisplayId, EntryOffset>): string;
42
+ /**
43
+ * Build the `edges.ndjson` byte stream.
44
+ *
45
+ * All links (both authored and generated) are written. Each line is a
46
+ * compact JSON object with `from`, `to`, `kind`, and `origin` — the
47
+ * `location` field is omitted as it is not needed for interchange.
48
+ */
49
+ export declare function buildEdgesNdjson(links: readonly Link[]): Uint8Array;
50
+ //# sourceMappingURL=ndjson_writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson_writer.d.ts","sourceRoot":"","sources":["../../src/compiler/ndjson_writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAG9D,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;CACrD;AAID;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,GACrC,mBAAmB,CAkBrB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,GACzC,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,UAAU,CAYnE"}