@hydranium/cli 1.0.0-next.4 → 1.0.0-next.400

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 (340) hide show
  1. package/README.md +102 -204
  2. package/bin/hydranium-cli.js +13 -0
  3. package/heap-analysis/heap/core/load.mjs +2 -2
  4. package/heap-analysis/heap/langium/langium.classifier.mjs +22 -11
  5. package/lib/cli-version.js.map +1 -1
  6. package/lib/cli.js +7 -2
  7. package/lib/cli.js.map +1 -1
  8. package/lib/commands/analyze-heap-args.d.ts.map +1 -1
  9. package/lib/commands/analyze-heap-args.js +1 -2
  10. package/lib/commands/analyze-heap-args.js.map +1 -1
  11. package/lib/commands/analyze-heap.d.ts +3 -0
  12. package/lib/commands/analyze-heap.d.ts.map +1 -1
  13. package/lib/commands/analyze-heap.js +2 -1
  14. package/lib/commands/analyze-heap.js.map +1 -1
  15. package/lib/commands/ast-ground-truth-args.d.ts +3 -2
  16. package/lib/commands/ast-ground-truth-args.d.ts.map +1 -1
  17. package/lib/commands/ast-ground-truth-args.js +11 -9
  18. package/lib/commands/ast-ground-truth-args.js.map +1 -1
  19. package/lib/commands/ast-ground-truth-driver.js +4 -2
  20. package/lib/commands/ast-ground-truth-driver.js.map +1 -1
  21. package/lib/commands/ast-ground-truth.js +1 -1
  22. package/lib/commands/ast-ground-truth.js.map +1 -1
  23. package/lib/commands/client-session.d.ts +17 -0
  24. package/lib/commands/client-session.d.ts.map +1 -0
  25. package/lib/commands/client-session.js +27 -0
  26. package/lib/commands/client-session.js.map +1 -0
  27. package/lib/commands/create-args.d.ts +17 -0
  28. package/lib/commands/create-args.d.ts.map +1 -0
  29. package/lib/commands/create-args.js +53 -0
  30. package/lib/commands/create-args.js.map +1 -0
  31. package/lib/commands/create.d.ts +38 -0
  32. package/lib/commands/create.d.ts.map +1 -0
  33. package/lib/commands/create.js +43 -0
  34. package/lib/commands/create.js.map +1 -0
  35. package/lib/commands/delete-args.d.ts +17 -0
  36. package/lib/commands/delete-args.d.ts.map +1 -0
  37. package/lib/commands/delete-args.js +49 -0
  38. package/lib/commands/delete-args.js.map +1 -0
  39. package/lib/commands/delete.d.ts +30 -0
  40. package/lib/commands/delete.d.ts.map +1 -0
  41. package/lib/commands/delete.js +32 -0
  42. package/lib/commands/delete.js.map +1 -0
  43. package/lib/commands/generate-ast-builder.d.ts +49 -0
  44. package/lib/commands/generate-ast-builder.d.ts.map +1 -0
  45. package/lib/commands/generate-ast-builder.js +191 -0
  46. package/lib/commands/generate-ast-builder.js.map +1 -0
  47. package/lib/commands/generate-languages.d.ts +35 -0
  48. package/lib/commands/generate-languages.d.ts.map +1 -0
  49. package/lib/commands/generate-languages.js +105 -0
  50. package/lib/commands/generate-languages.js.map +1 -0
  51. package/lib/commands/generate-transfer-builder.d.ts +33 -0
  52. package/lib/commands/generate-transfer-builder.d.ts.map +1 -0
  53. package/lib/commands/generate-transfer-builder.js +86 -0
  54. package/lib/commands/generate-transfer-builder.js.map +1 -0
  55. package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
  56. package/lib/commands/generate-transfer-model-args.js +30 -5
  57. package/lib/commands/generate-transfer-model-args.js.map +1 -1
  58. package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
  59. package/lib/commands/generate-transfer-model-config.js +10 -3
  60. package/lib/commands/generate-transfer-model-config.js.map +1 -1
  61. package/lib/commands/generate-transfer-model.d.ts +49 -9
  62. package/lib/commands/generate-transfer-model.d.ts.map +1 -1
  63. package/lib/commands/generate-transfer-model.js +235 -70
  64. package/lib/commands/generate-transfer-model.js.map +1 -1
  65. package/lib/commands/generated-module-path.d.ts +16 -0
  66. package/lib/commands/generated-module-path.d.ts.map +1 -0
  67. package/lib/commands/generated-module-path.js +21 -0
  68. package/lib/commands/generated-module-path.js.map +1 -0
  69. package/lib/commands/harness-args.d.ts +44 -42
  70. package/lib/commands/harness-args.d.ts.map +1 -1
  71. package/lib/commands/harness-args.js +109 -27
  72. package/lib/commands/harness-args.js.map +1 -1
  73. package/lib/commands/headless-harness.d.ts +37 -20
  74. package/lib/commands/headless-harness.d.ts.map +1 -1
  75. package/lib/commands/headless-harness.js +71 -19
  76. package/lib/commands/headless-harness.js.map +1 -1
  77. package/lib/commands/init-args.d.ts +2 -0
  78. package/lib/commands/init-args.d.ts.map +1 -1
  79. package/lib/commands/init-args.js +74 -31
  80. package/lib/commands/init-args.js.map +1 -1
  81. package/lib/commands/init-hosts.d.ts +24 -0
  82. package/lib/commands/init-hosts.d.ts.map +1 -0
  83. package/lib/commands/init-hosts.js +37 -0
  84. package/lib/commands/init-hosts.js.map +1 -0
  85. package/lib/commands/init-prompt.d.ts +3 -3
  86. package/lib/commands/init-prompt.d.ts.map +1 -1
  87. package/lib/commands/init-prompt.js +4 -5
  88. package/lib/commands/init-prompt.js.map +1 -1
  89. package/lib/commands/init-templates.d.ts +20 -14
  90. package/lib/commands/init-templates.d.ts.map +1 -1
  91. package/lib/commands/init-templates.js +3015 -750
  92. package/lib/commands/init-templates.js.map +1 -1
  93. package/lib/commands/init-wizard.d.ts +3 -0
  94. package/lib/commands/init-wizard.d.ts.map +1 -1
  95. package/lib/commands/init-wizard.js +46 -31
  96. package/lib/commands/init-wizard.js.map +1 -1
  97. package/lib/commands/init-workspace.d.ts +13 -11
  98. package/lib/commands/init-workspace.d.ts.map +1 -1
  99. package/lib/commands/init-workspace.js +21 -7
  100. package/lib/commands/init-workspace.js.map +1 -1
  101. package/lib/commands/init.d.ts +58 -22
  102. package/lib/commands/init.d.ts.map +1 -1
  103. package/lib/commands/init.js +203 -48
  104. package/lib/commands/init.js.map +1 -1
  105. package/lib/commands/kebab.d.ts +15 -0
  106. package/lib/commands/kebab.d.ts.map +1 -0
  107. package/lib/commands/kebab.js +17 -0
  108. package/lib/commands/kebab.js.map +1 -0
  109. package/lib/commands/lint-grammar-args.d.ts +3 -2
  110. package/lib/commands/lint-grammar-args.d.ts.map +1 -1
  111. package/lib/commands/lint-grammar-args.js +13 -10
  112. package/lib/commands/lint-grammar-args.js.map +1 -1
  113. package/lib/commands/lint-grammar-driver.js +2 -1
  114. package/lib/commands/lint-grammar-driver.js.map +1 -1
  115. package/lib/commands/lint-grammar-report.js.map +1 -1
  116. package/lib/commands/lint-grammar.js +1 -1
  117. package/lib/commands/lint-grammar.js.map +1 -1
  118. package/lib/commands/measure-memory-args.d.ts +3 -2
  119. package/lib/commands/measure-memory-args.d.ts.map +1 -1
  120. package/lib/commands/measure-memory-args.js +22 -11
  121. package/lib/commands/measure-memory-args.js.map +1 -1
  122. package/lib/commands/measure-memory-driver.js +5 -3
  123. package/lib/commands/measure-memory-driver.js.map +1 -1
  124. package/lib/commands/measure-memory.js +1 -1
  125. package/lib/commands/measure-memory.js.map +1 -1
  126. package/lib/commands/model-docs-args.d.ts +4 -3
  127. package/lib/commands/model-docs-args.d.ts.map +1 -1
  128. package/lib/commands/model-docs-args.js +12 -10
  129. package/lib/commands/model-docs-args.js.map +1 -1
  130. package/lib/commands/model-docs-driver.js +2 -1
  131. package/lib/commands/model-docs-driver.js.map +1 -1
  132. package/lib/commands/model-docs.js +1 -1
  133. package/lib/commands/model-docs.js.map +1 -1
  134. package/lib/commands/projects-args.d.ts.map +1 -1
  135. package/lib/commands/projects-args.js +5 -5
  136. package/lib/commands/projects-args.js.map +1 -1
  137. package/lib/commands/projects.d.ts +3 -4
  138. package/lib/commands/projects.d.ts.map +1 -1
  139. package/lib/commands/projects.js +2 -2
  140. package/lib/commands/projects.js.map +1 -1
  141. package/lib/commands/query-args.d.ts.map +1 -1
  142. package/lib/commands/query-args.js +6 -5
  143. package/lib/commands/query-args.js.map +1 -1
  144. package/lib/commands/query.d.ts +6 -5
  145. package/lib/commands/query.d.ts.map +1 -1
  146. package/lib/commands/query.js +5 -4
  147. package/lib/commands/query.js.map +1 -1
  148. package/lib/commands/reflect-args.d.ts +3 -2
  149. package/lib/commands/reflect-args.d.ts.map +1 -1
  150. package/lib/commands/reflect-args.js +13 -10
  151. package/lib/commands/reflect-args.js.map +1 -1
  152. package/lib/commands/reflect-driver.js +2 -1
  153. package/lib/commands/reflect-driver.js.map +1 -1
  154. package/lib/commands/reflect-report.js.map +1 -1
  155. package/lib/commands/reflect.js +1 -1
  156. package/lib/commands/reflect.js.map +1 -1
  157. package/lib/commands/save-args.d.ts.map +1 -1
  158. package/lib/commands/save-args.js +7 -4
  159. package/lib/commands/save-args.js.map +1 -1
  160. package/lib/commands/save.d.ts +8 -4
  161. package/lib/commands/save.d.ts.map +1 -1
  162. package/lib/commands/save.js +12 -23
  163. package/lib/commands/save.js.map +1 -1
  164. package/lib/commands/validate-args.d.ts +3 -2
  165. package/lib/commands/validate-args.d.ts.map +1 -1
  166. package/lib/commands/validate-args.js +13 -10
  167. package/lib/commands/validate-args.js.map +1 -1
  168. package/lib/commands/validate-driver.js +2 -1
  169. package/lib/commands/validate-driver.js.map +1 -1
  170. package/lib/commands/validate-report.js.map +1 -1
  171. package/lib/commands/validate.js +1 -1
  172. package/lib/commands/validate.js.map +1 -1
  173. package/lib/commands/watch-args.d.ts.map +1 -1
  174. package/lib/commands/watch-args.js +6 -4
  175. package/lib/commands/watch-args.js.map +1 -1
  176. package/lib/commands/watch.d.ts +3 -4
  177. package/lib/commands/watch.d.ts.map +1 -1
  178. package/lib/commands/watch.js +20 -2
  179. package/lib/commands/watch.js.map +1 -1
  180. package/lib/driver-heap.d.ts +52 -0
  181. package/lib/driver-heap.d.ts.map +1 -0
  182. package/lib/driver-heap.js +51 -0
  183. package/lib/driver-heap.js.map +1 -0
  184. package/lib/index.d.ts +3 -0
  185. package/lib/index.d.ts.map +1 -1
  186. package/lib/index.js +3 -0
  187. package/lib/index.js.map +1 -1
  188. package/lib/log-level.d.ts +21 -11
  189. package/lib/log-level.d.ts.map +1 -1
  190. package/lib/log-level.js +25 -14
  191. package/lib/log-level.js.map +1 -1
  192. package/lib/spawn-data-server.d.ts +9 -4
  193. package/lib/spawn-data-server.d.ts.map +1 -1
  194. package/lib/spawn-data-server.js +5 -4
  195. package/lib/spawn-data-server.js.map +1 -1
  196. package/lib/stderr-connection-logger.d.ts +12 -0
  197. package/lib/stderr-connection-logger.d.ts.map +1 -0
  198. package/lib/stderr-connection-logger.js +16 -0
  199. package/lib/stderr-connection-logger.js.map +1 -0
  200. package/lib/testing/echo-server.js +9 -1
  201. package/lib/testing/echo-server.js.map +1 -1
  202. package/package.json +90 -38
  203. package/src/cli.ts +7 -2
  204. package/src/commands/analyze-heap-args.ts +1 -2
  205. package/src/commands/analyze-heap.ts +4 -1
  206. package/src/commands/ast-ground-truth-args.ts +15 -12
  207. package/src/commands/ast-ground-truth-driver.ts +4 -2
  208. package/src/commands/ast-ground-truth.ts +1 -1
  209. package/src/commands/client-session.ts +33 -0
  210. package/src/commands/create-args.ts +68 -0
  211. package/src/commands/create.ts +83 -0
  212. package/src/commands/delete-args.ts +64 -0
  213. package/src/commands/delete.ts +61 -0
  214. package/src/commands/generate-ast-builder.ts +236 -0
  215. package/src/commands/generate-languages.ts +132 -0
  216. package/src/commands/generate-transfer-builder.ts +101 -0
  217. package/src/commands/generate-transfer-model-args.ts +30 -5
  218. package/src/commands/generate-transfer-model-config.ts +10 -3
  219. package/src/commands/generate-transfer-model.ts +316 -68
  220. package/src/commands/generated-module-path.ts +22 -0
  221. package/src/commands/harness-args.ts +99 -31
  222. package/src/commands/headless-harness.ts +89 -28
  223. package/src/commands/init-args.ts +76 -31
  224. package/src/commands/init-hosts.ts +51 -0
  225. package/src/commands/init-prompt.ts +5 -6
  226. package/src/commands/init-templates.ts +3183 -760
  227. package/src/commands/init-wizard.ts +55 -31
  228. package/src/commands/init-workspace.ts +31 -16
  229. package/src/commands/init.ts +261 -63
  230. package/src/commands/kebab.ts +17 -0
  231. package/src/commands/lint-grammar-args.ts +17 -13
  232. package/src/commands/lint-grammar-driver.ts +2 -1
  233. package/src/commands/lint-grammar.ts +1 -1
  234. package/src/commands/measure-memory-args.ts +27 -14
  235. package/src/commands/measure-memory-driver.ts +5 -3
  236. package/src/commands/measure-memory.ts +1 -1
  237. package/src/commands/model-docs-args.ts +16 -13
  238. package/src/commands/model-docs-driver.ts +2 -1
  239. package/src/commands/model-docs.ts +1 -1
  240. package/src/commands/projects-args.ts +5 -4
  241. package/src/commands/projects.ts +4 -6
  242. package/src/commands/query-args.ts +6 -4
  243. package/src/commands/query.ts +9 -9
  244. package/src/commands/reflect-args.ts +17 -13
  245. package/src/commands/reflect-driver.ts +2 -1
  246. package/src/commands/reflect.ts +1 -1
  247. package/src/commands/save-args.ts +7 -3
  248. package/src/commands/save.ts +24 -27
  249. package/src/commands/validate-args.ts +17 -13
  250. package/src/commands/validate-driver.ts +2 -1
  251. package/src/commands/validate.ts +1 -1
  252. package/src/commands/watch-args.ts +6 -3
  253. package/src/commands/watch.ts +28 -7
  254. package/src/driver-heap.ts +65 -0
  255. package/src/index.ts +3 -0
  256. package/src/log-level.ts +42 -14
  257. package/src/spawn-data-server.ts +17 -5
  258. package/src/stderr-connection-logger.ts +18 -0
  259. package/src/testing/echo-server.ts +11 -2
  260. package/templates/client/gitignore +3 -0
  261. package/templates/client/src/__GRAMMAR_ID__-diagram-module.ts +82 -0
  262. package/templates/editorconfig +15 -0
  263. package/templates/gitignore +1 -0
  264. package/templates/host-browser/esbuild.mjs +82 -0
  265. package/templates/host-browser/gitignore +4 -0
  266. package/templates/host-browser/hydranium-mark.svg +40 -0
  267. package/templates/host-browser/index.html +287 -0
  268. package/templates/host-browser/playwright.config.mts +24 -0
  269. package/templates/host-browser/src/data-status.ts +15 -0
  270. package/templates/host-browser/src/diagram-save.ts +60 -0
  271. package/templates/host-browser/src/diagram.ts +121 -0
  272. package/templates/host-browser/src/editor.ts +102 -0
  273. package/templates/host-browser/src/log.ts +14 -0
  274. package/templates/host-browser/src/monaco-editor-core-worker.d.ts +7 -0
  275. package/templates/host-browser/src/monaco-editor-worker.ts +10 -0
  276. package/templates/host-browser/src/posix-path-shim.ts +23 -0
  277. package/templates/host-browser/src/shown-file.ts +61 -0
  278. package/templates/host-browser/src/workspace.ts +5 -0
  279. package/templates/host-browser/tsconfig.e2e.json +16 -0
  280. package/templates/host-browser/tsconfig.page.json +16 -0
  281. package/templates/host-browser/tsconfig.worker.json +16 -0
  282. package/templates/host-theia-browser/esbuild.mjs +24 -0
  283. package/templates/host-theia-browser/gitignore +9 -0
  284. package/templates/host-theia-browser/playwright.config.mts +42 -0
  285. package/templates/host-theia-browser/start.mjs +50 -0
  286. package/templates/host-theia-browser/tsconfig.e2e.json +16 -0
  287. package/templates/host-theia-electron/esbuild.mjs +27 -0
  288. package/templates/host-theia-electron/gitignore +8 -0
  289. package/templates/host-theia-electron/playwright.config.mts +12 -0
  290. package/templates/host-theia-electron/start.mjs +47 -0
  291. package/templates/host-theia-electron/tsconfig.e2e.json +16 -0
  292. package/templates/host-vscode/esbuild.mjs +38 -0
  293. package/templates/host-vscode/gitignore +7 -0
  294. package/templates/host-vscode/playwright.config.mts +14 -0
  295. package/templates/host-vscode/src/__GRAMMAR_ID__-diagram-editor.ts +19 -0
  296. package/templates/host-vscode/src/show-model-command.ts +24 -0
  297. package/templates/host-vscode/src/webview/__GRAMMAR_ID__-diagram.ts +18 -0
  298. package/templates/host-vscode/src/webview/diagram.css +40 -0
  299. package/templates/host-vscode/start.mjs +22 -0
  300. package/templates/host-vscode/test/install-vscode.mts +21 -0
  301. package/templates/host-vscode/test/vscode-version.mts +10 -0
  302. package/templates/host-vscode/tsconfig.e2e.json +17 -0
  303. package/templates/host-vscode/tsconfig.json +19 -0
  304. package/templates/host-vscode/tsconfig.webview.json +17 -0
  305. package/templates/oxlintrc.json +4 -0
  306. package/templates/protocol/gitignore +3 -0
  307. package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +47 -0
  308. package/templates/server/gitignore +6 -0
  309. package/templates/server/src/glsp/__GRAMMAR_ID__/create-node-operation-handler.ts +62 -0
  310. package/templates/server/src/glsp/__GRAMMAR_ID__/delete-operation-handler.ts +63 -0
  311. package/templates/server/src/glsp/__GRAMMAR_ID__/gmodel-factory.ts +144 -0
  312. package/templates/server/src/glsp/__GRAMMAR_ID__/state.ts +18 -0
  313. package/templates/server/src/glsp/__GRAMMAR_ID__/storage.ts +16 -0
  314. package/templates/server/src/glsp/__GRAMMAR_ID__/submission-handler.ts +24 -0
  315. package/templates/server/src/grammar/common.langium +12 -0
  316. package/templates/server/src/language-server/__GRAMMAR_ID__-serializer.ts +53 -0
  317. package/templates/server/src/language-server/__GRAMMAR_ID__-validation.ts +30 -0
  318. package/templates/server/src/language-server/ast.ts +23 -0
  319. package/templates/server/src/node/services.ts +16 -0
  320. package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +403 -0
  321. package/templates/server/test/tsconfig.json +4 -0
  322. package/templates/server/tsconfig.test.json +10 -0
  323. package/templates/server/vitest.config.ts +14 -0
  324. package/templates/theia/gitignore +3 -0
  325. package/templates/theia/src/browser/__GRAMMAR_ID__-diagram-frontend-module.ts +65 -0
  326. package/templates/theia/src/browser/__PROJECT_ID__-connection-preload-module.ts +15 -0
  327. package/templates/theia/src/browser/__PROJECT_ID__-data-connection.ts +15 -0
  328. package/templates/theia/src/browser/__PROJECT_ID__-data-port.ts +11 -0
  329. package/templates/theia/src/browser/__PROJECT_ID__-glsp-client-contribution.ts +13 -0
  330. package/templates/theia/src/browser/__PROJECT_ID__-show-model-command.ts +51 -0
  331. package/templates/theia/src/common/__PROJECT_ID__-glsp-contribution.ts +3 -0
  332. package/templates/theia/src/node/__PROJECT_ID__-connection-backend-module.ts +12 -0
  333. package/templates/theia/src/node/__PROJECT_ID__-data-backend-module.ts +15 -0
  334. package/templates/theia/src/node/__PROJECT_ID__-glsp-backend-module.ts +16 -0
  335. package/templates/theia/style/diagram.css +20 -0
  336. package/templates/theia/tsconfig.json +24 -0
  337. package/templates/vscode-servers/gitignore +4 -0
  338. package/templates/vscode-servers/tsconfig.json +19 -0
  339. package/templates/workspace/nodes.__EXTENSION__ +5 -0
  340. package/templates/workspace/references.__EXTENSION__ +2 -0
@@ -1 +1 @@
1
- {"version":3,"file":"generate-transfer-model-config.js","sourceRoot":"","sources":["../../src/commands/generate-transfer-model-config.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,+FAA+F;AAC/F,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,SAAS,CAAU,CAAC;AAEtE,0FAA0F;AAC1F,SAAS,cAAc,CAAC,OAAe,EAAE,KAAa;IACnD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAkB;IACvD,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACF,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,sCAAsC,UAAU,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnI,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,0BAA0B,UAAU,0BAA0B,CAAC,CAAC;IACnF,CAAC;IACD,MAAM,MAAM,GAAG,GAA8B,CAAC;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,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,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,8CAA8C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO;QACJ,OAAO,EAAE,OAAQ;QACjB,gBAAgB,EAAE,gBAAiB;QACnC,OAAO,EAAE,OAAQ;QACjB,eAAe,EAAE,IAAI,CAAC,iBAAiB,CAAC;QACxC,aAAa,EAAE,IAAI,CAAC,eAAe,CAAC;QACpC,mBAAmB,EAAE,IAAI,CAAC,qBAAqB,CAAC;QAChD,eAAe,EAAE,IAAI,CAAC,iBAAiB,CAAC;QACxC,aAAa,EAAE,IAAI,CAAC,eAAe,CAAC;QACpC,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC;KACpC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"generate-transfer-model-config.js","sourceRoot":"","sources":["../../src/commands/generate-transfer-model-config.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,+FAA+F;AAC/F,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,eAAe,CAAU,CAAC;AAEhI,0FAA0F;AAC1F,SAAS,cAAc,CAAC,OAAe,EAAE,KAAa;IACnD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAkB;IACvD,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACF,GAAG,GAAG,IAAI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for the generated transfer model. */
25
25
  outFile: string;
26
+ /**
27
+ * Destination for a generated AST-node builder module. Omitted by consumers
28
+ * that construct no AST nodes; the transfer model is emitted either way.
29
+ *
30
+ * Emitted from this command rather than its own because the AST source is
31
+ * already parsed here, and because a consumer that regenerates one artefact
32
+ * and not the other has the two disagreeing about the same grammar.
33
+ */
34
+ astBuilderFile?: string;
35
+ /**
36
+ * Destination for a generated test module binding `makeTransferNodeBuilder`
37
+ * from `@hydranium/protocol/testing` to the transfer model, as `transferNode`,
38
+ * the way {@link astBuilderFile} binds `astNode`. Belongs in a test tree:
39
+ * production code has no use for a builder that fills grammar defaults.
40
+ *
41
+ * When it sits in another package than {@link outFile}, it imports the model
42
+ * by that package's name, so the package's main entry must re-export the
43
+ * generated model, and with it each type's constant: an interface the entry
44
+ * narrows hides the generated constant of the same name unless the entry
45
+ * re-exports that constant too, and the builder keeps the generated
46
+ * interface unless the entry declares `<LanguageId>TransferTypes` with the
47
+ * narrowed entry.
48
+ */
49
+ transferBuilderFile?: string;
50
+ /**
51
+ * Destination for a generated module stating each grammar's language id and
52
+ * file extensions, read from the `module.ts` beside {@link astFile}. Lets a
53
+ * package without Langium, such as one shared with clients, name the ids
54
+ * without copying them by hand.
55
+ */
56
+ languagesFile?: string;
26
57
  /** Name used for the base element type in the output. Defaults to `TransferElement`. */
27
58
  elementTypeName?: string;
28
59
  /** Name used for the terminal-patterns const in the output. Defaults to `ModelTerminals`. */
@@ -54,10 +85,17 @@ export interface GenerateTransferModelOptions {
54
85
  regenCommand?: string;
55
86
  }
56
87
  /**
57
- * Generate once, then re-generate whenever the AST or augmentation file changes,
88
+ * Generate once, then re-generate whenever an input file changes (the AST, the
89
+ * augmentation file, and `module.ts` when a languages file is written),
58
90
  * until `signal` aborts (the CLI wires this to SIGINT). Regeneration is debounced
59
91
  * so an editor's multi-event save fires a single run, and a generation error is
60
92
  * logged without tearing down the watch. Resolves when the signal aborts.
93
+ *
94
+ * Polled by path rather than watched through OS events: langium-cli removes
95
+ * its output directory and writes the files back, which an event watch, Node's
96
+ * and chokidar's alike, stops hearing after the first run. A run that finds an
97
+ * input missing is skipped, since the file's return is a change of its own, so
98
+ * nothing generates from a half-written output.
61
99
  */
62
100
  export declare function watchTransferModel(options: GenerateTransferModelOptions, context: {
63
101
  signal: AbortSignal;
@@ -85,10 +123,11 @@ export declare function parseTerminals(astSource: SourceFile, terminalsSourceNam
85
123
  }>;
86
124
  /**
87
125
  * Type-guard expression (against an `item: unknown`) for one member of a non-literal type-alias
88
- * union. Covers the full set of Langium data-type primitives: the `typeof`-checkable ones
89
- * (`string`/`number`/`boolean`/`bigint`) use `typeof`; `Date` — the one Langium primitive `typeof`
90
- * reports as `'object'` — uses `instanceof`; any other member is a named type whose generated
91
- * `is<Member>` guard is called.
126
+ * union. A string literal is compared as written, so the escapes Langium wrote stay valid.
127
+ * Covers the full set of Langium data-type primitives. The `typeof`-checkable ones
128
+ * (`string`/`number`/`boolean`/`bigint`) use `typeof`, and `Date`, the one Langium primitive
129
+ * `typeof` reports as `'object'`, uses `instanceof`. Any other member is a named type whose
130
+ * generated `is<Member>` guard is called.
92
131
  */
93
132
  export declare function typeAliasMemberGuard(member: string): string;
94
133
  /**
@@ -101,10 +140,11 @@ export declare function typeAliasMemberGuard(member: string): string;
101
140
  * name.
102
141
  *
103
142
  * Each referenced member is inlined and de-duplicated, preserving first-seen
104
- * order. The definition is returned UNCHANGED when it holds no
105
- * namespace-qualified reference (the single-language case) or when any referenced
106
- * member is not a pure string-literal union — passing it through rather than
107
- * emitting a half-resolved union.
143
+ * order; when no member holds a literal, the union is `never`. The definition
144
+ * is returned UNCHANGED when it holds no namespace-qualified reference (the
145
+ * single-language case) or when any referenced member is not a pure
146
+ * string-literal union — passing it through rather than emitting a
147
+ * half-resolved union.
108
148
  */
109
149
  export declare function resolveNamespacedStringUnion(astSource: SourceFile, definition: string): string;
110
150
  //# sourceMappingURL=generate-transfer-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate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AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAqB9F"}
1
+ {"version":3,"file":"generate-transfer-model.d.ts","sourceRoot":"","sources":["../../src/commands/generate-transfer-model.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAOlF,OAAO,EAQJ,KAAK,UAAU,EACjB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;GAQG;AACH,MAAM,WAAW,4BAA4B;IAC1C,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,gBAAgB,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;;;OAaG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;;OAQG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACxB;AAoCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,4BAA4B,EAAE,OAAO,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzH;AAOD,wCAAwC;AACxC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI,CAsSjF;AA2LD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC3B,SAAS,EAAE,UAAU,EACrB,mBAAmB,EAAE,MAAM,EAC3B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CA8B1C;AAsFD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAe3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAqB9F"}
@@ -8,7 +8,11 @@
8
8
  ********************************************************************************/
9
9
  import * as fs from 'fs';
10
10
  import * as path from 'path';
11
- import { Project, SyntaxKind } from 'ts-morph';
11
+ import { emitAstBuilder } from './generate-ast-builder.js';
12
+ import { emitLanguages } from './generate-languages.js';
13
+ import { emitTransferBuilder } from './generate-transfer-builder.js';
14
+ import { Project, SyntaxKind, ts } from 'ts-morph';
15
+ import { describeError } from '@hydranium/protocol';
12
16
  const DEFAULT_ELEMENT_TYPE_NAME = 'TransferElement';
13
17
  const DEFAULT_TERMINALS_NAME = 'ModelTerminals';
14
18
  const DEFAULT_REGEN_COMMAND = 'Run the hydranium-cli generate-transfer-model command to regenerate.';
@@ -18,11 +22,20 @@ const DEFAULT_REGEN_COMMAND = 'Run the hydranium-cli generate-transfer-model com
18
22
  * `<LanguageId>Terminals` const then spreads these.
19
23
  */
20
24
  const NAMESPACED_TERMINALS_NAME = 'Terminals';
25
+ /** How often `--watch` polls its input files. */
26
+ const WATCH_POLL_INTERVAL_MS = 250;
21
27
  /**
22
- * Generate once, then re-generate whenever the AST or augmentation file changes,
28
+ * Generate once, then re-generate whenever an input file changes (the AST, the
29
+ * augmentation file, and `module.ts` when a languages file is written),
23
30
  * until `signal` aborts (the CLI wires this to SIGINT). Regeneration is debounced
24
31
  * so an editor's multi-event save fires a single run, and a generation error is
25
32
  * logged without tearing down the watch. Resolves when the signal aborts.
33
+ *
34
+ * Polled by path rather than watched through OS events: langium-cli removes
35
+ * its output directory and writes the files back, which an event watch, Node's
36
+ * and chokidar's alike, stops hearing after the first run. A run that finds an
37
+ * input missing is skipped, since the file's return is a change of its own, so
38
+ * nothing generates from a half-written output.
26
39
  */
27
40
  export function watchTransferModel(options, context) {
28
41
  const runSafely = () => {
@@ -30,23 +43,42 @@ export function watchTransferModel(options, context) {
30
43
  generateTransferModel(options);
31
44
  }
32
45
  catch (error) {
33
- console.error(`Transfer-model generation failed: ${error instanceof Error ? error.message : String(error)}`);
46
+ console.error(`Transfer-model generation failed: ${describeError(error)}`);
34
47
  }
35
48
  };
36
49
  runSafely();
37
- console.log(`Watching ${options.astFile} and ${options.augmentationFile} for changes. Press Ctrl-C to stop.`);
50
+ // A grammar's language id and extensions reach only `module.ts`, so the
51
+ // languages module would go stale without it.
52
+ const watched = [
53
+ options.astFile,
54
+ options.augmentationFile,
55
+ ...(options.languagesFile !== undefined ? [languagesModuleFile(options)] : [])
56
+ ];
38
57
  let timer;
39
- const scheduleRerun = () => {
58
+ const rerun = () => {
59
+ if (watched.every(file => fs.existsSync(file))) {
60
+ runSafely();
61
+ }
62
+ };
63
+ // The poll reports every stat it takes; a replaced file has a new inode, a
64
+ // rewritten one a new mtime, a removed or returning one zeroed stats.
65
+ const onPoll = (current, previous) => {
66
+ if (current.ino === previous.ino && current.mtimeMs === previous.mtimeMs && current.size === previous.size) {
67
+ return;
68
+ }
40
69
  if (timer) {
41
70
  clearTimeout(timer);
42
71
  }
43
- timer = setTimeout(runSafely, 150);
72
+ timer = setTimeout(rerun, 150);
44
73
  };
45
- const watchers = [options.astFile, options.augmentationFile].map(file => fs.watch(file, scheduleRerun));
74
+ for (const file of watched) {
75
+ fs.watchFile(file, { interval: WATCH_POLL_INTERVAL_MS }, onPoll);
76
+ }
77
+ console.log(`Watching ${watched.join(', ')} for changes. Press Ctrl-C to stop.`);
46
78
  return new Promise(resolve => {
47
79
  context.signal.addEventListener('abort', () => {
48
- for (const watcher of watchers) {
49
- watcher.close();
80
+ for (const file of watched) {
81
+ fs.unwatchFile(file, onPoll);
50
82
  }
51
83
  if (timer) {
52
84
  clearTimeout(timer);
@@ -55,6 +87,10 @@ export function watchTransferModel(options, context) {
55
87
  }, { once: true });
56
88
  });
57
89
  }
90
+ /** The langium-cli `module.ts` beside the AST file, which the languages module is read from. */
91
+ function languagesModuleFile(options) {
92
+ return path.join(path.dirname(options.astFile), 'module.ts');
93
+ }
58
94
  /** Run the transfer-model generator. */
59
95
  export function generateTransferModel(options) {
60
96
  const elementTypeName = options.elementTypeName ?? DEFAULT_ELEMENT_TYPE_NAME;
@@ -92,9 +128,13 @@ export function generateTransferModel(options) {
92
128
  if (skipTypeAliases.has(name)) {
93
129
  continue;
94
130
  }
95
- const typeText = alias.getTypeNode()?.getText();
96
- if (typeText) {
97
- typeAliases.push({ name, definition: mapType(resolveNamespacedStringUnion(astSource, typeText), elementTypeName) });
131
+ const typeNode = alias.getTypeNode();
132
+ if (typeNode) {
133
+ typeAliases.push({
134
+ name,
135
+ definition: mapType(resolveNamespacedStringUnion(astSource, typeNode.getText()), elementTypeName),
136
+ members: unionMembers(typeNode).map(member => mapType(member, elementTypeName))
137
+ });
98
138
  }
99
139
  }
100
140
  // 5. Parse augmentations from the consumer's `declare module` blocks.
@@ -108,7 +148,6 @@ export function generateTransferModel(options) {
108
148
  // 7. Classify interfaces: abstract (union $type) vs concrete (literal $type).
109
149
  const interfaceNames = [];
110
150
  const abstractTypes = new Set();
111
- const concreteTypes = new Set();
112
151
  for (const name of Object.keys(reflectionTypes)) {
113
152
  const iface = astInterfaces.get(name);
114
153
  if (!iface) {
@@ -120,9 +159,6 @@ export function generateTransferModel(options) {
120
159
  if (typeText.includes('|')) {
121
160
  abstractTypes.add(name);
122
161
  }
123
- else {
124
- concreteTypes.add(name);
125
- }
126
162
  }
127
163
  // 8. Resolve extends-chains. Filter out type-alias supertypes (Langium reflection
128
164
  // includes them for the grammar hierarchy but TypeScript can't extend a union
@@ -157,12 +193,13 @@ export function generateTransferModel(options) {
157
193
  out.push(' readonly $type: string;');
158
194
  out.push('}');
159
195
  out.push('');
160
- // Type constants for concrete types.
196
+ // Langium's per-type constant under the same name, for every reflection type
197
+ // the model emits, abstract ones and unions included.
198
+ const reflectedTypes = Object.keys(reflectionTypes).filter(name => astInterfaces.has(name) || typeAliasNames.has(name));
161
199
  out.push('// --- Type Constants ---');
162
- for (const name of sorted) {
163
- if (concreteTypes.has(name)) {
164
- out.push(`export const ${name}Type = '${name}';`);
165
- }
200
+ for (const name of reflectedTypes) {
201
+ const keys = reflectionTypes[name].properties.map(property => `${property.name}: '${property.name}'`);
202
+ out.push(`export const ${name} = { ${[`$type: '${name}'`, ...keys].join(', ')} } as const;`);
166
203
  }
167
204
  out.push('');
168
205
  // Type aliases.
@@ -172,7 +209,7 @@ export function generateTransferModel(options) {
172
209
  out.push(`export type ${name} = ${definition};`);
173
210
  const literals = extractStringLiterals(definition);
174
211
  if (literals) {
175
- const items = literals.map(l => `'${l}'`).join(', ');
212
+ const items = literals.map(quote).join(', ');
176
213
  out.push(`export const ${name}Values = [${items}] as const;`);
177
214
  }
178
215
  }
@@ -200,7 +237,7 @@ export function generateTransferModel(options) {
200
237
  out.push(` readonly $type: ${typeValue};`);
201
238
  }
202
239
  else {
203
- out.push(` readonly $type: typeof ${name}Type;`);
240
+ out.push(` readonly $type: '${name}';`);
204
241
  }
205
242
  const emitted = new Set(['$type']);
206
243
  for (const prop of iface.getProperties()) {
@@ -256,24 +293,24 @@ export function generateTransferModel(options) {
256
293
  out.push(` return is${elementTypeName}(item) && (${checks});`);
257
294
  }
258
295
  else {
259
- out.push(` return is${elementTypeName}(item) && item.$type === ${name}Type;`);
296
+ out.push(` return is${elementTypeName}(item) && item.$type === '${name}';`);
260
297
  }
261
298
  out.push('}');
262
299
  out.push('');
263
300
  }
264
- for (const { name, definition } of typeAliases) {
301
+ for (const { name, definition, members } of typeAliases) {
265
302
  const literals = extractStringLiterals(definition);
266
303
  if (literals) {
267
- const checks = literals.map(l => `item === '${l}'`).join(' || ');
304
+ const checks = literals.map(l => `item === ${quote(l)}`).join(' || ') || 'false';
268
305
  out.push(`export function is${name}(item: unknown): item is ${name} {`);
269
306
  out.push(` return ${checks};`);
270
307
  out.push('}');
271
308
  out.push('');
272
309
  }
273
310
  else {
274
- // Union (or single) of named members and/or Langium data-type primitives. Each member maps
275
- // to its own check (typeof / instanceof / named-guard) via typeAliasMemberGuard.
276
- const members = definition.split('|').map(s => s.trim());
311
+ // Union (or single) of named members, Langium data-type primitives and the string
312
+ // literals a data-type rule's keywords add beside them. Each member maps to its own
313
+ // check via typeAliasMemberGuard.
277
314
  const checks = members.map(typeAliasMemberGuard).join(' || ');
278
315
  out.push(`export function is${name}(item: unknown): item is ${name} {`);
279
316
  out.push(` return ${checks};`);
@@ -281,6 +318,8 @@ export function generateTransferModel(options) {
281
318
  out.push('');
282
319
  }
283
320
  }
321
+ out.push(...renderTypeMap(languageId, reflectedTypes));
322
+ out.push(...renderReflection(languageId, elementTypeName, reflectedTypes, reflectionTypes));
284
323
  // Coverage check: warn on reflection types not emitted.
285
324
  const processedSet = new Set(sorted);
286
325
  for (const name of Object.keys(reflectionTypes)) {
@@ -293,10 +332,89 @@ export function generateTransferModel(options) {
293
332
  fs.mkdirSync(path.dirname(options.outFile), { recursive: true });
294
333
  if (fs.existsSync(options.outFile) && fs.readFileSync(options.outFile, 'utf-8') === content) {
295
334
  console.log('Transfer model is up to date.');
296
- return;
297
335
  }
298
- fs.writeFileSync(options.outFile, content, 'utf-8');
299
- console.log(`Generated: ${options.outFile}`);
336
+ else {
337
+ fs.writeFileSync(options.outFile, content, 'utf-8');
338
+ console.log(`Generated: ${options.outFile}`);
339
+ }
340
+ if (options.astBuilderFile !== undefined) {
341
+ const emitted = emitAstBuilder(astSource, {
342
+ outFile: options.astBuilderFile,
343
+ astFile: options.astFile,
344
+ languageId,
345
+ regenCommand
346
+ });
347
+ if (!emitted) {
348
+ console.warn(`Warning: no '${languageId}AstType' alias in ${options.astFile}; skipping the AST builder.`);
349
+ }
350
+ }
351
+ if (options.transferBuilderFile !== undefined) {
352
+ emitTransferBuilder({ outFile: options.transferBuilderFile, transferModelFile: options.outFile, languageId, regenCommand });
353
+ }
354
+ if (options.languagesFile !== undefined) {
355
+ const moduleSource = project.addSourceFileAtPath(languagesModuleFile(options));
356
+ emitLanguages(moduleSource, { outFile: options.languagesFile, regenCommand });
357
+ }
358
+ }
359
+ /**
360
+ * `<LanguageId>TransferTypes`, each `$type` to its interface, so an encoder or a
361
+ * builder can type a node by the grammar the way Langium's `<LanguageId>AstType`
362
+ * does on the AST side.
363
+ */
364
+ function renderTypeMap(languageId, types) {
365
+ return ['// --- Type Map ---', `export type ${languageId}TransferTypes = {`, ...types.map(name => ` ${name}: ${name};`), '};', ''];
366
+ }
367
+ /**
368
+ * `<LanguageId>TransferReflection`, the grammar metadata with the method names
369
+ * Langium's `AstReflection` uses. A plain object with no framework import, so
370
+ * the file stays self-contained, and nothing references it but its importers:
371
+ * the `is` guards test `$type` directly, so a guard never pulls it in. `types`
372
+ * keeps its literal type, which is how the transfer-node builder tells which
373
+ * fields the grammar defaults.
374
+ */
375
+ function renderReflection(languageId, elementTypeName, types, reflectionTypes) {
376
+ const metaData = `${languageId}TransferTypeMetaData`;
377
+ // Index signatures, not `Readonly<Record<…>>`: a grammar type may be named
378
+ // `Record` or `Readonly`, which Langium does not reserve as it does `Object`.
379
+ const out = [
380
+ '// --- Reflection ---',
381
+ `export interface ${metaData} {`,
382
+ ' readonly name: string;',
383
+ ' readonly properties: {',
384
+ ' readonly [name: string]: { readonly name: string; readonly defaultValue?: unknown; readonly optional?: boolean; readonly referenceType?: string };',
385
+ ' };',
386
+ ' readonly superTypes: readonly string[];',
387
+ '}',
388
+ '',
389
+ `export const ${languageId}TransferReflection = {`,
390
+ ' types: {'
391
+ ];
392
+ for (const name of types) {
393
+ const { properties, superTypes } = reflectionTypes[name];
394
+ const propertyEntries = properties.map(property => {
395
+ const fields = [`name: '${property.name}'`];
396
+ if (property.defaultValue !== undefined) {
397
+ fields.push(`defaultValue: ${property.defaultValue}`);
398
+ }
399
+ if (property.optional) {
400
+ fields.push('optional: true');
401
+ }
402
+ if (property.referenceType !== undefined) {
403
+ fields.push(`referenceType: '${property.referenceType}'`);
404
+ }
405
+ return `${property.name}: { ${fields.join(', ')} }`;
406
+ });
407
+ const supers = superTypes.map(superType => `'${superType}'`).join(', ');
408
+ const propertiesText = propertyEntries.length > 0 ? `{ ${propertyEntries.join(', ')} }` : '{}';
409
+ out.push(` ${name}: { name: '${name}', properties: ${propertiesText}, superTypes: [${supers}] },`);
410
+ }
411
+ out.push(` } as const satisfies { readonly [type: string]: ${metaData} },`, '', ' getAllTypes(): string[] {', ' return Object.keys(this.types);', ' },', '',
412
+ // An own-property check, not `types[type] ?? …`: a name the object
413
+ // prototype carries, `toString` say, would read the inherited member and
414
+ // make `isSubtype` throw. `hasOwnProperty.call` rather than `Object.hasOwn`
415
+ // because the adopter's protocol package may target a lib without it.
416
+ ` getTypeMetaData(type: string): ${metaData} {`, ' return Object.prototype.hasOwnProperty.call(this.types, type)', ` ? (this.types as { readonly [type: string]: ${metaData} })[type]`, ' : { name: type, properties: {}, superTypes: [] };', ' },', '', ' isSubtype(subtype: string, supertype: string): boolean {', ' return subtype === supertype || this.getTypeMetaData(subtype).superTypes.some(type => this.isSubtype(type, supertype));', ' },', '', ' getAllSubTypes(type: string): string[] {', ' return this.getAllTypes().filter(candidate => this.isSubtype(candidate, type));', ' },', '', ' isInstance(item: unknown, type: string): boolean {', ` return is${elementTypeName}(item) && this.isSubtype(item.$type, type);`, ' }', '};', '');
417
+ return out;
300
418
  }
301
419
  // ---------------------------------------------------------------------------
302
420
  // AST source parsing helpers
@@ -335,10 +453,11 @@ function findAstReflectionClass(source) {
335
453
  throw new Error('Could not find a class extending AbstractAstReflection in the AST source.');
336
454
  }
337
455
  /**
338
- * Extract `superTypes` for each entry of the reflection class's `types` property
339
- * initializer. We rely on the Langium convention that `X.$type === 'X'`, so a
340
- * supertype expression resolves to the literal type-name string by stripping
341
- * `.$type`.
456
+ * Extract `superTypes` and the grammar properties for each entry of the
457
+ * reflection class's `types` property initializer. We rely on the Langium
458
+ * convention that `X.$type === 'X'` and `X.p === 'p'`, so a type expression
459
+ * resolves to the literal type-name string by stripping `.$type`, and a
460
+ * property's name is its key.
342
461
  */
343
462
  function parseReflectionTypes(reflectionClass) {
344
463
  const result = {};
@@ -359,29 +478,31 @@ function parseReflectionTypes(reflectionClass) {
359
478
  const value = entry.getLastChildByKind(SyntaxKind.ObjectLiteralExpression);
360
479
  const supersProp = value?.getProperty('superTypes');
361
480
  const supersInit = supersProp?.getFirstChildByKind(SyntaxKind.ArrayLiteralExpression);
362
- const superTypes = [];
363
- if (supersInit) {
364
- for (const element of supersInit.getElements()) {
365
- const text = element.getText();
366
- const dotMatch = /^([A-Za-z_$][\w$]*)\.\$type$/.exec(text);
367
- if (dotMatch) {
368
- superTypes.push(dotMatch[1]);
369
- continue;
370
- }
371
- // Bare identifier or quoted string fall-back.
372
- const stringMatch = /^['"](.+)['"]$/.exec(text);
373
- if (stringMatch) {
374
- superTypes.push(stringMatch[1]);
375
- }
376
- else {
377
- superTypes.push(text);
378
- }
379
- }
380
- }
381
- result[name] = { superTypes };
481
+ const superTypes = supersInit?.getElements().map(element => typeNameOf(element.getText())) ?? [];
482
+ result[name] = { superTypes, properties: parseReflectionProperties(value) };
382
483
  }
383
484
  return result;
384
485
  }
486
+ function parseReflectionProperties(entry) {
487
+ const propertiesInit = entry?.getProperty('properties')?.getFirstChildByKind(SyntaxKind.ObjectLiteralExpression);
488
+ const properties = [];
489
+ for (const property of propertiesInit?.getChildrenOfKind(SyntaxKind.PropertyAssignment) ?? []) {
490
+ const meta = property.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
491
+ const field = (key) => meta?.getProperty(key)?.asKind(SyntaxKind.PropertyAssignment)?.getInitializer()?.getText();
492
+ const referenceType = field('referenceType');
493
+ properties.push({
494
+ name: property.getName(),
495
+ defaultValue: field('defaultValue'),
496
+ optional: field('optional') === 'true',
497
+ referenceType: referenceType === undefined ? undefined : typeNameOf(referenceType)
498
+ });
499
+ }
500
+ return properties;
501
+ }
502
+ /** `X.$type` or a quoted `'X'` to `X`; any other text passes through. */
503
+ function typeNameOf(text) {
504
+ return /^([A-Za-z_$][\w$]*)\.\$type$/.exec(text)?.[1] ?? /^['"](.+)['"]$/.exec(text)?.[1] ?? text;
505
+ }
385
506
  /**
386
507
  * Collect terminal regex literals from the AST file.
387
508
  *
@@ -500,12 +621,16 @@ function mapType(text, elementTypeName) {
500
621
  }
501
622
  /**
502
623
  * Type-guard expression (against an `item: unknown`) for one member of a non-literal type-alias
503
- * union. Covers the full set of Langium data-type primitives: the `typeof`-checkable ones
504
- * (`string`/`number`/`boolean`/`bigint`) use `typeof`; `Date` — the one Langium primitive `typeof`
505
- * reports as `'object'` — uses `instanceof`; any other member is a named type whose generated
506
- * `is<Member>` guard is called.
624
+ * union. A string literal is compared as written, so the escapes Langium wrote stay valid.
625
+ * Covers the full set of Langium data-type primitives. The `typeof`-checkable ones
626
+ * (`string`/`number`/`boolean`/`bigint`) use `typeof`, and `Date`, the one Langium primitive
627
+ * `typeof` reports as `'object'`, uses `instanceof`. Any other member is a named type whose
628
+ * generated `is<Member>` guard is called.
507
629
  */
508
630
  export function typeAliasMemberGuard(member) {
631
+ if (member.startsWith("'") || member.startsWith('"')) {
632
+ return `item === ${member}`;
633
+ }
509
634
  switch (member) {
510
635
  case 'string':
511
636
  case 'number':
@@ -528,10 +653,11 @@ export function typeAliasMemberGuard(member) {
528
653
  * name.
529
654
  *
530
655
  * Each referenced member is inlined and de-duplicated, preserving first-seen
531
- * order. The definition is returned UNCHANGED when it holds no
532
- * namespace-qualified reference (the single-language case) or when any referenced
533
- * member is not a pure string-literal union — passing it through rather than
534
- * emitting a half-resolved union.
656
+ * order; when no member holds a literal, the union is `never`. The definition
657
+ * is returned UNCHANGED when it holds no namespace-qualified reference (the
658
+ * single-language case) or when any referenced member is not a pure
659
+ * string-literal union — passing it through rather than emitting a
660
+ * half-resolved union.
535
661
  */
536
662
  export function resolveNamespacedStringUnion(astSource, definition) {
537
663
  const references = [...definition.matchAll(/\b([A-Za-z_]\w*)\.([A-Za-z_]\w*)\b/g)];
@@ -553,15 +679,54 @@ export function resolveNamespacedStringUnion(astSource, definition) {
553
679
  }
554
680
  }
555
681
  }
556
- return literals.map(literal => `'${literal}'`).join(' | ');
682
+ return literals.length > 0 ? literals.map(quote).join(' | ') : 'never';
683
+ }
684
+ /**
685
+ * The members of a type-alias union as TypeScript parses them. If a data-type rule groups
686
+ * alternatives in parentheses, the alias Langium generates contains the same group, as in
687
+ * `'a' | ('b' | Keyword)`, so each group is flattened into its members. Splitting the text on
688
+ * `|` breaks such a group and any keyword that contains `|`, such as `'||'`, and the
689
+ * resulting guard does not compile.
690
+ */
691
+ function unionMembers(typeNode) {
692
+ if (typeNode.isKind(SyntaxKind.UnionType)) {
693
+ return typeNode.getTypeNodes().flatMap(member => unionMembers(member));
694
+ }
695
+ if (typeNode.isKind(SyntaxKind.ParenthesizedType)) {
696
+ return unionMembers(typeNode.getTypeNode());
697
+ }
698
+ return [typeNode.getText()];
557
699
  }
558
- /** Extract string literals from a union definition, or undefined if not pure literals. */
700
+ /**
701
+ * The values of a union of string literals, or undefined when the definition holds anything
702
+ * else. The TypeScript scanner decodes each literal, so a keyword with a quote in it reads the
703
+ * same whichever quotes and escapes Langium wrote it with. Langium writes the keyword names of
704
+ * a language without keywords as `never`, which adds no value.
705
+ */
559
706
  function extractStringLiterals(definition) {
560
- const stringLiteral = '(?:\'[^\']*\'|"[^"]*")';
561
- if (!new RegExp(`^\\|?\\s*${stringLiteral}(\\s*\\|\\s*${stringLiteral})*$`).test(definition.trim())) {
562
- return undefined;
707
+ const scanner = ts.createScanner(ts.ScriptTarget.Latest, true, ts.LanguageVariant.Standard, definition);
708
+ const literals = [];
709
+ let members = 0;
710
+ for (let token = scanner.scan(); token !== ts.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
711
+ if (token === ts.SyntaxKind.StringLiteral) {
712
+ literals.push(scanner.getTokenValue());
713
+ members++;
714
+ }
715
+ else if (token === ts.SyntaxKind.NeverKeyword) {
716
+ members++;
717
+ }
718
+ else if (token !== ts.SyntaxKind.BarToken) {
719
+ return undefined;
720
+ }
563
721
  }
564
- return [...definition.matchAll(/'([^']*)'|"([^"]*)"/g)].map(m => m[1] ?? m[2]);
722
+ return members > 0 ? literals : undefined;
723
+ }
724
+ /**
725
+ * `value` as a string literal in the single quotes the generated file uses. A keyword can
726
+ * contain a quote or a backslash, and either one ends or escapes the literal unless escaped.
727
+ */
728
+ function quote(value) {
729
+ return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
565
730
  }
566
731
  function topologicalSort(names, getDeps) {
567
732
  const visited = new Set();