@specverse/engines 4.1.30 → 4.2.1

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 (285) hide show
  1. package/assets/examples/manifests/frontend-only.yaml +3 -6
  2. package/assets/examples/manifests/fullstack-app.yaml +5 -7
  3. package/assets/examples/manifests/fullstack-monorepo.yaml +3 -6
  4. package/assets/templates/default/specs/main.specly +65 -0
  5. package/dist/inference/comprehensive-engine.d.ts.map +1 -1
  6. package/dist/inference/comprehensive-engine.js +3 -19
  7. package/dist/inference/comprehensive-engine.js.map +1 -1
  8. package/dist/inference/core/rule-engine.d.ts +31 -0
  9. package/dist/inference/core/rule-engine.d.ts.map +1 -1
  10. package/dist/inference/core/rule-engine.js +117 -33
  11. package/dist/inference/core/rule-engine.js.map +1 -1
  12. package/dist/inference/core/rule-file-types.d.ts +0 -2
  13. package/dist/inference/core/rule-file-types.d.ts.map +1 -1
  14. package/dist/inference/core/rule-file-types.js +3 -6
  15. package/dist/inference/core/rule-file-types.js.map +1 -1
  16. package/dist/inference/core/rule-loader.d.ts +5 -15
  17. package/dist/inference/core/rule-loader.d.ts.map +1 -1
  18. package/dist/inference/core/rule-loader.js +43 -132
  19. package/dist/inference/core/rule-loader.js.map +1 -1
  20. package/dist/inference/core/types.d.ts +0 -6
  21. package/dist/inference/core/types.d.ts.map +1 -1
  22. package/dist/inference/core/types.js +0 -4
  23. package/dist/inference/core/types.js.map +1 -1
  24. package/dist/inference/logical/generators/component-type-resolver.d.ts +0 -26
  25. package/dist/inference/logical/generators/component-type-resolver.d.ts.map +1 -1
  26. package/dist/inference/logical/generators/component-type-resolver.js +0 -19
  27. package/dist/inference/logical/generators/component-type-resolver.js.map +1 -1
  28. package/dist/inference/logical/generators/specialist-view-expander.d.ts +1 -17
  29. package/dist/inference/logical/generators/specialist-view-expander.d.ts.map +1 -1
  30. package/dist/inference/logical/generators/specialist-view-expander.js +0 -15
  31. package/dist/inference/logical/generators/specialist-view-expander.js.map +1 -1
  32. package/dist/inference/logical/generators/view-generator.d.ts +4 -14
  33. package/dist/inference/logical/generators/view-generator.d.ts.map +1 -1
  34. package/dist/inference/logical/generators/view-generator.js +6 -26
  35. package/dist/inference/logical/generators/view-generator.js.map +1 -1
  36. package/dist/inference/logical/index.d.ts +2 -2
  37. package/dist/inference/logical/index.d.ts.map +1 -1
  38. package/dist/inference/logical/logical-engine.d.ts.map +1 -1
  39. package/dist/inference/logical/logical-engine.js +17 -80
  40. package/dist/inference/logical/logical-engine.js.map +1 -1
  41. package/dist/inference/quint-transpiler.d.ts +5 -3
  42. package/dist/inference/quint-transpiler.d.ts.map +1 -1
  43. package/dist/inference/quint-transpiler.js +11 -6
  44. package/dist/inference/quint-transpiler.js.map +1 -1
  45. package/dist/libs/instance-factories/CURVED-INTERFACE.md +278 -0
  46. package/dist/libs/instance-factories/README.md +73 -0
  47. package/dist/libs/instance-factories/applications/README.md +51 -0
  48. package/dist/libs/instance-factories/applications/generic-app.yaml +52 -0
  49. package/{libs/instance-factories/applications/react-app.yaml → dist/libs/instance-factories/applications/react-app-runtime.yaml} +30 -77
  50. package/dist/libs/instance-factories/applications/react-app-starter.yaml +143 -0
  51. package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +24 -2
  52. package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +54 -33
  53. package/dist/libs/instance-factories/applications/templates/react-starter/README.md +211 -0
  54. package/dist/libs/instance-factories/applications/templates/react-starter/api-types-starter-generator.js +69 -0
  55. package/dist/libs/instance-factories/applications/templates/react-starter/app-tsx-generator.js +110 -0
  56. package/dist/libs/instance-factories/applications/templates/react-starter/belongs-to.js +40 -0
  57. package/dist/libs/instance-factories/applications/templates/react-starter/dashboard-body-composer.js +129 -0
  58. package/dist/libs/instance-factories/applications/templates/react-starter/detail-body-composer.js +80 -0
  59. package/dist/libs/instance-factories/applications/templates/react-starter/form-body-composer.js +217 -0
  60. package/dist/libs/instance-factories/applications/templates/react-starter/helpers-emitter.js +51 -0
  61. package/dist/libs/instance-factories/applications/templates/react-starter/html-to-jsx.js +192 -0
  62. package/dist/libs/instance-factories/applications/templates/react-starter/list-body-composer.js +56 -0
  63. package/dist/libs/instance-factories/applications/templates/react-starter/orchestrator.js +41 -0
  64. package/dist/libs/instance-factories/applications/templates/react-starter/package-json-generator.js +38 -0
  65. package/dist/libs/instance-factories/applications/templates/react-starter/regen-safety.js +89 -0
  66. package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/dashboard.tsx.template +49 -0
  67. package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/detail.tsx.template +96 -0
  68. package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/form.tsx.template +116 -0
  69. package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/list.tsx.template +74 -0
  70. package/dist/libs/instance-factories/applications/templates/react-starter/use-api-hooks-starter-generator.js +95 -0
  71. package/dist/libs/instance-factories/applications/templates/react-starter/view-emitter.js +81 -0
  72. package/dist/libs/instance-factories/applications/templates/react-starter/views-generator.js +66 -0
  73. package/dist/libs/instance-factories/archived/fastify-prisma.yaml +104 -0
  74. package/dist/libs/instance-factories/cli/README.md +43 -0
  75. package/dist/libs/instance-factories/cli/commander-js.yaml +55 -0
  76. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +63 -12
  77. package/dist/libs/instance-factories/communication/README.md +47 -0
  78. package/dist/libs/instance-factories/communication/event-emitter.yaml +60 -0
  79. package/dist/libs/instance-factories/communication/rabbitmq-events.yaml +87 -0
  80. package/dist/libs/instance-factories/controllers/README.md +42 -0
  81. package/dist/libs/instance-factories/controllers/fastify.yaml +139 -0
  82. package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +29 -2
  83. package/dist/libs/instance-factories/infrastructure/README.md +29 -0
  84. package/dist/libs/instance-factories/infrastructure/docker-k8s.yaml +61 -0
  85. package/dist/libs/instance-factories/orms/README.md +54 -0
  86. package/dist/libs/instance-factories/orms/prisma.yaml +89 -0
  87. package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +2 -2
  88. package/dist/libs/instance-factories/scaffolding/README.md +49 -0
  89. package/dist/libs/instance-factories/scaffolding/generic-scaffold.yaml +65 -0
  90. package/dist/libs/instance-factories/sdks/README.md +28 -0
  91. package/dist/libs/instance-factories/sdks/python-sdk.yaml +66 -0
  92. package/dist/libs/instance-factories/sdks/typescript-sdk.yaml +59 -0
  93. package/dist/libs/instance-factories/services/README.md +55 -0
  94. package/dist/libs/instance-factories/services/prisma-services.yaml +71 -0
  95. package/dist/libs/instance-factories/storage/README.md +34 -0
  96. package/dist/libs/instance-factories/storage/mongodb.yaml +79 -0
  97. package/dist/libs/instance-factories/storage/postgresql.yaml +75 -0
  98. package/dist/libs/instance-factories/storage/redis.yaml +79 -0
  99. package/dist/libs/instance-factories/testing/README.md +40 -0
  100. package/dist/libs/instance-factories/testing/vitest-tests.yaml +63 -0
  101. package/dist/libs/instance-factories/tools/README.md +70 -0
  102. package/dist/libs/instance-factories/tools/mcp.yaml +36 -0
  103. package/dist/libs/instance-factories/tools/vscode.yaml +35 -0
  104. package/dist/libs/instance-factories/validation/README.md +38 -0
  105. package/dist/libs/instance-factories/validation/zod.yaml +56 -0
  106. package/dist/realize/engines/code-generator.d.ts.map +1 -1
  107. package/dist/realize/engines/code-generator.js +3 -0
  108. package/dist/realize/engines/code-generator.js.map +1 -1
  109. package/dist/realize/index.d.ts.map +1 -1
  110. package/dist/realize/index.js +15 -22
  111. package/dist/realize/index.js.map +1 -1
  112. package/dist/registry/utils/manifest-adapter.d.ts +8 -1
  113. package/dist/registry/utils/manifest-adapter.d.ts.map +1 -1
  114. package/dist/registry/utils/manifest-adapter.js +8 -1
  115. package/dist/registry/utils/manifest-adapter.js.map +1 -1
  116. package/libs/instance-factories/applications/react-app-starter.yaml +143 -0
  117. package/libs/instance-factories/applications/templates/react/env-example-generator.ts +24 -2
  118. package/libs/instance-factories/applications/templates/react/vite-config-generator.ts +54 -33
  119. package/libs/instance-factories/applications/templates/react-starter/README.md +211 -0
  120. package/libs/instance-factories/applications/templates/react-starter/__tests__/dashboard-body-composer.test.ts +153 -0
  121. package/libs/instance-factories/applications/templates/react-starter/__tests__/detail-body-composer.test.ts +146 -0
  122. package/libs/instance-factories/applications/templates/react-starter/__tests__/form-body-composer.test.ts +188 -0
  123. package/libs/instance-factories/applications/templates/react-starter/__tests__/helpers-emitter.test.ts +55 -0
  124. package/libs/instance-factories/applications/templates/react-starter/__tests__/html-to-jsx.test.ts +140 -0
  125. package/libs/instance-factories/applications/templates/react-starter/__tests__/list-body-composer.test.ts +146 -0
  126. package/libs/instance-factories/applications/templates/react-starter/__tests__/orchestrator.test.ts +184 -0
  127. package/libs/instance-factories/applications/templates/react-starter/__tests__/parity-p2-factory-imports.test.ts +116 -0
  128. package/libs/instance-factories/applications/templates/react-starter/__tests__/parity-p3-rendered-output.test.ts +183 -0
  129. package/libs/instance-factories/applications/templates/react-starter/__tests__/regen-safety.test.ts +144 -0
  130. package/libs/instance-factories/applications/templates/react-starter/__tests__/starter-generators.test.ts +114 -0
  131. package/libs/instance-factories/applications/templates/react-starter/__tests__/view-emitter.test.ts +107 -0
  132. package/libs/instance-factories/applications/templates/react-starter/__tests__/views-generator.test.ts +139 -0
  133. package/libs/instance-factories/applications/templates/react-starter/api-types-starter-generator.ts +98 -0
  134. package/libs/instance-factories/applications/templates/react-starter/app-tsx-generator.ts +141 -0
  135. package/libs/instance-factories/applications/templates/react-starter/belongs-to.ts +82 -0
  136. package/libs/instance-factories/applications/templates/react-starter/dashboard-body-composer.ts +189 -0
  137. package/libs/instance-factories/applications/templates/react-starter/detail-body-composer.ts +135 -0
  138. package/libs/instance-factories/applications/templates/react-starter/form-body-composer.ts +383 -0
  139. package/libs/instance-factories/applications/templates/react-starter/helpers-emitter.ts +66 -0
  140. package/libs/instance-factories/applications/templates/react-starter/html-to-jsx.ts +334 -0
  141. package/libs/instance-factories/applications/templates/react-starter/list-body-composer.ts +146 -0
  142. package/libs/instance-factories/applications/templates/react-starter/orchestrator.ts +95 -0
  143. package/libs/instance-factories/applications/templates/react-starter/package-json-generator.ts +57 -0
  144. package/libs/instance-factories/applications/templates/react-starter/regen-safety.ts +157 -0
  145. package/libs/instance-factories/applications/templates/react-starter/skeletons/dashboard.tsx.template +49 -0
  146. package/libs/instance-factories/applications/templates/react-starter/skeletons/detail.tsx.template +96 -0
  147. package/libs/instance-factories/applications/templates/react-starter/skeletons/form.tsx.template +116 -0
  148. package/libs/instance-factories/applications/templates/react-starter/skeletons/list.tsx.template +74 -0
  149. package/libs/instance-factories/applications/templates/react-starter/use-api-hooks-starter-generator.ts +124 -0
  150. package/libs/instance-factories/applications/templates/react-starter/view-emitter.ts +209 -0
  151. package/libs/instance-factories/applications/templates/react-starter/views-generator.ts +137 -0
  152. package/libs/instance-factories/cli/templates/commander/command-generator.ts +63 -12
  153. package/libs/instance-factories/controllers/fastify.yaml +7 -0
  154. package/libs/instance-factories/controllers/templates/fastify/server-generator.ts +36 -2
  155. package/libs/instance-factories/orms/templates/prisma/schema-generator.ts +11 -4
  156. package/package.json +3 -3
  157. package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +0 -530
  158. package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +0 -73
  159. package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +0 -99
  160. package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +0 -49
  161. package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +0 -156
  162. package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +0 -935
  163. package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +0 -143
  164. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +0 -646
  165. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +0 -65
  166. package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +0 -143
  167. package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +0 -143
  168. package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +0 -355
  169. package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +0 -91
  170. package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +0 -79
  171. package/dist/libs/instance-factories/views/index.js +0 -48
  172. package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +0 -742
  173. package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +0 -824
  174. package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +0 -719
  175. package/dist/libs/instance-factories/views/templates/react/app-generator.js +0 -45
  176. package/dist/libs/instance-factories/views/templates/react/components-generator.js +0 -820
  177. package/dist/libs/instance-factories/views/templates/react/forms-generator.js +0 -275
  178. package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +0 -46
  179. package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +0 -81
  180. package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +0 -9
  181. package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +0 -23
  182. package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +0 -21
  183. package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +0 -299
  184. package/dist/libs/instance-factories/views/templates/react/router-generator.js +0 -136
  185. package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +0 -107
  186. package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +0 -187
  187. package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +0 -7
  188. package/dist/libs/instance-factories/views/templates/react/types-generator.js +0 -56
  189. package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +0 -27
  190. package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +0 -29
  191. package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +0 -261
  192. package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +0 -34
  193. package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +0 -800
  194. package/dist/libs/instance-factories/views/templates/shared/base-generator.js +0 -305
  195. package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +0 -517
  196. package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
  197. package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +0 -445
  198. package/dist/libs/instance-factories/views/templates/shared/index.js +0 -80
  199. package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +0 -210
  200. package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +0 -492
  201. package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +0 -321
  202. package/dist/realize/index.js.bak +0 -758
  203. package/libs/instance-factories/applications/templates/react/_view-components-source.ts +0 -555
  204. package/libs/instance-factories/applications/templates/react/app-tsx-generator.ts +0 -94
  205. package/libs/instance-factories/applications/templates/react/field-helpers-generator.ts +0 -106
  206. package/libs/instance-factories/applications/templates/react/package-json-generator.ts +0 -57
  207. package/libs/instance-factories/applications/templates/react/pattern-adapter-generator.ts +0 -179
  208. package/libs/instance-factories/applications/templates/react/react-pattern-adapter.tsx +0 -1347
  209. package/libs/instance-factories/applications/templates/react/relationship-field-generator.ts +0 -150
  210. package/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.ts +0 -704
  211. package/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.ts +0 -84
  212. package/libs/instance-factories/applications/templates/react/view-dashboard-generator.ts +0 -150
  213. package/libs/instance-factories/applications/templates/react/view-detail-generator.ts +0 -150
  214. package/libs/instance-factories/applications/templates/react/view-form-generator.ts +0 -362
  215. package/libs/instance-factories/applications/templates/react/view-list-generator.ts +0 -98
  216. package/libs/instance-factories/applications/templates/react/view-router-generator.ts +0 -89
  217. package/libs/instance-factories/views/README.md +0 -62
  218. package/libs/instance-factories/views/index.d.ts +0 -13
  219. package/libs/instance-factories/views/index.d.ts.map +0 -1
  220. package/libs/instance-factories/views/index.js +0 -18
  221. package/libs/instance-factories/views/index.js.map +0 -1
  222. package/libs/instance-factories/views/index.ts +0 -45
  223. package/libs/instance-factories/views/react-components.yaml +0 -129
  224. package/libs/instance-factories/views/templates/ARCHITECTURE.md +0 -198
  225. package/libs/instance-factories/views/templates/react/adapters/antd-adapter.ts +0 -869
  226. package/libs/instance-factories/views/templates/react/adapters/mui-adapter.ts +0 -953
  227. package/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.ts +0 -806
  228. package/libs/instance-factories/views/templates/react/app-generator.ts +0 -55
  229. package/libs/instance-factories/views/templates/react/components-generator.ts +0 -938
  230. package/libs/instance-factories/views/templates/react/forms-generator.ts +0 -325
  231. package/libs/instance-factories/views/templates/react/frontend-package-json-generator.ts +0 -57
  232. package/libs/instance-factories/views/templates/react/hooks-generator.ts +0 -106
  233. package/libs/instance-factories/views/templates/react/index-css-generator.ts +0 -14
  234. package/libs/instance-factories/views/templates/react/index-html-generator.ts +0 -34
  235. package/libs/instance-factories/views/templates/react/main-tsx-generator.ts +0 -29
  236. package/libs/instance-factories/views/templates/react/react-component-generator.d.ts +0 -152
  237. package/libs/instance-factories/views/templates/react/react-component-generator.d.ts.map +0 -1
  238. package/libs/instance-factories/views/templates/react/react-component-generator.js +0 -398
  239. package/libs/instance-factories/views/templates/react/react-component-generator.js.map +0 -1
  240. package/libs/instance-factories/views/templates/react/react-component-generator.ts +0 -533
  241. package/libs/instance-factories/views/templates/react/router-generator.ts +0 -197
  242. package/libs/instance-factories/views/templates/react/router-generic-generator.ts +0 -132
  243. package/libs/instance-factories/views/templates/react/shared-utils-generator.ts +0 -196
  244. package/libs/instance-factories/views/templates/react/spec-json-generator.ts +0 -17
  245. package/libs/instance-factories/views/templates/react/types-generator.ts +0 -76
  246. package/libs/instance-factories/views/templates/react/views-metadata-generator.ts +0 -42
  247. package/libs/instance-factories/views/templates/react/vite-config-generator.ts +0 -38
  248. package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.d.ts.map +0 -1
  249. package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js.map +0 -1
  250. package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.ts +0 -474
  251. package/libs/instance-factories/views/templates/shared/__tests__/composite-patterns.test.ts +0 -242
  252. package/libs/instance-factories/views/templates/shared/adapter-types.d.ts +0 -77
  253. package/libs/instance-factories/views/templates/shared/adapter-types.d.ts.map +0 -1
  254. package/libs/instance-factories/views/templates/shared/adapter-types.js +0 -47
  255. package/libs/instance-factories/views/templates/shared/adapter-types.js.map +0 -1
  256. package/libs/instance-factories/views/templates/shared/adapter-types.ts +0 -142
  257. package/libs/instance-factories/views/templates/shared/atomic-components-registry.d.ts +0 -63
  258. package/libs/instance-factories/views/templates/shared/atomic-components-registry.d.ts.map +0 -1
  259. package/libs/instance-factories/views/templates/shared/atomic-components-registry.js +0 -822
  260. package/libs/instance-factories/views/templates/shared/atomic-components-registry.js.map +0 -1
  261. package/libs/instance-factories/views/templates/shared/atomic-components-registry.ts +0 -908
  262. package/libs/instance-factories/views/templates/shared/base-generator.d.ts +0 -247
  263. package/libs/instance-factories/views/templates/shared/base-generator.d.ts.map +0 -1
  264. package/libs/instance-factories/views/templates/shared/base-generator.js +0 -363
  265. package/libs/instance-factories/views/templates/shared/base-generator.js.map +0 -1
  266. package/libs/instance-factories/views/templates/shared/base-generator.ts +0 -608
  267. package/libs/instance-factories/views/templates/shared/component-metadata.d.ts +0 -254
  268. package/libs/instance-factories/views/templates/shared/component-metadata.d.ts.map +0 -1
  269. package/libs/instance-factories/views/templates/shared/component-metadata.js +0 -602
  270. package/libs/instance-factories/views/templates/shared/component-metadata.js.map +0 -1
  271. package/libs/instance-factories/views/templates/shared/component-metadata.ts +0 -803
  272. package/libs/instance-factories/views/templates/shared/composite-pattern-types.ts +0 -250
  273. package/libs/instance-factories/views/templates/shared/composite-patterns.ts +0 -535
  274. package/libs/instance-factories/views/templates/shared/index.ts +0 -68
  275. package/libs/instance-factories/views/templates/shared/pattern-validator.ts +0 -279
  276. package/libs/instance-factories/views/templates/shared/property-mapper.d.ts +0 -149
  277. package/libs/instance-factories/views/templates/shared/property-mapper.d.ts.map +0 -1
  278. package/libs/instance-factories/views/templates/shared/property-mapper.js +0 -580
  279. package/libs/instance-factories/views/templates/shared/property-mapper.js.map +0 -1
  280. package/libs/instance-factories/views/templates/shared/property-mapper.ts +0 -700
  281. package/libs/instance-factories/views/templates/shared/syntax-mapper.d.ts +0 -143
  282. package/libs/instance-factories/views/templates/shared/syntax-mapper.d.ts.map +0 -1
  283. package/libs/instance-factories/views/templates/shared/syntax-mapper.js +0 -420
  284. package/libs/instance-factories/views/templates/shared/syntax-mapper.js.map +0 -1
  285. package/libs/instance-factories/views/templates/shared/syntax-mapper.ts +0 -539
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as ts from 'typescript';
3
+ import { composeDetailBody } from '../detail-body-composer.js';
4
+ import { emitView, type EmitContext, type ModelSpec } from '../view-emitter.js';
5
+
6
+ function makeContext(overrides: Partial<EmitContext> = {}): EmitContext {
7
+ const post: ModelSpec = {
8
+ name: 'Post',
9
+ attributes: {
10
+ id: { type: 'UUID', required: true },
11
+ title: { type: 'String', required: true },
12
+ body: { type: 'Text', required: false },
13
+ authorId: { type: 'UUID', required: true },
14
+ createdAt: { type: 'DateTime', required: false },
15
+ publishedAt: { type: 'DateTime', required: false },
16
+ },
17
+ relationships: {
18
+ author: { type: 'belongsTo', targetModel: 'Author' },
19
+ },
20
+ };
21
+
22
+ return {
23
+ view: { type: 'detail', model: 'Post' },
24
+ viewName: 'PostDetailView',
25
+ model: post,
26
+ modelSchemas: { Post: post },
27
+ renderBody: composeDetailBody,
28
+ ...overrides,
29
+ };
30
+ }
31
+
32
+ function assertValidTsx(source: string, label: string): void {
33
+ const result = ts.transpileModule(source, {
34
+ compilerOptions: {
35
+ jsx: ts.JsxEmit.Preserve,
36
+ target: ts.ScriptTarget.ES2022,
37
+ module: ts.ModuleKind.ESNext,
38
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
39
+ strict: false,
40
+ },
41
+ reportDiagnostics: true,
42
+ });
43
+ const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
44
+ if (errors.length > 0) {
45
+ const message = errors
46
+ .map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
47
+ .join('\n');
48
+ throw new Error(`${label} failed to parse as TSX:\n${message}\n\n--- source ---\n${source}`);
49
+ }
50
+ }
51
+
52
+ describe('composeDetailBody — direct output', () => {
53
+ it('groups fields into business / belongsTo / metadata sections', () => {
54
+ const body = composeDetailBody(makeContext());
55
+
56
+ // Business fields (first <dl>)
57
+ expect(body).toContain('>Title<');
58
+ expect(body).toContain('>Body<');
59
+
60
+ // belongsTo section — surfaces author as a resolved name via
61
+ // resolveEntityDisplayName against the authorOptions array wired
62
+ // in by view-emitter's RELATED_HOOKS substitution.
63
+ expect(body).toContain('>Author<');
64
+ expect(body).toContain('resolveEntityDisplayName((item as any).authorId, authorOptions)');
65
+
66
+ // Metadata section (id / createdAt / publishedAt) — muted styling
67
+ expect(body).toContain('>Id<');
68
+ expect(body).toContain('>Created At<');
69
+ expect(body).toContain('>Published At<');
70
+ expect(body).toContain('text-xs text-gray-500');
71
+
72
+ // Business section is separate from metadata (no mixing)
73
+ const businessIdx = body.indexOf('>Title<');
74
+ const metadataIdx = body.indexOf('>Id<');
75
+ expect(businessIdx).toBeLessThan(metadataIdx);
76
+ });
77
+
78
+ it('emits one <dt>/<dd> per field with (item as any).FIELD access', () => {
79
+ const body = composeDetailBody(makeContext());
80
+ expect(body).toContain('(item as any).title ??');
81
+ expect(body).toContain('(item as any).body ??');
82
+ expect(body).toContain('(item as any).id ??');
83
+ expect(body).toContain('(item as any).createdAt ??');
84
+ });
85
+
86
+ it('falls back to a "no business fields" message when all attrs are metadata', () => {
87
+ const mostlyMetadata: ModelSpec = {
88
+ name: 'Stub',
89
+ attributes: {
90
+ id: { type: 'UUID' },
91
+ createdAt: { type: 'DateTime' },
92
+ },
93
+ };
94
+ const body = composeDetailBody(makeContext({
95
+ model: mostlyMetadata,
96
+ view: { type: 'detail', model: 'Stub' },
97
+ viewName: 'StubDetailView',
98
+ modelSchemas: { Stub: mostlyMetadata },
99
+ }));
100
+ expect(body).toContain('No business fields defined');
101
+ });
102
+
103
+ it('skips the belongsTo section when no belongsTo relationships exist', () => {
104
+ const solo: ModelSpec = {
105
+ name: 'Solo',
106
+ attributes: { id: {}, name: {} },
107
+ relationships: {
108
+ tags: { type: 'hasMany', targetModel: 'Tag' }, // hasMany, not belongsTo
109
+ },
110
+ };
111
+ const body = composeDetailBody(makeContext({
112
+ model: solo,
113
+ view: { type: 'detail', model: 'Solo' },
114
+ viewName: 'SoloDetailView',
115
+ modelSchemas: { Solo: solo },
116
+ }));
117
+ expect(body).not.toContain('resolveEntityDisplayName');
118
+ expect(body).toContain('>Name<');
119
+ });
120
+ });
121
+
122
+ describe('emitView wired to composeDetailBody — end-to-end', () => {
123
+ it('produces a complete PostDetailView.tsx that parses', () => {
124
+ const source = emitView(makeContext());
125
+ assertValidTsx(source, 'PostDetailView');
126
+ });
127
+
128
+ it('wires the skeleton: component, hooks, actions, body', () => {
129
+ const source = emitView(makeContext());
130
+ expect(source).toContain('export function PostDetailView');
131
+ expect(source).toContain('usePostsQuery');
132
+ expect(source).toContain('useDeletePostMutation');
133
+ expect(source).toContain('Post detail');
134
+ expect(source).toContain('onEdit(item)');
135
+ expect(source).toContain("confirm('Delete this post?')");
136
+ expect(source).toContain('(item as any).title ??');
137
+ expect(source).not.toMatch(/\{\{[A-Z_]+\}\}/);
138
+ });
139
+
140
+ it('handles plural singular correctly for the loading / not-found copy', () => {
141
+ const source = emitView(makeContext());
142
+ expect(source).toContain('Loading…');
143
+ // SINGULAR_LOWER substitution: "No post matching id ..."
144
+ expect(source).toContain('No post matching id');
145
+ });
146
+ });
@@ -0,0 +1,188 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as ts from 'typescript';
3
+ import { composeFormBody } from '../form-body-composer.js';
4
+ import { emitView, type EmitContext, type ModelSpec } from '../view-emitter.js';
5
+
6
+ function makeContext(overrides: Partial<EmitContext> = {}): EmitContext {
7
+ const post: ModelSpec = {
8
+ name: 'Post',
9
+ attributes: {
10
+ id: { type: 'UUID', required: true, auto: 'uuid4' },
11
+ title: { type: 'String', required: true },
12
+ body: { type: 'Text', required: false },
13
+ published: { type: 'Boolean', required: false },
14
+ score: { type: 'Integer', required: false },
15
+ email: { type: 'Email', required: false },
16
+ status: { type: 'String', required: false, values: ['draft', 'live', 'archived'] },
17
+ authorId: { type: 'UUID', required: true }, // belongsTo FK
18
+ externalId: { type: 'UUID', required: false }, // non-FK UUID
19
+ createdAt: { type: 'DateTime', required: false }, // metadata
20
+ },
21
+ relationships: {
22
+ author: { type: 'belongsTo', targetModel: 'Author' },
23
+ },
24
+ };
25
+
26
+ return {
27
+ view: { type: 'form', model: 'Post' },
28
+ viewName: 'PostFormView',
29
+ model: post,
30
+ modelSchemas: { Post: post },
31
+ renderBody: composeFormBody,
32
+ ...overrides,
33
+ };
34
+ }
35
+
36
+ function assertValidTsx(source: string, label: string): void {
37
+ const result = ts.transpileModule(source, {
38
+ compilerOptions: {
39
+ jsx: ts.JsxEmit.Preserve,
40
+ target: ts.ScriptTarget.ES2022,
41
+ module: ts.ModuleKind.ESNext,
42
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
43
+ strict: false,
44
+ },
45
+ reportDiagnostics: true,
46
+ });
47
+ const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
48
+ if (errors.length > 0) {
49
+ const message = errors
50
+ .map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
51
+ .join('\n');
52
+ throw new Error(`${label} failed to parse as TSX:\n${message}\n\n--- source ---\n${source}`);
53
+ }
54
+ }
55
+
56
+ describe('composeFormBody — field selection', () => {
57
+ it('omits auto-generated fields (id, createdAt) and attrs with auto markers', () => {
58
+ const body = composeFormBody(makeContext());
59
+ expect(body).not.toMatch(/htmlFor="id"/);
60
+ expect(body).not.toMatch(/htmlFor="createdAt"/);
61
+ });
62
+
63
+ it('includes business fields in order', () => {
64
+ const body = composeFormBody(makeContext());
65
+ expect(body).toContain('htmlFor="title"');
66
+ expect(body).toContain('htmlFor="body"');
67
+ expect(body).toContain('htmlFor="score"');
68
+ });
69
+
70
+ it('renders a message when there are no editable fields', () => {
71
+ const emptyish: ModelSpec = {
72
+ name: 'Bare',
73
+ attributes: {
74
+ id: { type: 'UUID', auto: 'uuid4' },
75
+ createdAt: { type: 'DateTime' },
76
+ },
77
+ };
78
+ const body = composeFormBody(makeContext({
79
+ model: emptyish,
80
+ view: { type: 'form', model: 'Bare' },
81
+ viewName: 'BareFormView',
82
+ modelSchemas: { Bare: emptyish },
83
+ }));
84
+ expect(body).toContain('No editable fields for this model.');
85
+ });
86
+ });
87
+
88
+ describe('composeFormBody — input type per attribute', () => {
89
+ it('String with values=[...] → select', () => {
90
+ const body = composeFormBody(makeContext());
91
+ expect(body).toMatch(/<select\s[^>]*id="status"/);
92
+ expect(body).toContain('<option value="draft">draft</option>');
93
+ expect(body).toContain('<option value="live">live</option>');
94
+ });
95
+
96
+ it('Text → textarea', () => {
97
+ const body = composeFormBody(makeContext());
98
+ expect(body).toMatch(/<textarea\s[^>]*id="body"/);
99
+ });
100
+
101
+ it('Boolean → checkbox', () => {
102
+ const body = composeFormBody(makeContext());
103
+ expect(body).toContain('type="checkbox"');
104
+ expect(body).toContain('id="published"');
105
+ expect(body).toContain("checked={Boolean((formData as any).published)}");
106
+ });
107
+
108
+ it('Integer → number input with Number() coercion', () => {
109
+ const body = composeFormBody(makeContext());
110
+ expect(body).toMatch(/id="score"[\s\S]*type="number"/);
111
+ expect(body).toContain("Number(e.target.value)");
112
+ });
113
+
114
+ it('Email → email input', () => {
115
+ const body = composeFormBody(makeContext());
116
+ expect(body).toMatch(/id="email"[\s\S]*type="email"/);
117
+ });
118
+
119
+ it('String default → text input', () => {
120
+ const body = composeFormBody(makeContext());
121
+ expect(body).toMatch(/id="title"[\s\S]*type="text"/);
122
+ });
123
+
124
+ it('UUID → text input (treated like string)', () => {
125
+ // externalId is a plain UUID attribute — no belongsTo relationship
126
+ // shadows it, so it renders as a text input. (FK UUIDs like
127
+ // authorId render as a <select> instead; see the belongsTo suite.)
128
+ const body = composeFormBody(makeContext());
129
+ expect(body).toMatch(/id="externalId"[\s\S]*type="text"/);
130
+ });
131
+ });
132
+
133
+ describe('composeFormBody — required markers', () => {
134
+ it('adds required HTML attribute to required inputs; omits it on optional ones', () => {
135
+ const body = composeFormBody(makeContext());
136
+ // The bareword ` required` attribute, emitted at end of an onChange
137
+ // line. Required fields in the fixture: title, authorId (belongsTo FK
138
+ // emitted as required). Optional: body, published, score, email, status.
139
+ const occurrences = (body.match(/ required$/gm) ?? []).length;
140
+ expect(occurrences).toBe(2);
141
+ });
142
+
143
+ it("appends ' *' to the label of required fields", () => {
144
+ const body = composeFormBody(makeContext());
145
+ expect(body).toContain('Title *');
146
+ // body is not required
147
+ expect(body).not.toContain('Body *');
148
+ });
149
+ });
150
+
151
+ describe('composeFormBody — belongsTo section', () => {
152
+ it('emits a <select> for each belongsTo, iterating ${relName}Options', () => {
153
+ const body = composeFormBody(makeContext());
154
+ // Author belongsTo User — author is the relationship name, so the
155
+ // options array is authorOptions and the FK column is authorId.
156
+ expect(body).toMatch(/<select[\s\S]*?id="authorId"/);
157
+ expect(body).toContain('authorOptions.map');
158
+ expect(body).toContain('getEntityDisplayName(opt)');
159
+ });
160
+
161
+ it('does not emit plain text inputs for FK columns shadowed by a belongsTo', () => {
162
+ // authorId is shadowed by the author belongsTo relationship — it
163
+ // should only render once (as the <select>), never as a text input.
164
+ const body = composeFormBody(makeContext());
165
+ expect(body).not.toMatch(/<input[\s\S]*?id="authorId"[\s\S]*?type="text"/);
166
+ });
167
+ });
168
+
169
+ describe('emitView wired to composeFormBody — end-to-end', () => {
170
+ it('produces a complete PostFormView.tsx that parses', () => {
171
+ const source = emitView(makeContext());
172
+ assertValidTsx(source, 'PostFormView');
173
+ });
174
+
175
+ it('wires the skeleton: component, hooks, modes, body', () => {
176
+ const source = emitView(makeContext());
177
+ expect(source).toContain('export function PostFormView');
178
+ expect(source).toContain('useCreatePostMutation');
179
+ expect(source).toContain('useUpdatePostMutation');
180
+ expect(source).toContain('mode === \'create\'');
181
+ expect(source).toContain('Create Post');
182
+ expect(source).toContain('Update Post');
183
+ // Body injected
184
+ expect(source).toContain('htmlFor="title"');
185
+ expect(source).toContain('<textarea');
186
+ expect(source).not.toMatch(/\{\{[A-Z_]+\}\}/);
187
+ });
188
+ });
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as ts from 'typescript';
3
+ import { emitEntityDisplay } from '../helpers-emitter.js';
4
+
5
+ function assertValidTsx(source: string, label: string): void {
6
+ const result = ts.transpileModule(source, {
7
+ compilerOptions: {
8
+ jsx: ts.JsxEmit.Preserve,
9
+ target: ts.ScriptTarget.ES2022,
10
+ module: ts.ModuleKind.ESNext,
11
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
12
+ strict: true,
13
+ },
14
+ reportDiagnostics: true,
15
+ });
16
+ const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
17
+ if (errors.length > 0) {
18
+ const message = errors
19
+ .map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
20
+ .join('\n');
21
+ throw new Error(`${label} failed to parse as TypeScript:\n${message}`);
22
+ }
23
+ }
24
+
25
+ describe('emitEntityDisplay', () => {
26
+ it('produces a module that parses under strict TypeScript', () => {
27
+ assertValidTsx(emitEntityDisplay(), 'entity-display.ts');
28
+ });
29
+
30
+ it('exports both getEntityDisplayName and resolveEntityDisplayName', () => {
31
+ const src = emitEntityDisplay();
32
+ expect(src).toMatch(/export function getEntityDisplayName/);
33
+ expect(src).toMatch(/export function resolveEntityDisplayName/);
34
+ });
35
+
36
+ it('uses the canonical candidate list in documented order', () => {
37
+ const src = emitEntityDisplay();
38
+ // Order matters: name → title → displayName → label → username → email.
39
+ // The order mirrors @specverse/runtime/views/core/entity-display.
40
+ const candidatesLine = src.match(/const candidates = \[([^\]]+)\]/)?.[1];
41
+ expect(candidatesLine).toBeDefined();
42
+ expect(candidatesLine).toContain("'name'");
43
+ expect(candidatesLine).toContain("'title'");
44
+ expect(candidatesLine).toContain("'displayName'");
45
+ expect(candidatesLine).toContain("'email'");
46
+ // Check relative order
47
+ const order = ['name', 'title', 'displayName', 'label', 'username', 'email'];
48
+ let lastIdx = -1;
49
+ for (const n of order) {
50
+ const idx = candidatesLine!.indexOf(`'${n}'`);
51
+ expect(idx).toBeGreaterThan(lastIdx);
52
+ lastIdx = idx;
53
+ }
54
+ });
55
+ });
@@ -0,0 +1,140 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { htmlToJsx } from '../html-to-jsx.js';
3
+
4
+ describe('htmlToJsx — attribute renames', () => {
5
+ it('renames class → className', () => {
6
+ expect(htmlToJsx('<div class="foo">x</div>')).toBe('<div className="foo">x</div>');
7
+ });
8
+
9
+ it('renames class inside nested elements', () => {
10
+ const input = '<div class="a"><span class="b">hi</span></div>';
11
+ const expected = '<div className="a"><span className="b">hi</span></div>';
12
+ expect(htmlToJsx(input)).toBe(expected);
13
+ });
14
+
15
+ it('renames for → htmlFor on labels', () => {
16
+ expect(htmlToJsx('<label for="id">X</label>')).toBe('<label htmlFor="id">X</label>');
17
+ });
18
+
19
+ it('renames tabindex → tabIndex', () => {
20
+ expect(htmlToJsx('<div tabindex="0">x</div>')).toBe('<div tabIndex="0">x</div>');
21
+ });
22
+
23
+ it('renames multiple attributes in a single tag', () => {
24
+ const input = '<input class="c" readonly maxlength="10" />';
25
+ const out = htmlToJsx(input);
26
+ expect(out).toContain('className="c"');
27
+ expect(out).toContain('readOnly');
28
+ expect(out).toContain('maxLength="10"');
29
+ });
30
+
31
+ it('does not rewrite attribute values that contain "class"', () => {
32
+ // The substring "class" in an attribute value should not be renamed.
33
+ const input = '<div class="has class word" data-x="my class name">y</div>';
34
+ const out = htmlToJsx(input);
35
+ // Expected: only the class ATTRIBUTE is renamed; values unchanged.
36
+ expect(out).toBe('<div className="has class word" data-x="my class name">y</div>');
37
+ });
38
+ });
39
+
40
+ describe('htmlToJsx — void elements', () => {
41
+ it('self-closes img', () => {
42
+ expect(htmlToJsx('<img src="a.png" alt="A">')).toBe('<img src="a.png" alt="A" />');
43
+ });
44
+
45
+ it('self-closes br', () => {
46
+ expect(htmlToJsx('line<br>break')).toBe('line<br />break');
47
+ });
48
+
49
+ it('self-closes input', () => {
50
+ expect(htmlToJsx('<input type="text" class="f">')).toBe('<input type="text" className="f" />');
51
+ });
52
+
53
+ it('self-closes hr', () => {
54
+ expect(htmlToJsx('<hr>')).toBe('<hr />');
55
+ });
56
+
57
+ it('leaves already-self-closed void elements alone', () => {
58
+ expect(htmlToJsx('<br />')).toBe('<br />');
59
+ expect(htmlToJsx('<img src="a" />')).toBe('<img src="a" />');
60
+ });
61
+
62
+ it('handles void elements in the middle of content', () => {
63
+ const input = '<p>hello<br>world<br>!</p>';
64
+ expect(htmlToJsx(input)).toBe('<p>hello<br />world<br />!</p>');
65
+ });
66
+ });
67
+
68
+ describe('htmlToJsx — inline style conversion', () => {
69
+ it('converts a single-declaration style', () => {
70
+ const input = '<div style="color: red">x</div>';
71
+ const out = htmlToJsx(input);
72
+ expect(out).toBe("<div style={{ color: 'red' }}>x</div>");
73
+ });
74
+
75
+ it('converts multiple declarations and camelCases property names', () => {
76
+ const input = '<div style="color: red; font-size: 14px; background-color: blue">x</div>';
77
+ const out = htmlToJsx(input);
78
+ expect(out).toBe("<div style={{ color: 'red', fontSize: '14px', backgroundColor: 'blue' }}>x</div>");
79
+ });
80
+
81
+ it('handles empty style', () => {
82
+ expect(htmlToJsx('<div style="">x</div>')).toBe('<div style={{}}>x</div>');
83
+ });
84
+
85
+ it('escapes single quotes inside values', () => {
86
+ const input = `<div style="font-family: 'Helvetica Neue'">x</div>`;
87
+ const out = htmlToJsx(input);
88
+ expect(out).toBe("<div style={{ fontFamily: '\\'Helvetica Neue\\'' }}>x</div>");
89
+ });
90
+
91
+ it('strips trailing semicolons and extra spacing', () => {
92
+ const input = '<div style="color:red; font-size: 14px ;">x</div>';
93
+ const out = htmlToJsx(input);
94
+ expect(out).toBe("<div style={{ color: 'red', fontSize: '14px' }}>x</div>");
95
+ });
96
+ });
97
+
98
+ describe('htmlToJsx — idempotence', () => {
99
+ it('is a no-op on already-transformed input', () => {
100
+ const jsxLike = '<div className="a"><input type="text" /><br /></div>';
101
+ expect(htmlToJsx(jsxLike)).toBe(jsxLike);
102
+ });
103
+ });
104
+
105
+ describe('htmlToJsx — empty / degenerate input', () => {
106
+ it('returns empty string for empty input', () => {
107
+ expect(htmlToJsx('')).toBe('');
108
+ });
109
+
110
+ it('returns text-only input unchanged', () => {
111
+ expect(htmlToJsx('Loading...')).toBe('Loading...');
112
+ });
113
+ });
114
+
115
+ describe('htmlToJsx — realistic Tailwind-adapter output', () => {
116
+ it('transforms a typical table produced by the adapter', () => {
117
+ const input =
118
+ '<table class="w-full text-left border-collapse">' +
119
+ '<thead><tr><th class="px-4 py-2 font-semibold">Title</th></tr></thead>' +
120
+ '<tbody><tr class="hover:bg-gray-50"><td class="px-4 py-2">Hello</td></tr></tbody>' +
121
+ '</table>';
122
+ const out = htmlToJsx(input);
123
+ expect(out).toContain('className="w-full text-left border-collapse"');
124
+ expect(out).toContain('className="px-4 py-2 font-semibold"');
125
+ expect(out).toContain('className="hover:bg-gray-50"');
126
+ expect(out).not.toContain('class=');
127
+ });
128
+
129
+ it('transforms a form-group with inputs', () => {
130
+ const input =
131
+ '<div class="space-y-4">' +
132
+ '<label for="title" class="text-sm">Title</label>' +
133
+ '<input type="text" class="border rounded px-2 py-1">' +
134
+ '</div>';
135
+ const out = htmlToJsx(input);
136
+ expect(out).toContain('htmlFor="title"');
137
+ expect(out).toContain('className="text-sm"');
138
+ expect(out).toContain('<input type="text" className="border rounded px-2 py-1" />');
139
+ });
140
+ });
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as ts from 'typescript';
3
+ import { composeListBody } from '../list-body-composer.js';
4
+ import { emitView, type EmitContext, type ModelSpec } from '../view-emitter.js';
5
+
6
+ /**
7
+ * End-to-end: the canonical Tailwind adapter renders the table shell,
8
+ * the composer injects a JSX row-map, the emitter substitutes into
9
+ * the skeleton. The full output must parse as valid TSX.
10
+ */
11
+
12
+ function makeContext(overrides: Partial<EmitContext> = {}): EmitContext {
13
+ const post: ModelSpec = {
14
+ name: 'Post',
15
+ attributes: {
16
+ // `id` is excluded by runtime's inferFieldsFromSchema directly.
17
+ id: { type: 'UUID', required: true },
18
+ title: { type: 'String', required: true },
19
+ body: { type: 'Text', required: false },
20
+ // `auto=now` is what marks publishedAt as excluded from column
21
+ // inference — the canonical rule from runtime pattern-engine.
22
+ publishedAt: { type: 'DateTime', required: false, auto: 'now' },
23
+ authorId: { type: 'UUID', required: true },
24
+ },
25
+ };
26
+
27
+ return {
28
+ view: { type: 'list', model: 'Post' },
29
+ viewName: 'PostListView',
30
+ model: post,
31
+ modelSchemas: { Post: post },
32
+ renderBody: composeListBody,
33
+ ...overrides,
34
+ };
35
+ }
36
+
37
+ function assertValidTsx(source: string, label: string): void {
38
+ const result = ts.transpileModule(source, {
39
+ compilerOptions: {
40
+ jsx: ts.JsxEmit.Preserve,
41
+ target: ts.ScriptTarget.ES2022,
42
+ module: ts.ModuleKind.ESNext,
43
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
44
+ strict: false,
45
+ },
46
+ reportDiagnostics: true,
47
+ });
48
+ const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
49
+ if (errors.length > 0) {
50
+ const message = errors
51
+ .map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
52
+ .join('\n');
53
+ throw new Error(`${label} failed to parse as TSX:\n${message}\n\n--- source ---\n${source}`);
54
+ }
55
+ }
56
+
57
+ describe('composeListBody — direct output', () => {
58
+ it('produces JSX containing the canonical table shell', () => {
59
+ const body = composeListBody(makeContext());
60
+ // Comes from the Tailwind adapter's table template
61
+ expect(body).toContain('overflow-x-auto');
62
+ expect(body).toContain('min-w-full');
63
+ expect(body).toContain('<thead');
64
+ expect(body).toContain('<tbody');
65
+ // After html-to-jsx: class → className
66
+ expect(body).toContain('className=');
67
+ expect(body).not.toMatch(/\bclass=/);
68
+ });
69
+
70
+ it('renders one header cell per non-metadata attribute, humanized', () => {
71
+ const body = composeListBody(makeContext());
72
+ expect(body).toContain('>Title<');
73
+ expect(body).toContain('>Body<');
74
+ expect(body).toContain('>Author Id<'); // authorId humanized
75
+ expect(body).not.toContain('>Id<'); // id filtered as metadata
76
+ expect(body).not.toContain('>Published At<'); // publishedAt filtered as metadata
77
+ });
78
+
79
+ it('emits a filtered.map expression with one cell per column', () => {
80
+ const body = composeListBody(makeContext());
81
+ expect(body).toContain('filtered.map((item, idx) =>');
82
+ expect(body).toContain('onClick={() => onSelect?.(item)}');
83
+
84
+ // Count how many times each field name appears in cell-context (inside
85
+ // the `<td>...item.FIELD ??` substring). Metadata should appear 0 times;
86
+ // business fields exactly once each.
87
+ const cellsRegion = body.slice(body.indexOf('<tbody'));
88
+ const cellAppearances = (field: string) =>
89
+ (cellsRegion.match(new RegExp(`item as any\\)\\.${field} \\?\\?`, 'g')) ?? []).length;
90
+
91
+ expect(cellAppearances('title')).toBe(1);
92
+ expect(cellAppearances('body')).toBe(1);
93
+ expect(cellAppearances('authorId')).toBe(1);
94
+ expect(cellAppearances('id')).toBe(0); // metadata
95
+ expect(cellAppearances('publishedAt')).toBe(0); // metadata
96
+ });
97
+
98
+ it('handles a model with zero non-metadata attributes', () => {
99
+ const empty: ModelSpec = {
100
+ name: 'Pulse',
101
+ attributes: { id: { type: 'UUID', required: true } },
102
+ };
103
+ const body = composeListBody(makeContext({
104
+ model: empty,
105
+ view: { type: 'list', model: 'Pulse' },
106
+ viewName: 'PulseListView',
107
+ modelSchemas: { Pulse: empty },
108
+ }));
109
+ // Table renders with empty columns array (no <th> cells inside <tr>)
110
+ expect(body).toContain('<thead');
111
+ // Row map still present — but cells block empty
112
+ expect(body).toContain('filtered.map');
113
+ });
114
+ });
115
+
116
+ describe('emitView wired to composeListBody — end-to-end', () => {
117
+ it('produces a complete PostListView.tsx that parses', () => {
118
+ const source = emitView(makeContext());
119
+ assertValidTsx(source, 'PostListView');
120
+ });
121
+
122
+ it('integrates skeleton + composer correctly', () => {
123
+ const source = emitView(makeContext());
124
+ // From skeleton
125
+ expect(source).toContain('export function PostListView');
126
+ expect(source).toContain('usePostsQuery');
127
+ expect(source).toContain('useDeletePostMutation');
128
+ // From composer (canonical adapter shell + row map)
129
+ expect(source).toContain('filtered.map');
130
+ expect(source).toContain('onSelect?.(item)');
131
+ expect(source).toContain('>Title<');
132
+ // No stray sentinels or placeholders
133
+ expect(source).not.toContain('__SPECVERSE_TBODY_ROWS__');
134
+ expect(source).not.toMatch(/\{\{[A-Z_]+\}\}/);
135
+ });
136
+
137
+ it('produces readable, line-broken output (no wall of HTML)', () => {
138
+ const source = emitView(makeContext());
139
+ // Sanity: the emitted file should be multi-line idiomatic React,
140
+ // not one giant collapsed line.
141
+ const lines = source.split('\n');
142
+ expect(lines.length).toBeGreaterThan(30);
143
+ // And no obviously-HTML escape leakage
144
+ expect(source).not.toContain('dangerouslySetInnerHTML');
145
+ });
146
+ });