@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,34 @@
1
+ /**
2
+ * @module core/ast/render
3
+ *
4
+ * Body-AST → canonical body-string renderer. The faithful inverse of
5
+ * `buildBodyAst` on already-canonical input.
6
+ *
7
+ * Invariant: for any canonical body string `s` (i.e. after running the
8
+ * MarkSpec formatter),
9
+ *
10
+ * render(buildBodyAst(s)) === s
11
+ *
12
+ * `render` does NOT re-implement the formatter's normalisation passes
13
+ * (bullet rewriting, blank-line collapse, modal lowercasing). It assumes
14
+ * its input was produced from a body string that is already in canonical
15
+ * form and simply reverses the structural mapping that `build.ts` applied.
16
+ *
17
+ * This module is pure library code: no `Deno.*` APIs.
18
+ */
19
+ import type { BodyBlock } from "./nodes.js";
20
+ /**
21
+ * Serialise a body AST back to canonical MarkSpec body text.
22
+ *
23
+ * This is the faithful inverse of `buildBodyAst` on already-canonical input:
24
+ * for any canonical body string `s`, `render(buildBodyAst(s)) === s`.
25
+ *
26
+ * `render` assumes its input was produced from body text already normalised
27
+ * by the MarkSpec formatter. It does not re-run normalisation passes.
28
+ *
29
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst`.
30
+ * @returns The canonical body string, with blocks separated by a single
31
+ * blank line (two newlines) and no trailing newline.
32
+ */
33
+ export declare function render(blocks: readonly BodyBlock[]): string;
34
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/ast/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAEV,SAAS,EAaV,MAAM,YAAY,CAAC;AA+MpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAG3D"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @module core/ast/render
3
+ *
4
+ * Body-AST → canonical body-string renderer. The faithful inverse of
5
+ * `buildBodyAst` on already-canonical input.
6
+ *
7
+ * Invariant: for any canonical body string `s` (i.e. after running the
8
+ * MarkSpec formatter),
9
+ *
10
+ * render(buildBodyAst(s)) === s
11
+ *
12
+ * `render` does NOT re-implement the formatter's normalisation passes
13
+ * (bullet rewriting, blank-line collapse, modal lowercasing). It assumes
14
+ * its input was produced from a body string that is already in canonical
15
+ * form and simply reverses the structural mapping that `build.ts` applied.
16
+ *
17
+ * This module is pure library code: no `Deno.*` APIs.
18
+ */
19
+ // ---------------------------------------------------------------------------
20
+ // Per-node serialisers
21
+ // ---------------------------------------------------------------------------
22
+ function renderParagraph(node) {
23
+ // The paragraph's text is stored verbatim (markers are recorded as spans
24
+ // but the text is unchanged). Emit the text directly.
25
+ return node.content.text;
26
+ }
27
+ function renderList(node) {
28
+ const itemLines = [];
29
+ for (const item of node.items) {
30
+ const rendered = renderListItem(item, node.ordered, itemLines.length + 1);
31
+ itemLines.push(rendered);
32
+ }
33
+ // Loose lists (spread=true) have blank lines between items in source;
34
+ // tight lists do not.
35
+ return itemLines.join(node.spread ? "\n\n" : "\n");
36
+ }
37
+ function renderListItem(item, ordered, index) {
38
+ if (item.blocks.length === 0) {
39
+ const bullet = ordered ? `${index}.` : "-";
40
+ return bullet;
41
+ }
42
+ const firstBlock = item.blocks[0];
43
+ const restBlocks = item.blocks.slice(1);
44
+ // The bullet prefix for the first block.
45
+ const bullet = ordered ? `${index}.` : "-";
46
+ // Render the first block. For a paragraph, the text follows the bullet
47
+ // directly. For any other block, we render it indented.
48
+ let firstLine;
49
+ let extraLines = [];
50
+ // GFM task-list checkbox, re-emitted right after the bullet. Absent for
51
+ // non-task items (`item.checked === undefined`); independent of
52
+ // `ListNode.hasTaskItems`, so MSL-B042 is unaffected.
53
+ const checkbox = item.checked === undefined
54
+ ? ""
55
+ : item.checked
56
+ ? "[x] "
57
+ : "[ ] ";
58
+ if (firstBlock.kind === "paragraph") {
59
+ // `- text` — inline with the bullet.
60
+ const text = firstBlock.content.text;
61
+ const textLines = text.split("\n");
62
+ firstLine = `${bullet} ${checkbox}${textLines[0]}`;
63
+ // Known limitation: continuation-line indent is a fixed 2 spaces and
64
+ // does not account for checkbox width, so a MULTI-LINE paragraph in a
65
+ // task-list item (`- [x] line one\n line two`) does not round-trip
66
+ // byte-identically. Task lists are an excluded construct (MSL-B042);
67
+ // the corpus only exercises single-line task items, so no canonical
68
+ // input regresses and the equivalence gate stays green.
69
+ if (textLines.length > 1) {
70
+ // Continuation lines of a multi-line paragraph are indented to align
71
+ // with the first character after the bullet (`- ` = 2 chars).
72
+ extraLines = textLines.slice(1).map((l) => (l ? ` ${l}` : ""));
73
+ }
74
+ }
75
+ else {
76
+ // Block content that isn't a paragraph: render on its own line(s),
77
+ // indented by 2 spaces.
78
+ firstLine = checkbox ? `${bullet} ${checkbox}`.trimEnd() : bullet;
79
+ const blockStr = renderBlock(firstBlock);
80
+ extraLines = blockStr.split("\n").map((l) => (l ? ` ${l}` : ""));
81
+ }
82
+ const allLines = [firstLine, ...extraLines];
83
+ // Remaining blocks in the item, indented. A "loose" item
84
+ // (`listItem.spread`, captured from mdast) separates its blocks with a
85
+ // blank line in source; a tight item (e.g. a paragraph with a nested
86
+ // list directly under it) does not. Gating on the item's own spread —
87
+ // NOT the list-level `ListNode.spread` — keeps loose multi-block items
88
+ // byte-identical while letting tight nested lists round-trip.
89
+ for (const block of restBlocks) {
90
+ if (item.spread)
91
+ allLines.push(""); // blank line before next block
92
+ const blockStr = renderBlock(block);
93
+ for (const l of blockStr.split("\n")) {
94
+ allLines.push(l ? ` ${l}` : "");
95
+ }
96
+ }
97
+ return allLines.join("\n");
98
+ }
99
+ function renderTable(node) {
100
+ // Emit the verbatim source substring captured at parse time.
101
+ // This preserves author column widths exactly (e.g. a separator row
102
+ // wider than its cell content) for byte-identical round-trip,
103
+ // matching the behaviour of CodeNode, FeatureNode, MathNode, and
104
+ // UnknownNode which also carry their raw source text.
105
+ return node.raw;
106
+ }
107
+ function renderFigure(node) {
108
+ return `![${node.alt}](${node.path})`;
109
+ }
110
+ function renderCode(node) {
111
+ const lang = node.lang ?? "";
112
+ return `\`\`\`${lang}\n${node.text}\n\`\`\``;
113
+ }
114
+ function renderFeature(node) {
115
+ return `\`\`\`gherkin\n${node.source}\n\`\`\``;
116
+ }
117
+ function renderMath(node) {
118
+ // build.ts splits on `$$…$$`. The tex field is the inner content
119
+ // (including any surrounding whitespace). Match what MATH_BLOCK_RE captured:
120
+ // the regex is /^\$\$([\s\S]*?)\$\$$/ so tex may start/end with \n.
121
+ return `$$${node.tex}$$`;
122
+ }
123
+ function renderDefinitionList(node) {
124
+ return node.items
125
+ .map((item) => `${item.term.text}\n: ${item.definition.text}`)
126
+ .join("\n\n");
127
+ }
128
+ function renderNote(node) {
129
+ // build.ts stores the content text with `\n\n` between paragraphs
130
+ // that were separated by a blank quoted line in the source. Reconstruct
131
+ // by prefixing every non-empty content line with `> ` and every empty
132
+ // line (the paragraph separator) with bare `>` (no trailing space),
133
+ // matching the canonical blank-quoted-line format.
134
+ const text = node.content.text;
135
+ if (!text)
136
+ return `> [!${node.admonition}]`;
137
+ const lines = text.split("\n");
138
+ if (node.markerInline) {
139
+ // Body began on the marker line in source — reproduce that form:
140
+ // first content line stays on `> [!KIND] …`, the rest are quoted.
141
+ const [first, ...rest] = lines;
142
+ return `> [!${node.admonition}] ${first}` +
143
+ (rest.length
144
+ ? "\n" + rest.map((l) => l ? `> ${l}` : `>`).join("\n")
145
+ : "");
146
+ }
147
+ return `> [!${node.admonition}]\n` +
148
+ lines.map((l) => l ? `> ${l}` : `>`).join("\n");
149
+ }
150
+ function renderBlockquote(node) {
151
+ // build.ts stores the content text with `\n\n` between paragraphs
152
+ // that were separated by a blank quoted line in the source. Re-add
153
+ // `> ` to every non-empty line and bare `>` to every empty line for
154
+ // byte-identical round-trip.
155
+ const text = node.content.text;
156
+ return text.split("\n").map((l) => l ? `> ${l}` : `>`).join("\n");
157
+ }
158
+ function renderCaption(node) {
159
+ return `${node.keyword}: ${node.text}`;
160
+ }
161
+ function renderUnknown(node) {
162
+ return node.raw;
163
+ }
164
+ // ---------------------------------------------------------------------------
165
+ // Block dispatcher
166
+ // ---------------------------------------------------------------------------
167
+ function renderBlock(block) {
168
+ switch (block.kind) {
169
+ case "paragraph":
170
+ return renderParagraph(block);
171
+ case "list":
172
+ return renderList(block);
173
+ case "table":
174
+ return renderTable(block);
175
+ case "figure":
176
+ return renderFigure(block);
177
+ case "code":
178
+ return renderCode(block);
179
+ case "feature":
180
+ return renderFeature(block);
181
+ case "math":
182
+ return renderMath(block);
183
+ case "definition-list":
184
+ return renderDefinitionList(block);
185
+ case "note":
186
+ return renderNote(block);
187
+ case "blockquote":
188
+ return renderBlockquote(block);
189
+ case "caption":
190
+ return renderCaption(block);
191
+ case "unknown":
192
+ return renderUnknown(block);
193
+ }
194
+ }
195
+ // ---------------------------------------------------------------------------
196
+ // Public API
197
+ // ---------------------------------------------------------------------------
198
+ /**
199
+ * Serialise a body AST back to canonical MarkSpec body text.
200
+ *
201
+ * This is the faithful inverse of `buildBodyAst` on already-canonical input:
202
+ * for any canonical body string `s`, `render(buildBodyAst(s)) === s`.
203
+ *
204
+ * `render` assumes its input was produced from body text already normalised
205
+ * by the MarkSpec formatter. It does not re-run normalisation passes.
206
+ *
207
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst`.
208
+ * @returns The canonical body string, with blocks separated by a single
209
+ * blank line (two newlines) and no trailing newline.
210
+ */
211
+ export function render(blocks) {
212
+ if (blocks.length === 0)
213
+ return "";
214
+ return blocks.map(renderBlock).join("\n\n");
215
+ }
@@ -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"}
@@ -12,14 +12,32 @@
12
12
  * an `inverse:` declaration in the effective profile, then accumulates
13
13
  * back-links on target entries.
14
14
  */
15
+ /**
16
+ * Attribute-name → LinkKind for forward-link attributes that may carry
17
+ * inverse declarations. Used to tag generated back-link edges with the
18
+ * forward relationship kind so consumers can reconstruct the full graph.
19
+ */
20
+ const ATTR_TO_LINK_KIND = {
21
+ "Satisfies": "satisfies",
22
+ "Derived-from": "derived-from",
23
+ "References": "references",
24
+ "Allocated-to": "allocated-to",
25
+ "Realizes": "realizes",
26
+ "Verifies": "verifies",
27
+ "Tests": "tests",
28
+ "Depends-on": "depends-on",
29
+ "Part-of": "part-of",
30
+ "Generated-from": "generated-from",
31
+ "Supersedes": "supersedes",
32
+ };
15
33
  export function generateInverses(entries, profile) {
16
34
  if (entries.length === 0) {
17
- return { entries: [], diagnostics: [] };
35
+ return { entries: [], links: [], diagnostics: [] };
18
36
  }
19
37
  // Step 1: Collect all inverse declarations from the profile
20
38
  const inverseSpecs = collectInverseSpecs(profile);
21
39
  if (inverseSpecs.length === 0) {
22
- return { entries: [...entries], diagnostics: [] };
40
+ return { entries: [...entries], links: [], diagnostics: [] };
23
41
  }
24
42
  // Step 2: Index entries by id
25
43
  const byId = new Map();
@@ -31,8 +49,10 @@ export function generateInverses(entries, profile) {
31
49
  // Step 3–5: Walk entries, accumulate back-links
32
50
  // Map: targetId → Map<inverseAttrName, Set<sourceId>>
33
51
  const generated = new Map();
52
+ // Parallel list of raw generated-edge data for Link emission.
53
+ const generatedEdges = [];
34
54
  for (const source of entries) {
35
- if (source.shape !== "identified" || source.id === undefined)
55
+ if (source.shape !== "Authored" || source.id === undefined)
36
56
  continue;
37
57
  const applicableSpecs = resolveApplicableSpecs(inverseSpecs, source.type);
38
58
  for (const spec of applicableSpecs) {
@@ -53,7 +73,15 @@ export function generateInverses(entries, profile) {
53
73
  idSet = new Set();
54
74
  targetMap.set(spec.inverse.name, idSet);
55
75
  }
76
+ const wasNew = !idSet.has(source.id);
56
77
  idSet.add(source.id);
78
+ if (wasNew) {
79
+ generatedEdges.push({
80
+ targetUlid: targetId,
81
+ sourceUlid: source.id,
82
+ attrName: spec.attrName,
83
+ });
84
+ }
57
85
  }
58
86
  }
59
87
  }
@@ -102,7 +130,25 @@ export function generateInverses(entries, profile) {
102
130
  result.push(e);
103
131
  }
104
132
  }
105
- return { entries: result, diagnostics };
133
+ // Resolve generated edges to displayId-based Link objects.
134
+ const links = [];
135
+ for (const { targetUlid, sourceUlid, attrName } of generatedEdges) {
136
+ const kind = ATTR_TO_LINK_KIND[attrName];
137
+ if (!kind)
138
+ continue;
139
+ const target = byId.get(targetUlid);
140
+ const source = byId.get(sourceUlid);
141
+ if (!target || !source)
142
+ continue;
143
+ links.push({
144
+ from: target.displayId,
145
+ to: source.displayId,
146
+ kind,
147
+ location: source.location,
148
+ origin: "generated",
149
+ });
150
+ }
151
+ return { entries: result, links, diagnostics };
106
152
  }
107
153
  /** Collect all inverse-bearing attribute declarations from the profile. */
108
154
  function collectInverseSpecs(profile) {
@@ -117,16 +163,6 @@ function collectInverseSpecs(profile) {
117
163
  });
118
164
  }
119
165
  }
120
- // Identified shape scope
121
- for (const [, entry] of profile.identified.attributes) {
122
- if (entry.value.inverse) {
123
- specs.push({
124
- attrName: entry.value.name,
125
- inverse: entry.value.inverse,
126
- sourceType: null,
127
- });
128
- }
129
- }
130
166
  // Type scopes
131
167
  for (const [typeName, typeEntry] of profile.types) {
132
168
  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
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/compiler/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAA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E,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,48 @@
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
+ /**
10
+ * Build the `manifest.json` object for a compiled project.
11
+ *
12
+ * When `streaming` is false (default): emits the Tier 1 inline form —
13
+ * both `entries` and `edges` point at `compiled.json`.
14
+ * When `streaming` is true: emits the Tier 2 NDJSON form —
15
+ * entries → `entries.ndjson` + `entries.idx`, edges → `edges.ndjson`.
16
+ */
17
+ export function buildManifest(result, config, projectRoot, _profile, version, streaming = false) {
18
+ const byType = {};
19
+ for (const entry of result.entries.values()) {
20
+ const typeName = entry.type ?? "unknown";
21
+ byType[typeName] = (byType[typeName] ?? 0) + 1;
22
+ }
23
+ return {
24
+ markspecSchemaVersion: 1,
25
+ generator: {
26
+ release: version,
27
+ coreSchema: 1,
28
+ },
29
+ project: {
30
+ name: config.name ?? "",
31
+ root: projectRoot,
32
+ },
33
+ counts: {
34
+ entries: result.entries.size,
35
+ edges: result.links.length,
36
+ byType,
37
+ },
38
+ entries: streaming
39
+ ? { format: "ndjson", file: "entries.ndjson", index: "entries.idx" }
40
+ : { format: "inline", file: "compiled.json" },
41
+ edges: streaming
42
+ ? { format: "ndjson", file: "edges.ndjson" }
43
+ : { format: "inline", file: "compiled.json" },
44
+ sqliteMirror: null,
45
+ federation: config.parents ?? [],
46
+ reserved: {},
47
+ };
48
+ }
@@ -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,EACL,IAAI,EAGL,MAAM,iBAAiB,CAAC;AAMzB,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,gEAAgE;AAChE,MAAM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const result = await parseFile(content, { file: filePath });
40
- allEntries.push(...result.entries);
40
+ const stat = options.statFile
41
+ ? await options.statFile(filePath)
42
+ : undefined;
43
+ const mtimeStr = stat?.mtime ? stat.mtime.toISOString() : undefined;
44
+ const annotatedEntries = result.entries.map((entry) => ({
45
+ ...entry,
46
+ properties: {
47
+ ...entry.properties,
48
+ file: {
49
+ path: filePath,
50
+ line: entry.location.line,
51
+ column: entry.location.column,
52
+ mtime: mtimeStr,
53
+ },
54
+ },
55
+ }));
56
+ allEntries.push(...annotatedEntries);
41
57
  parseDiagnostics.push(...result.diagnostics);
42
58
  if (result.document)
43
59
  documents.set(filePath, result.document);
@@ -60,9 +76,11 @@ export async function compile(paths, options) {
60
76
  }
61
77
  }
62
78
  // Phase 3.5: Generate inverse attributes from profile declarations.
79
+ let generatedLinks = [];
63
80
  if (options.profile) {
64
81
  const inverseResult = generateInverses([...entries.values()], options.profile);
65
82
  parseDiagnostics.push(...inverseResult.diagnostics);
83
+ generatedLinks = inverseResult.links;
66
84
  entries.clear();
67
85
  for (const entry of inverseResult.entries) {
68
86
  if (!entries.has(entry.displayId)) {
@@ -70,7 +88,8 @@ export async function compile(paths, options) {
70
88
  }
71
89
  }
72
90
  }
73
- const links = extractLinks([...entries.values()]);
91
+ const authoredLinks = extractLinks([...entries.values()]);
92
+ const links = [...authoredLinks, ...generatedLinks];
74
93
  // MSL-T013: check link targets for draft/retired state.
75
94
  const linkTargetDiags = checkLinkTargets(entries, links);
76
95
  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"}