@open-mercato/cli 0.6.7 → 0.6.8-canary.320.1.bf889f49e4

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 (335) hide show
  1. package/.turbo/turbo-build.log +77 -4
  2. package/AGENTS.md +6 -1
  3. package/build.mjs +68 -11
  4. package/dist/agentic/claude-code/hooks/entity-migration-check.ts +32 -88
  5. package/dist/agentic/codex/enforcement-rules.md +2 -16
  6. package/dist/agentic/cursor/hooks/entity-migration-check.mjs +19 -50
  7. package/dist/agentic/cursor/rules/entity-guard.mdc +9 -21
  8. package/dist/agentic/cursor/rules/generated-guard.mdc +3 -5
  9. package/dist/agentic/cursor/rules/open-mercato.mdc +3 -29
  10. package/dist/agentic/guides/ai-workflows.md +76 -0
  11. package/dist/agentic/guides/architecture.md +107 -0
  12. package/dist/agentic/guides/backend-ui.md +86 -0
  13. package/dist/agentic/guides/contracts.md +92 -0
  14. package/dist/agentic/guides/extensions.md +121 -0
  15. package/dist/agentic/guides/framework-extension-points.md +36 -0
  16. package/dist/agentic/guides/integrations.md +81 -0
  17. package/dist/agentic/guides/module-facts.json +116757 -3951
  18. package/dist/agentic/guides/module-system.md +12 -127
  19. package/dist/agentic/guides/modules/ai_assistant.md +227 -28
  20. package/dist/agentic/guides/modules/api_docs.md +58 -2
  21. package/dist/agentic/guides/modules/api_keys.md +92 -7
  22. package/dist/agentic/guides/modules/attachments.md +119 -14
  23. package/dist/agentic/guides/modules/audit_logs.md +131 -10
  24. package/dist/agentic/guides/modules/auth.md +276 -33
  25. package/dist/agentic/guides/modules/business_rules.md +149 -14
  26. package/dist/agentic/guides/modules/catalog.md +482 -43
  27. package/dist/agentic/guides/modules/channel_gmail.md +82 -3
  28. package/dist/agentic/guides/modules/channel_imap.md +82 -3
  29. package/dist/agentic/guides/modules/checkout.md +305 -27
  30. package/dist/agentic/guides/modules/communication_channels.md +315 -33
  31. package/dist/agentic/guides/modules/configs.md +104 -8
  32. package/dist/agentic/guides/modules/content.md +57 -2
  33. package/dist/agentic/guides/modules/currencies.md +152 -17
  34. package/dist/agentic/guides/modules/customer_accounts.md +387 -45
  35. package/dist/agentic/guides/modules/customers.md +746 -85
  36. package/dist/agentic/guides/modules/dashboards.md +155 -10
  37. package/dist/agentic/guides/modules/data_sync.md +149 -16
  38. package/dist/agentic/guides/modules/design_system.md +102 -0
  39. package/dist/agentic/guides/modules/dictionaries.md +107 -12
  40. package/dist/agentic/guides/modules/directory.md +148 -15
  41. package/dist/agentic/guides/modules/entities.md +145 -13
  42. package/dist/agentic/guides/modules/events.md +59 -2
  43. package/dist/agentic/guides/modules/feature_toggles.md +119 -9
  44. package/dist/agentic/guides/modules/gateway_stripe.md +92 -4
  45. package/dist/agentic/guides/modules/generators.md +45 -2
  46. package/dist/agentic/guides/modules/inbox_ops.md +207 -27
  47. package/dist/agentic/guides/modules/integrations.md +149 -16
  48. package/dist/agentic/guides/modules/messages.md +223 -24
  49. package/dist/agentic/guides/modules/notifications.md +96 -8
  50. package/dist/agentic/guides/modules/onboarding.md +77 -6
  51. package/dist/agentic/guides/modules/payment_gateways.md +168 -21
  52. package/dist/agentic/guides/modules/perspectives.md +77 -7
  53. package/dist/agentic/guides/modules/planner.md +136 -18
  54. package/dist/agentic/guides/modules/portal.md +93 -2
  55. package/dist/agentic/guides/modules/progress.md +104 -14
  56. package/dist/agentic/guides/modules/query_index.md +154 -15
  57. package/dist/agentic/guides/modules/record_locks.md +206 -21
  58. package/dist/agentic/guides/modules/resources.md +197 -30
  59. package/dist/agentic/guides/modules/sales.md +687 -84
  60. package/dist/agentic/guides/modules/scheduler.md +133 -14
  61. package/dist/agentic/guides/modules/search.md +170 -6
  62. package/dist/agentic/guides/modules/security.md +294 -35
  63. package/dist/agentic/guides/modules/shipping_carriers.md +134 -18
  64. package/dist/agentic/guides/modules/sso.md +151 -26
  65. package/dist/agentic/guides/modules/staff.md +372 -57
  66. package/dist/agentic/guides/modules/storage_s3.md +95 -5
  67. package/dist/agentic/guides/modules/sync_akeneo.md +85 -3
  68. package/dist/agentic/guides/modules/sync_excel.md +75 -6
  69. package/dist/agentic/guides/modules/system_status_overlays.md +60 -2
  70. package/dist/agentic/guides/modules/translations.md +104 -10
  71. package/dist/agentic/guides/modules/webhooks.md +203 -24
  72. package/dist/agentic/guides/modules/wms.md +469 -47
  73. package/dist/agentic/guides/modules/workflows.md +302 -43
  74. package/dist/agentic/guides/reference-module-facts.json +6942 -0
  75. package/dist/agentic/guides/reference-modules/example.md +462 -0
  76. package/dist/agentic/guides/spec-delivery.md +56 -0
  77. package/dist/agentic/guides/testing-debugging.md +80 -0
  78. package/dist/agentic/guides/upstream/AGENTS.md +300 -0
  79. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +334 -0
  80. package/dist/agentic/guides/upstream/manifest.json +8 -0
  81. package/dist/agentic/shared/AGENTS.md.template +120 -311
  82. package/dist/agentic/shared/ai/agentic.config.json +2 -0
  83. package/dist/agentic/shared/ai/harness/README.md +50 -0
  84. package/dist/agentic/shared/ai/harness/RELEASE.md +59 -0
  85. package/dist/agentic/shared/ai/harness/cases.json +20596 -0
  86. package/dist/agentic/shared/ai/harness/cases.schema.json +196 -0
  87. package/dist/agentic/shared/ai/harness/design-system-inventory.json +6326 -0
  88. package/dist/agentic/shared/ai/harness/fixtures/index.json +51 -0
  89. package/dist/agentic/shared/ai/harness/fixtures/seeds.json +166 -0
  90. package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +21 -0
  91. package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +96 -0
  92. package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +172 -0
  93. package/dist/agentic/shared/ai/harness/knowledge-change.schema.json +228 -0
  94. package/dist/agentic/shared/ai/harness/release-matrix.json +163 -0
  95. package/dist/agentic/shared/ai/harness/release-result.schema.json +219 -0
  96. package/dist/agentic/shared/ai/harness/result.schema.json +136 -0
  97. package/dist/agentic/shared/ai/harness/routing-response.schema.json +22 -0
  98. package/dist/agentic/shared/ai/harness/source-link-inventory.json +1706 -0
  99. package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +73 -0
  100. package/dist/agentic/shared/ai/harness/validators.json +82 -0
  101. package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +2121 -0
  102. package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +1096 -0
  103. package/dist/agentic/shared/ai/harness/writable-spec-oracles.mjs +602 -0
  104. package/dist/agentic/shared/ai/lessons/_template.md +16 -0
  105. package/dist/agentic/shared/ai/lessons.md +26 -3
  106. package/dist/agentic/shared/ai/review-checklist.md +36 -0
  107. package/dist/agentic/shared/ai/skills/om-auto-implement-spec/SKILL.md +21 -0
  108. package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +4 -0
  109. package/dist/agentic/shared/ai/skills/om-auto-upgrade-0.6.6-to-0.6.7/SKILL.md +98 -0
  110. package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +21 -241
  111. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +31 -0
  112. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +53 -0
  113. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +15 -0
  114. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +11 -0
  115. package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +30 -0
  116. package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +12 -0
  117. package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +13 -0
  118. package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +14 -0
  119. package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +28 -0
  120. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +12 -0
  121. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +22 -0
  122. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +12 -0
  123. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +19 -0
  124. package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +17 -601
  125. package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +21 -0
  126. package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +15 -0
  127. package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +16 -0
  128. package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +10 -0
  129. package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +15 -310
  130. package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +19 -0
  131. package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +31 -0
  132. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +100 -0
  133. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +16 -0
  134. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/knowledge-change.md +133 -0
  135. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +17 -0
  136. package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +25 -0
  137. package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +11 -0
  138. package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +13 -0
  139. package/dist/agentic/shared/ai/skills/om-help/SKILL.md +15 -97
  140. package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +18 -0
  141. package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +20 -0
  142. package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +33 -152
  143. package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +33 -0
  144. package/dist/agentic/shared/ai/skills/om-implement-spec/references/planning-and-progress.md +40 -0
  145. package/dist/agentic/shared/ai/skills/om-implement-spec/references/report-templates.md +27 -0
  146. package/dist/agentic/shared/ai/skills/om-implement-spec/references/spec-resolution.md +24 -0
  147. package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +25 -708
  148. package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +16 -0
  149. package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +25 -0
  150. package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +15 -0
  151. package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +12 -0
  152. package/dist/agentic/shared/ai/skills/om-judge-agent-session/SKILL.md +34 -0
  153. package/dist/agentic/shared/ai/skills/om-judge-agent-session/agents/openai.yaml +4 -0
  154. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/agentic-setup.md +11 -0
  155. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/input-normalization.md +31 -0
  156. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/judge-workflow.md +39 -0
  157. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/report-template.md +43 -0
  158. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/rules.md +11 -0
  159. package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +20 -820
  160. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +32 -0
  161. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +172 -0
  162. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +14 -0
  163. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +83 -0
  164. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +40 -0
  165. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +11 -0
  166. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +22 -0
  167. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +13 -0
  168. package/dist/agentic/shared/ai/skills/om-share-this-session/SKILL.md +41 -0
  169. package/dist/agentic/shared/ai/skills/om-share-this-session/references/agentic-setup.md +19 -0
  170. package/dist/agentic/shared/ai/skills/om-share-this-session/references/bundle-preparation.md +44 -0
  171. package/dist/agentic/shared/ai/skills/om-share-this-session/references/consent-and-review.md +39 -0
  172. package/dist/agentic/shared/ai/skills/om-share-this-session/references/publication.md +20 -0
  173. package/dist/agentic/shared/ai/skills/om-share-this-session/references/report-templates.md +57 -0
  174. package/dist/agentic/shared/ai/skills/om-share-this-session/references/rules.md +11 -0
  175. package/dist/agentic/shared/ai/skills/om-share-this-session/scripts/prepare-share-bundle.mjs +486 -0
  176. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +20 -843
  177. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +42 -0
  178. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +27 -0
  179. package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +13 -0
  180. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +43 -0
  181. package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +11 -0
  182. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +15 -63
  183. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +15 -0
  184. package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +17 -467
  185. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +29 -0
  186. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +14 -0
  187. package/dist/agentic/shared/ai/skills/tiers.json +143 -21
  188. package/dist/agentic/shared/ai/skills/tiers.schema.json +52 -40
  189. package/dist/agentic/shared/ai/specs/2026-08-06-reference-module-activation.md +248 -0
  190. package/dist/agentic/shared/ai/specs/README.md +4 -3
  191. package/dist/agentic/shared/ai/specs/SPEC-000-template.md +226 -10
  192. package/dist/agentic/shared/ai/trackers/github.md +108 -4
  193. package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +224 -0
  194. package/dist/agentic/shared/scripts/check-lessons.mjs +178 -0
  195. package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +3812 -0
  196. package/dist/agentic/shared/scripts/execution-sandbox.mjs +329 -0
  197. package/dist/agentic/shared/scripts/framework-context.mjs +888 -0
  198. package/dist/agentic/shared/scripts/install-skills.mjs +1029 -0
  199. package/dist/agentic/shared/scripts/install-skills.sh +4 -694
  200. package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +222 -0
  201. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +1774 -0
  202. package/dist/agentic/shared/scripts/validate-knowledge-change.mjs +1172 -0
  203. package/dist/bin.js +32 -34
  204. package/dist/bin.js.map +2 -2
  205. package/dist/lib/__integration__/TC-INT-008.spec.js +88 -8
  206. package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
  207. package/dist/lib/agentic-init.js +13 -3
  208. package/dist/lib/agentic-init.js.map +2 -2
  209. package/dist/lib/agentic-setup.js +434 -186
  210. package/dist/lib/agentic-setup.js.map +2 -2
  211. package/dist/lib/cli-bootstrap-mode.js +32 -0
  212. package/dist/lib/cli-bootstrap-mode.js.map +7 -0
  213. package/dist/lib/dev-supervisor-manifest.js +105 -0
  214. package/dist/lib/dev-supervisor-manifest.js.map +7 -0
  215. package/dist/lib/generate-watch-events.js +15 -0
  216. package/dist/lib/generate-watch-events.js.map +2 -2
  217. package/dist/lib/generators/entity-ids.js +11 -24
  218. package/dist/lib/generators/entity-ids.js.map +2 -2
  219. package/dist/lib/generators/extensions/injection-widgets.js +20 -0
  220. package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
  221. package/dist/lib/generators/module-di.js +10 -23
  222. package/dist/lib/generators/module-di.js.map +2 -2
  223. package/dist/lib/generators/module-entities.js +10 -23
  224. package/dist/lib/generators/module-entities.js.map +2 -2
  225. package/dist/lib/generators/module-extension-facts.js +1882 -0
  226. package/dist/lib/generators/module-extension-facts.js.map +7 -0
  227. package/dist/lib/generators/module-fact-sources.js +70 -0
  228. package/dist/lib/generators/module-fact-sources.js.map +7 -0
  229. package/dist/lib/generators/module-facts-discovery.js +64 -7
  230. package/dist/lib/generators/module-facts-discovery.js.map +2 -2
  231. package/dist/lib/generators/module-facts.js +1913 -52
  232. package/dist/lib/generators/module-facts.js.map +3 -3
  233. package/dist/lib/generators/module-override-targets.js +712 -0
  234. package/dist/lib/generators/module-override-targets.js.map +7 -0
  235. package/dist/lib/generators/module-registry.js +405 -36
  236. package/dist/lib/generators/module-registry.js.map +2 -2
  237. package/dist/lib/generators/route-manifest-shards.js +170 -0
  238. package/dist/lib/generators/route-manifest-shards.js.map +7 -0
  239. package/dist/lib/in-process-generate-watcher.js +12 -3
  240. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  241. package/dist/lib/load-env.js +24 -0
  242. package/dist/lib/load-env.js.map +7 -0
  243. package/dist/lib/queue-worker-supervisor.js.map +2 -2
  244. package/dist/lib/resolver.js +28 -3
  245. package/dist/lib/resolver.js.map +2 -2
  246. package/dist/lib/telemetry-init.js +358 -0
  247. package/dist/lib/telemetry-init.js.map +7 -0
  248. package/dist/lib/testing/integration.js +5 -2
  249. package/dist/lib/testing/integration.js.map +2 -2
  250. package/dist/lib/utils.js +15 -8
  251. package/dist/lib/utils.js.map +2 -2
  252. package/dist/mercato.js +35 -9
  253. package/dist/mercato.js.map +2 -2
  254. package/package.json +13 -11
  255. package/src/__tests__/mercato.test.ts +144 -0
  256. package/src/bin.ts +60 -42
  257. package/src/lib/__integration__/TC-INT-008.spec.ts +107 -9
  258. package/src/lib/__tests__/agentic-init.test.ts +41 -5
  259. package/src/lib/__tests__/agentic-setup.ownership.test.ts +386 -0
  260. package/src/lib/__tests__/cli-bootstrap-mode.test.ts +22 -0
  261. package/src/lib/__tests__/content-stable-writes.test.ts +74 -0
  262. package/src/lib/__tests__/dev-supervisor-manifest.test.ts +131 -0
  263. package/src/lib/__tests__/generate-watch-events.test.ts +76 -0
  264. package/src/lib/__tests__/in-process-generate-watcher.test.ts +52 -1
  265. package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
  266. package/src/lib/__tests__/load-env.test.ts +65 -0
  267. package/src/lib/__tests__/queue-worker-supervisor.test.ts +33 -0
  268. package/src/lib/__tests__/resolver.enterprise.test.ts +50 -0
  269. package/src/lib/__tests__/telemetry-init.test.ts +298 -0
  270. package/src/lib/agentic-init.ts +15 -3
  271. package/src/lib/agentic-setup.ts +573 -222
  272. package/src/lib/cli-bootstrap-mode.ts +31 -0
  273. package/src/lib/dev-supervisor-manifest.ts +142 -0
  274. package/src/lib/generate-watch-events.ts +14 -0
  275. package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +92 -0
  276. package/src/lib/generators/__tests__/entity-ids.test.ts +32 -0
  277. package/src/lib/generators/__tests__/helpers/override-target-diagnostic-fixtures.ts +150 -0
  278. package/src/lib/generators/__tests__/module-extension-activations.test.ts +762 -0
  279. package/src/lib/generators/__tests__/module-extension-facts.test.ts +603 -0
  280. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +139 -2
  281. package/src/lib/generators/__tests__/module-facts.computed-di-token.test.ts +88 -0
  282. package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +1 -0
  283. package/src/lib/generators/__tests__/module-facts.discovery.test.ts +54 -10
  284. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +414 -0
  285. package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +108 -0
  286. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +393 -0
  287. package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +561 -0
  288. package/src/lib/generators/__tests__/module-facts.search-entity-id.test.ts +151 -0
  289. package/src/lib/generators/__tests__/module-facts.source-links.test.ts +160 -0
  290. package/src/lib/generators/__tests__/module-override-targets.diagnostic-wiring.test.ts +92 -0
  291. package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +149 -0
  292. package/src/lib/generators/__tests__/module-override-targets.test.ts +328 -0
  293. package/src/lib/generators/__tests__/module-override-targets.unknown-mode.test.ts +117 -0
  294. package/src/lib/generators/__tests__/module-subset.test.ts +266 -0
  295. package/src/lib/generators/__tests__/output-snapshots.test.ts +3 -3
  296. package/src/lib/generators/__tests__/route-manifest-shards.test.ts +62 -0
  297. package/src/lib/generators/entity-ids.ts +10 -26
  298. package/src/lib/generators/extensions/injection-widgets.ts +51 -0
  299. package/src/lib/generators/module-di.ts +9 -25
  300. package/src/lib/generators/module-entities.ts +9 -25
  301. package/src/lib/generators/module-extension-facts.ts +2472 -0
  302. package/src/lib/generators/module-fact-sources.ts +108 -0
  303. package/src/lib/generators/module-facts-discovery.ts +104 -7
  304. package/src/lib/generators/module-facts.ts +2747 -138
  305. package/src/lib/generators/module-override-targets.ts +907 -0
  306. package/src/lib/generators/module-registry.ts +448 -35
  307. package/src/lib/generators/route-manifest-shards.ts +146 -0
  308. package/src/lib/in-process-generate-watcher.ts +13 -4
  309. package/src/lib/load-env.ts +30 -0
  310. package/src/lib/queue-worker-supervisor.ts +7 -2
  311. package/src/lib/resolver.ts +34 -3
  312. package/src/lib/telemetry-init.ts +461 -0
  313. package/src/lib/testing/__tests__/integration.test.ts +4 -0
  314. package/src/lib/testing/integration.ts +5 -2
  315. package/src/lib/utils.ts +24 -16
  316. package/src/mercato.ts +46 -9
  317. package/dist/agentic/guides/cache.md +0 -45
  318. package/dist/agentic/guides/core.md +0 -453
  319. package/dist/agentic/guides/events.md +0 -117
  320. package/dist/agentic/guides/queue.md +0 -53
  321. package/dist/agentic/guides/search.md +0 -115
  322. package/dist/agentic/guides/shared.md +0 -108
  323. package/dist/agentic/guides/ui.md +0 -347
  324. package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +0 -27
  325. package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +0 -27
  326. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +0 -260
  327. package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +0 -146
  328. package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +0 -84
  329. package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +0 -193
  330. package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +0 -34
  331. package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +0 -762
  332. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +0 -50
  333. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +0 -97
  334. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +0 -271
  335. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +0 -101
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/generators/entity-ids.ts"],
4
- "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport ts from 'typescript-js'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver, ModuleEntry } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS } from './scanner'\nimport {\n calculateChecksum,\n readChecksumRecord,\n writeChecksumRecord,\n ensureDir,\n toVar,\n toSnake,\n rimrafDir,\n logGenerationResult,\n writeIfChanged,\n type GeneratorResult,\n createGeneratorResult,\n} from '../utils'\nimport { addAutoGeneratedComment, createGeneratedSourceFile, elementAccess, getSourceText, identifier, returnStatement } from './ast'\n\ntype GroupKey = '@app' | '@open-mercato/core' | string\ntype EntityFieldMap = Record<string, string[]>\n\nexport interface EntityIdsOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\n/**\n * Extract exported class names from a TypeScript source file without dynamic import.\n * This is used for @app modules since Node.js can't import TypeScript files directly.\n */\nfunction parseExportedClassNamesFromFile(filePath: string): string[] {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n const classNames: string[] = []\n\n sf.forEachChild((node) => {\n // Check for exported class declarations\n if (ts.isClassDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n )\n if (hasExport) {\n classNames.push(node.name.text)\n }\n }\n })\n\n return classNames\n}\n\nfunction unwrapObjectLiteralExpression(\n expression: ts.Expression | undefined,\n): ts.ObjectLiteralExpression | undefined {\n if (!expression) return undefined\n if (ts.isObjectLiteralExpression(expression)) return expression\n if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)) {\n return unwrapObjectLiteralExpression(expression.expression)\n }\n if (ts.isParenthesizedExpression(expression)) {\n return unwrapObjectLiteralExpression(expression.expression)\n }\n return undefined\n}\n\nfunction readPropertyInitializer(\n objectLiteral: ts.ObjectLiteralExpression,\n propertyName: string,\n): ts.Expression | undefined {\n for (const property of objectLiteral.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const name = ts.isIdentifier(property.name)\n ? property.name.text\n : ts.isStringLiteralLike(property.name)\n ? property.name.text\n : undefined\n if (name === propertyName) {\n return property.initializer\n }\n }\n return undefined\n}\n\nfunction parseGeneratedModuleEntityNames(filePath: string, moduleId: string): string[] {\n if (!fs.existsSync(filePath)) return []\n\n const source = fs.readFileSync(filePath, 'utf8')\n const scriptKind = filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.ES2020, true, scriptKind)\n\n for (const statement of sf.statements) {\n if (!ts.isVariableStatement(statement)) continue\n const declaration = statement.declarationList.declarations.find((candidate) =>\n ts.isIdentifier(candidate.name) && candidate.name.text === 'E')\n if (!declaration) continue\n\n const eObject = unwrapObjectLiteralExpression(declaration.initializer)\n if (!eObject) continue\n\n const moduleObject = unwrapObjectLiteralExpression(readPropertyInitializer(eObject, moduleId))\n if (!moduleObject) return []\n\n const names: string[] = []\n for (const property of moduleObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const name = ts.isIdentifier(property.name)\n ? property.name.text\n : ts.isStringLiteralLike(property.name)\n ? property.name.text\n : undefined\n if (name) names.push(name)\n }\n return names\n }\n\n return []\n}\n\nfunction parseGeneratedEntityFieldsFile(filePath: string): string[] {\n if (!fs.existsSync(filePath)) return []\n\n const source = fs.readFileSync(filePath, 'utf8')\n const scriptKind = filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.ES2020, true, scriptKind)\n const fields: string[] = []\n\n for (const statement of sf.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n if (!ts.isStringLiteralLike(declaration.initializer)) continue\n fields.push(declaration.initializer.text)\n }\n }\n\n return Array.from(new Set(fields))\n}\n\nfunction resolveExistingFile(candidates: string[]): string | null {\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n\nfunction loadStandaloneGeneratedPackageEntities(\n resolver: PackageResolver,\n entry: ModuleEntry,\n): { entityNames: string[]; entityFieldMap: EntityFieldMap } | null {\n if (resolver.isMonorepo() || !entry.from || entry.from === '@app') return null\n\n const packageRoot = resolver.getPackageRoot(entry.from)\n const generatedRoot = fs.existsSync(path.join(packageRoot, 'generated'))\n ? path.join(packageRoot, 'generated')\n : path.join(packageRoot, 'dist', 'generated')\n const idsFile = resolveExistingFile([\n path.join(generatedRoot, 'entities.ids.generated.ts'),\n path.join(generatedRoot, 'entities.ids.generated.js'),\n ])\n if (!idsFile) return null\n const entityNames = parseGeneratedModuleEntityNames(idsFile, entry.id)\n\n if (entityNames.length === 0) return null\n\n const entityFieldMap: EntityFieldMap = {}\n for (const entityName of entityNames) {\n const fieldsFile = resolveExistingFile([\n path.join(generatedRoot, 'entities', entityName, 'index.ts'),\n path.join(generatedRoot, 'entities', entityName, 'index.js'),\n ])\n if (!fieldsFile) continue\n const fields = parseGeneratedEntityFieldsFile(fieldsFile)\n entityFieldMap[entityName] = fields\n }\n\n return { entityNames, entityFieldMap }\n}\n\nfunction parseEntityFieldsFromFile(filePath: string, exportedClassNames: string[]): EntityFieldMap {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n\n const exported = new Set(exportedClassNames)\n const result: EntityFieldMap = {}\n\n function getDecoratorArgNameLiteral(dec: ts.Decorator | undefined): string | undefined {\n if (!dec) return undefined\n const expr = dec.expression\n if (!ts.isCallExpression(expr)) return undefined\n if (!expr.arguments.length) return undefined\n const first = expr.arguments[0]\n if (!ts.isObjectLiteralExpression(first)) return undefined\n for (const prop of first.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === 'name') {\n if (ts.isStringLiteral(prop.initializer)) return prop.initializer.text\n }\n }\n return undefined\n }\n\n function normalizeDbName(propertyName: string, _decoratorName?: string, nameOverride?: string): string {\n if (nameOverride) return nameOverride\n return toSnake(propertyName)\n }\n\n sf.forEachChild((node) => {\n if (!ts.isClassDeclaration(node) || !node.name) return\n const clsName = node.name.text\n if (!exported.has(clsName)) return\n const entityKey = toSnake(clsName)\n const fields: string[] = []\n\n for (const member of node.members) {\n if (!ts.isPropertyDeclaration(member) || !member.name) continue\n const name = ts.isIdentifier(member.name)\n ? member.name.text\n : ts.isStringLiteral(member.name)\n ? member.name.text\n : undefined\n if (!name) continue\n if (member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword)) continue\n const decorators = ts.canHaveDecorators(member)\n ? ts.getDecorators(member) ?? []\n : []\n let dbName: string | undefined\n if (decorators && decorators.length) {\n for (const d of decorators) {\n const nameOverride = getDecoratorArgNameLiteral(d)\n dbName = normalizeDbName(name, undefined, nameOverride)\n if (dbName) break\n }\n }\n if (!dbName) dbName = normalizeDbName(name)\n fields.push(dbName)\n }\n result[entityKey] = Array.from(new Set(fields))\n })\n\n return result\n}\n\nfunction writeTrackedFile(\n filePath: string,\n content: string,\n result: GeneratorResult,\n): void {\n if (writeIfChanged(filePath, content)) {\n result.filesWritten.push(filePath)\n } else {\n result.filesUnchanged.push(filePath)\n }\n}\n\nfunction writePerEntityFieldFiles(\n outRoot: string,\n fieldsByEntity: EntityFieldMap,\n result: GeneratorResult,\n): void {\n fs.mkdirSync(outRoot, { recursive: true })\n const desiredEntities = new Set(Object.keys(fieldsByEntity))\n for (const [entity, fields] of Object.entries(fieldsByEntity)) {\n const entDir = path.join(outRoot, entity)\n fs.mkdirSync(entDir, { recursive: true })\n const sourceFile = createGeneratedSourceFile(`${entity}/index.ts`)\n for (const field of fields) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: toVar(field),\n initializer: JSON.stringify(field),\n },\n ],\n })\n }\n writeTrackedFile(path.join(entDir, 'index.ts'), getSourceText(sourceFile), result)\n }\n\n const existingEntries = fs.existsSync(outRoot) ? fs.readdirSync(outRoot, { withFileTypes: true }) : []\n for (const entry of existingEntries) {\n if (!entry.isDirectory()) continue\n if (desiredEntities.has(entry.name)) continue\n const staleDirectory = path.join(outRoot, entry.name)\n rimrafDir(staleDirectory)\n result.filesWritten.push(staleDirectory)\n }\n}\n\nfunction writeEntityFieldsRegistry(\n generatedRoot: string,\n fieldsByEntity: EntityFieldMap,\n result: GeneratorResult,\n): void {\n const entities = Object.keys(fieldsByEntity).sort((a, b) => a.localeCompare(b))\n const registry: Record<string, Record<string, string>> = {}\n for (const entity of entities) {\n registry[toVar(entity)] = {}\n for (const field of fieldsByEntity[entity] ?? []) {\n registry[toVar(entity)][toVar(field)] = field\n }\n }\n\n const sourceFile = createGeneratedSourceFile('entity-fields-registry.ts')\n addAutoGeneratedComment(sourceFile, 'entity-ids')\n sourceFile.insertText(sourceFile.getFullText().length, '// Static registry for entity fields - eliminates dynamic imports for Turbopack compatibility\\n')\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'entityFieldsRegistry',\n type: 'Record<string, Record<string, string>>',\n initializer: JSON.stringify(registry, null, 2),\n },\n ],\n })\n sourceFile.addFunction({\n name: 'getEntityFields',\n isExported: true,\n parameters: [{ name: 'slug', type: 'string' }],\n returnType: 'Record<string, string> | undefined',\n statements: [returnStatement(elementAccess(identifier('entityFieldsRegistry'), identifier('slug')))],\n })\n const outPath = path.join(generatedRoot, 'entity-fields-registry.ts')\n writeTrackedFile(outPath, getSourceText(sourceFile), result)\n}\n\nexport async function generateEntityIds(options: EntityIdsOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.ids.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.ids.generated.checksum')\n\n const entries = resolver.loadEnabledModules()\n\n const consolidated: Record<string, Record<string, string>> = {}\n const grouped: Record<GroupKey, Record<string, Record<string, string>>> = {}\n const modulesDict: Record<string, string> = {}\n const groupedModulesDict: Record<GroupKey, Record<string, string>> = {}\n\n const fieldsByGroup: Record<GroupKey, Record<string, EntityFieldMap>> = {}\n\n for (const entry of entries) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imps = resolver.getModuleImportBase(entry)\n const group: GroupKey = (entry.from as GroupKey) || '@open-mercato/core'\n\n const standaloneGeneratedPackageEntities = loadStandaloneGeneratedPackageEntities(resolver, entry)\n\n // Locate entities definition file (prefer app override)\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override', 'entities', 'schema']\n let importPath: string | null = null\n let filePath: string | null = null\n\n for (const base of bases) {\n for (const f of candidates) {\n const p = resolveConventionFile(base, f)\n if (p) {\n const fromApp = base.startsWith(roots.appBase)\n const sub = path.basename(base) // 'data' | 'db'\n importPath = `${fromApp ? imps.appBase : imps.pkgBase}/${sub}/${f}`\n filePath = p\n break\n }\n }\n if (importPath) break\n }\n\n // No entities file found -> still register module id\n if (!filePath && !standaloneGeneratedPackageEntities) {\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n continue\n }\n\n const exportNames = filePath ? parseExportedClassNamesFromFile(filePath) : []\n\n const entityNames = standaloneGeneratedPackageEntities\n ? standaloneGeneratedPackageEntities.entityNames\n : exportNames\n .map((k) => toSnake(k))\n .filter((k, idx, arr) => arr.indexOf(k) === idx)\n\n // Build dictionaries\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n\n consolidated[modId] = consolidated[modId] || {}\n grouped[group] = grouped[group] || {}\n grouped[group][modId] = grouped[group][modId] || {}\n\n for (const en of entityNames) {\n consolidated[modId][en] = `${modId}:${en}`\n grouped[group][modId][en] = `${modId}:${en}`\n }\n\n // Parse entity fields from TypeScript source\n const entityFieldMap = standaloneGeneratedPackageEntities\n ? standaloneGeneratedPackageEntities.entityFieldMap\n : parseEntityFieldsFromFile(filePath!, exportNames)\n fieldsByGroup[group] = fieldsByGroup[group] || {}\n fieldsByGroup[group][modId] = entityFieldMap\n }\n\n // Write consolidated output\n const consolidatedSourceFile = createGeneratedSourceFile('entities.ids.generated.ts')\n addAutoGeneratedComment(consolidatedSourceFile, 'entity-ids')\n consolidatedSourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n { name: 'M', initializer: `${JSON.stringify(modulesDict, null, 2)} as const` },\n { name: 'E', initializer: `${JSON.stringify(consolidated, null, 2)} as const` },\n ],\n })\n consolidatedSourceFile.addTypeAlias({\n name: 'KnownModuleId',\n isExported: true,\n type: 'keyof typeof M',\n })\n consolidatedSourceFile.addTypeAlias({\n name: 'KnownEntities',\n isExported: true,\n type: 'typeof E',\n })\n const consolidatedSrc = getSourceText(consolidatedSourceFile)\n\n // Check if content has changed\n const newChecksum = calculateChecksum(consolidatedSrc)\n let shouldWrite = true\n\n const existingRecord = readChecksumRecord(checksumFile)\n if (existingRecord && existingRecord.content === newChecksum) {\n shouldWrite = false\n }\n\n if (shouldWrite) {\n ensureDir(outFile)\n fs.writeFileSync(outFile, consolidatedSrc)\n writeChecksumRecord(checksumFile, { content: newChecksum, structure: '' })\n result.filesWritten.push(outFile)\n if (!quiet) {\n logGenerationResult(path.relative(process.cwd(), outFile), true)\n }\n } else {\n result.filesUnchanged.push(outFile)\n }\n\n // Write per-group outputs\n const groups = Object.keys(grouped) as GroupKey[]\n for (const g of groups) {\n if (!resolver.isMonorepo() && g !== '@app') {\n continue\n }\n\n const pkgOutputDir = resolver.getPackageOutputDir(g)\n // Skip @app group since it writes to the same location as the consolidated output\n if (g === '@app' && pkgOutputDir === outputDir) {\n continue\n }\n const out = path.join(pkgOutputDir, 'entities.ids.generated.ts')\n\n const groupSourceFile = createGeneratedSourceFile(`${String(g)}/entities.ids.generated.ts`)\n addAutoGeneratedComment(groupSourceFile, 'entity-ids')\n groupSourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n { name: 'M', initializer: `${JSON.stringify(groupedModulesDict[g] || {}, null, 2)} as const` },\n { name: 'E', initializer: `${JSON.stringify(grouped[g] || {}, null, 2)} as const` },\n ],\n })\n groupSourceFile.addTypeAlias({\n name: 'KnownModuleId',\n isExported: true,\n type: 'keyof typeof M',\n })\n groupSourceFile.addTypeAlias({\n name: 'KnownEntities',\n isExported: true,\n type: 'typeof E',\n })\n const src = getSourceText(groupSourceFile)\n writeTrackedFile(out, src, result)\n\n const fieldsRoot = path.join(pkgOutputDir, 'entities')\n const fieldsByModule = fieldsByGroup[g] || {}\n const combined: EntityFieldMap = {}\n for (const mId of Object.keys(fieldsByModule)) {\n const mMap = fieldsByModule[mId]\n for (const [entity, fields] of Object.entries(mMap)) {\n combined[entity] = Array.from(new Set([...(combined[entity] || []), ...fields]))\n }\n }\n writePerEntityFieldFiles(fieldsRoot, combined, result)\n\n // Generate static entity fields registry for Turbopack compatibility\n writeEntityFieldsRegistry(pkgOutputDir, combined, result)\n }\n\n // Write combined entity fields to root generated/ folder\n const combinedAll: EntityFieldMap = {}\n for (const groupFields of Object.values(fieldsByGroup)) {\n for (const mMap of Object.values(groupFields)) {\n for (const [entity, fields] of Object.entries(mMap)) {\n combinedAll[entity] = Array.from(new Set([...(combinedAll[entity] || []), ...fields]))\n }\n }\n }\n writePerEntityFieldFiles(path.join(outputDir, 'entities'), combinedAll, result)\n writeEntityFieldsRegistry(outputDir, combinedAll, result)\n\n return result\n}\n\nfunction resolveConventionFile(baseDir: string, basename: string): string | null {\n for (const extension of MODULE_CODE_EXTENSIONS) {\n const candidate = path.join(baseDir, `${basename}${extension}`)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n"],
5
- "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,+BAA+B;AAExC,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,yBAAyB,2BAA2B,eAAe,eAAe,YAAY,uBAAuB;AAc9H,SAAS,gCAAgC,UAA4B;AACnE,QAAM,MAAM,GAAG,aAAa,UAAU,MAAM;AAC5C,QAAM,KAAK,GAAG,iBAAiB,UAAU,KAAK,GAAG,aAAa,QAAQ,MAAM,GAAG,WAAW,EAAE;AAC5F,QAAM,aAAuB,CAAC;AAE9B,KAAG,aAAa,CAAC,SAAS;AAExB,QAAI,GAAG,mBAAmB,IAAI,KAAK,KAAK,MAAM;AAC5C,YAAM,YAAY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GAAG,MAAM,CAAC,CAAC;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AACA,2BAAyB,KAAK,KAAK,WAAW,UAAU,GAAG,aAAa,MAAM;AAC9E,4BAA0B,WAAW,aAAa,MAAM;AAExD,SAAO;AACT;AAEA,SAAS,sBAAsB,SAAiB,UAAiC;AAC/E,aAAW,aAAa,wBAAwB;AAC9C,UAAM,YAAY,KAAK,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE;AAC9D,QAAI,GAAG,WAAW,SAAS,EAAG,QAAO;AAAA,EACvC;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport ts from 'typescript-js'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver, ModuleEntry } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS } from './scanner'\nimport {\n toVar,\n toSnake,\n rimrafDir,\n type GeneratorResult,\n createGeneratorResult,\n writeGeneratedFile,\n writeIfChanged,\n} from '../utils'\nimport { addAutoGeneratedComment, createGeneratedSourceFile, elementAccess, getSourceText, identifier, returnStatement } from './ast'\n\ntype GroupKey = '@app' | '@open-mercato/core' | string\ntype EntityFieldMap = Record<string, string[]>\n\nexport interface EntityIdsOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\n/**\n * Extract exported class names from a TypeScript source file without dynamic import.\n * This is used for @app modules since Node.js can't import TypeScript files directly.\n */\nfunction parseExportedClassNamesFromFile(filePath: string): string[] {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n const classNames: string[] = []\n\n sf.forEachChild((node) => {\n // Check for exported class declarations\n if (ts.isClassDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n )\n if (hasExport) {\n classNames.push(node.name.text)\n }\n }\n })\n\n return classNames\n}\n\nfunction unwrapObjectLiteralExpression(\n expression: ts.Expression | undefined,\n): ts.ObjectLiteralExpression | undefined {\n if (!expression) return undefined\n if (ts.isObjectLiteralExpression(expression)) return expression\n if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)) {\n return unwrapObjectLiteralExpression(expression.expression)\n }\n if (ts.isParenthesizedExpression(expression)) {\n return unwrapObjectLiteralExpression(expression.expression)\n }\n return undefined\n}\n\nfunction readPropertyInitializer(\n objectLiteral: ts.ObjectLiteralExpression,\n propertyName: string,\n): ts.Expression | undefined {\n for (const property of objectLiteral.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const name = ts.isIdentifier(property.name)\n ? property.name.text\n : ts.isStringLiteralLike(property.name)\n ? property.name.text\n : undefined\n if (name === propertyName) {\n return property.initializer\n }\n }\n return undefined\n}\n\nfunction parseGeneratedModuleEntityNames(filePath: string, moduleId: string): string[] {\n if (!fs.existsSync(filePath)) return []\n\n const source = fs.readFileSync(filePath, 'utf8')\n const scriptKind = filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.ES2020, true, scriptKind)\n\n for (const statement of sf.statements) {\n if (!ts.isVariableStatement(statement)) continue\n const declaration = statement.declarationList.declarations.find((candidate) =>\n ts.isIdentifier(candidate.name) && candidate.name.text === 'E')\n if (!declaration) continue\n\n const eObject = unwrapObjectLiteralExpression(declaration.initializer)\n if (!eObject) continue\n\n const moduleObject = unwrapObjectLiteralExpression(readPropertyInitializer(eObject, moduleId))\n if (!moduleObject) return []\n\n const names: string[] = []\n for (const property of moduleObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const name = ts.isIdentifier(property.name)\n ? property.name.text\n : ts.isStringLiteralLike(property.name)\n ? property.name.text\n : undefined\n if (name) names.push(name)\n }\n return names\n }\n\n return []\n}\n\nfunction parseGeneratedEntityFieldsFile(filePath: string): string[] {\n if (!fs.existsSync(filePath)) return []\n\n const source = fs.readFileSync(filePath, 'utf8')\n const scriptKind = filePath.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS\n const sf = ts.createSourceFile(filePath, source, ts.ScriptTarget.ES2020, true, scriptKind)\n const fields: string[] = []\n\n for (const statement of sf.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n if (!ts.isStringLiteralLike(declaration.initializer)) continue\n fields.push(declaration.initializer.text)\n }\n }\n\n return Array.from(new Set(fields))\n}\n\nfunction resolveExistingFile(candidates: string[]): string | null {\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n\nfunction loadStandaloneGeneratedPackageEntities(\n resolver: PackageResolver,\n entry: ModuleEntry,\n): { entityNames: string[]; entityFieldMap: EntityFieldMap } | null {\n if (resolver.isMonorepo() || !entry.from || entry.from === '@app') return null\n\n const packageRoot = resolver.getPackageRoot(entry.from)\n const generatedRoot = fs.existsSync(path.join(packageRoot, 'generated'))\n ? path.join(packageRoot, 'generated')\n : path.join(packageRoot, 'dist', 'generated')\n const idsFile = resolveExistingFile([\n path.join(generatedRoot, 'entities.ids.generated.ts'),\n path.join(generatedRoot, 'entities.ids.generated.js'),\n ])\n if (!idsFile) return null\n const entityNames = parseGeneratedModuleEntityNames(idsFile, entry.id)\n\n if (entityNames.length === 0) return null\n\n const entityFieldMap: EntityFieldMap = {}\n for (const entityName of entityNames) {\n const fieldsFile = resolveExistingFile([\n path.join(generatedRoot, 'entities', entityName, 'index.ts'),\n path.join(generatedRoot, 'entities', entityName, 'index.js'),\n ])\n if (!fieldsFile) continue\n const fields = parseGeneratedEntityFieldsFile(fieldsFile)\n entityFieldMap[entityName] = fields\n }\n\n return { entityNames, entityFieldMap }\n}\n\nfunction parseEntityFieldsFromFile(filePath: string, exportedClassNames: string[]): EntityFieldMap {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n\n const exported = new Set(exportedClassNames)\n const result: EntityFieldMap = {}\n\n function getDecoratorArgNameLiteral(dec: ts.Decorator | undefined): string | undefined {\n if (!dec) return undefined\n const expr = dec.expression\n if (!ts.isCallExpression(expr)) return undefined\n if (!expr.arguments.length) return undefined\n const first = expr.arguments[0]\n if (!ts.isObjectLiteralExpression(first)) return undefined\n for (const prop of first.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === 'name') {\n if (ts.isStringLiteral(prop.initializer)) return prop.initializer.text\n }\n }\n return undefined\n }\n\n function normalizeDbName(propertyName: string, _decoratorName?: string, nameOverride?: string): string {\n if (nameOverride) return nameOverride\n return toSnake(propertyName)\n }\n\n sf.forEachChild((node) => {\n if (!ts.isClassDeclaration(node) || !node.name) return\n const clsName = node.name.text\n if (!exported.has(clsName)) return\n const entityKey = toSnake(clsName)\n const fields: string[] = []\n\n for (const member of node.members) {\n if (!ts.isPropertyDeclaration(member) || !member.name) continue\n const name = ts.isIdentifier(member.name)\n ? member.name.text\n : ts.isStringLiteral(member.name)\n ? member.name.text\n : undefined\n if (!name) continue\n if (member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword)) continue\n const decorators = ts.canHaveDecorators(member)\n ? ts.getDecorators(member) ?? []\n : []\n let dbName: string | undefined\n if (decorators && decorators.length) {\n for (const d of decorators) {\n const nameOverride = getDecoratorArgNameLiteral(d)\n dbName = normalizeDbName(name, undefined, nameOverride)\n if (dbName) break\n }\n }\n if (!dbName) dbName = normalizeDbName(name)\n fields.push(dbName)\n }\n result[entityKey] = Array.from(new Set(fields))\n })\n\n return result\n}\n\nfunction writeTrackedFile(\n filePath: string,\n content: string,\n result: GeneratorResult,\n): void {\n if (writeIfChanged(filePath, content)) {\n result.filesWritten.push(filePath)\n } else {\n result.filesUnchanged.push(filePath)\n }\n}\n\nfunction writePerEntityFieldFiles(\n outRoot: string,\n fieldsByEntity: EntityFieldMap,\n result: GeneratorResult,\n): void {\n fs.mkdirSync(outRoot, { recursive: true })\n const desiredEntities = new Set(Object.keys(fieldsByEntity))\n for (const [entity, fields] of Object.entries(fieldsByEntity)) {\n const entDir = path.join(outRoot, entity)\n fs.mkdirSync(entDir, { recursive: true })\n const sourceFile = createGeneratedSourceFile(`${entity}/index.ts`)\n for (const field of fields) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: toVar(field),\n initializer: JSON.stringify(field),\n },\n ],\n })\n }\n writeTrackedFile(path.join(entDir, 'index.ts'), getSourceText(sourceFile), result)\n }\n\n const existingEntries = fs.existsSync(outRoot) ? fs.readdirSync(outRoot, { withFileTypes: true }) : []\n for (const entry of existingEntries) {\n if (!entry.isDirectory()) continue\n if (desiredEntities.has(entry.name)) continue\n const staleDirectory = path.join(outRoot, entry.name)\n rimrafDir(staleDirectory)\n result.filesWritten.push(staleDirectory)\n }\n}\n\nfunction writeEntityFieldsRegistry(\n generatedRoot: string,\n fieldsByEntity: EntityFieldMap,\n result: GeneratorResult,\n): void {\n const entities = Object.keys(fieldsByEntity).sort((a, b) => a.localeCompare(b))\n const registry: Record<string, Record<string, string>> = {}\n for (const entity of entities) {\n registry[toVar(entity)] = {}\n for (const field of fieldsByEntity[entity] ?? []) {\n registry[toVar(entity)][toVar(field)] = field\n }\n }\n\n const sourceFile = createGeneratedSourceFile('entity-fields-registry.ts')\n addAutoGeneratedComment(sourceFile, 'entity-ids')\n sourceFile.insertText(sourceFile.getFullText().length, '// Static registry for entity fields - eliminates dynamic imports for Turbopack compatibility\\n')\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'entityFieldsRegistry',\n type: 'Record<string, Record<string, string>>',\n initializer: JSON.stringify(registry, null, 2),\n },\n ],\n })\n sourceFile.addFunction({\n name: 'getEntityFields',\n isExported: true,\n parameters: [{ name: 'slug', type: 'string' }],\n returnType: 'Record<string, string> | undefined',\n statements: [returnStatement(elementAccess(identifier('entityFieldsRegistry'), identifier('slug')))],\n })\n const outPath = path.join(generatedRoot, 'entity-fields-registry.ts')\n writeTrackedFile(outPath, getSourceText(sourceFile), result)\n}\n\nexport async function generateEntityIds(options: EntityIdsOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.ids.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.ids.generated.checksum')\n\n const entries = resolver.loadEnabledModules()\n\n const consolidated: Record<string, Record<string, string>> = {}\n const grouped: Record<GroupKey, Record<string, Record<string, string>>> = {}\n const modulesDict: Record<string, string> = {}\n const groupedModulesDict: Record<GroupKey, Record<string, string>> = {}\n\n const fieldsByGroup: Record<GroupKey, Record<string, EntityFieldMap>> = {}\n\n for (const entry of entries) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imps = resolver.getModuleImportBase(entry)\n const group: GroupKey = (entry.from as GroupKey) || '@open-mercato/core'\n\n const standaloneGeneratedPackageEntities = loadStandaloneGeneratedPackageEntities(resolver, entry)\n\n // Locate entities definition file (prefer app override)\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override', 'entities', 'schema']\n let importPath: string | null = null\n let filePath: string | null = null\n\n for (const base of bases) {\n for (const f of candidates) {\n const p = resolveConventionFile(base, f)\n if (p) {\n const fromApp = base.startsWith(roots.appBase)\n const sub = path.basename(base) // 'data' | 'db'\n importPath = `${fromApp ? imps.appBase : imps.pkgBase}/${sub}/${f}`\n filePath = p\n break\n }\n }\n if (importPath) break\n }\n\n // No entities file found -> still register module id\n if (!filePath && !standaloneGeneratedPackageEntities) {\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n continue\n }\n\n const exportNames = filePath ? parseExportedClassNamesFromFile(filePath) : []\n\n const entityNames = standaloneGeneratedPackageEntities\n ? standaloneGeneratedPackageEntities.entityNames\n : exportNames\n .map((k) => toSnake(k))\n .filter((k, idx, arr) => arr.indexOf(k) === idx)\n\n // Build dictionaries\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n\n consolidated[modId] = consolidated[modId] || {}\n grouped[group] = grouped[group] || {}\n grouped[group][modId] = grouped[group][modId] || {}\n\n for (const en of entityNames) {\n consolidated[modId][en] = `${modId}:${en}`\n grouped[group][modId][en] = `${modId}:${en}`\n }\n\n // Parse entity fields from TypeScript source\n const entityFieldMap = standaloneGeneratedPackageEntities\n ? standaloneGeneratedPackageEntities.entityFieldMap\n : parseEntityFieldsFromFile(filePath!, exportNames)\n fieldsByGroup[group] = fieldsByGroup[group] || {}\n fieldsByGroup[group][modId] = entityFieldMap\n }\n\n // Write consolidated output\n const consolidatedSourceFile = createGeneratedSourceFile('entities.ids.generated.ts')\n addAutoGeneratedComment(consolidatedSourceFile, 'entity-ids')\n consolidatedSourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n { name: 'M', initializer: `${JSON.stringify(modulesDict, null, 2)} as const` },\n { name: 'E', initializer: `${JSON.stringify(consolidated, null, 2)} as const` },\n ],\n })\n consolidatedSourceFile.addTypeAlias({\n name: 'KnownModuleId',\n isExported: true,\n type: 'keyof typeof M',\n })\n consolidatedSourceFile.addTypeAlias({\n name: 'KnownEntities',\n isExported: true,\n type: 'typeof E',\n })\n const consolidatedSrc = getSourceText(consolidatedSourceFile)\n\n writeGeneratedFile({\n outFile,\n checksumFile,\n content: consolidatedSrc,\n structureChecksum: '',\n result,\n quiet,\n })\n\n // Write per-group outputs\n const groups = Object.keys(grouped) as GroupKey[]\n for (const g of groups) {\n if (!resolver.isMonorepo() && g !== '@app') {\n continue\n }\n\n const pkgOutputDir = resolver.getPackageOutputDir(g)\n // Skip @app group since it writes to the same location as the consolidated output\n if (g === '@app' && pkgOutputDir === outputDir) {\n continue\n }\n const out = path.join(pkgOutputDir, 'entities.ids.generated.ts')\n\n const groupSourceFile = createGeneratedSourceFile(`${String(g)}/entities.ids.generated.ts`)\n addAutoGeneratedComment(groupSourceFile, 'entity-ids')\n groupSourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n { name: 'M', initializer: `${JSON.stringify(groupedModulesDict[g] || {}, null, 2)} as const` },\n { name: 'E', initializer: `${JSON.stringify(grouped[g] || {}, null, 2)} as const` },\n ],\n })\n groupSourceFile.addTypeAlias({\n name: 'KnownModuleId',\n isExported: true,\n type: 'keyof typeof M',\n })\n groupSourceFile.addTypeAlias({\n name: 'KnownEntities',\n isExported: true,\n type: 'typeof E',\n })\n const src = getSourceText(groupSourceFile)\n writeTrackedFile(out, src, result)\n\n const fieldsRoot = path.join(pkgOutputDir, 'entities')\n const fieldsByModule = fieldsByGroup[g] || {}\n const combined: EntityFieldMap = {}\n for (const mId of Object.keys(fieldsByModule)) {\n const mMap = fieldsByModule[mId]\n for (const [entity, fields] of Object.entries(mMap)) {\n combined[entity] = Array.from(new Set([...(combined[entity] || []), ...fields]))\n }\n }\n writePerEntityFieldFiles(fieldsRoot, combined, result)\n\n // Generate static entity fields registry for Turbopack compatibility\n writeEntityFieldsRegistry(pkgOutputDir, combined, result)\n }\n\n // Write combined entity fields to root generated/ folder\n const combinedAll: EntityFieldMap = {}\n for (const groupFields of Object.values(fieldsByGroup)) {\n for (const mMap of Object.values(groupFields)) {\n for (const [entity, fields] of Object.entries(mMap)) {\n combinedAll[entity] = Array.from(new Set([...(combinedAll[entity] || []), ...fields]))\n }\n }\n }\n writePerEntityFieldFiles(path.join(outputDir, 'entities'), combinedAll, result)\n writeEntityFieldsRegistry(outputDir, combinedAll, result)\n\n return result\n}\n\nfunction resolveConventionFile(baseDir: string, basename: string): string | null {\n for (const extension of MODULE_CODE_EXTENSIONS) {\n const candidate = path.join(baseDir, `${basename}${extension}`)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n"],
5
+ "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,+BAA+B;AAExC,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB,2BAA2B,eAAe,eAAe,YAAY,uBAAuB;AAc9H,SAAS,gCAAgC,UAA4B;AACnE,QAAM,MAAM,GAAG,aAAa,UAAU,MAAM;AAC5C,QAAM,KAAK,GAAG,iBAAiB,UAAU,KAAK,GAAG,aAAa,QAAQ,MAAM,GAAG,WAAW,EAAE;AAC5F,QAAM,aAAuB,CAAC;AAE9B,KAAG,aAAa,CAAC,SAAS;AAExB,QAAI,GAAG,mBAAmB,IAAI,KAAK,KAAK,MAAM;AAC5C,YAAM,YAAY,KAAK,WAAW;AAAA,QAChC,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW;AAAA,MAClC;AACA,UAAI,WAAW;AACb,mBAAW,KAAK,KAAK,KAAK,IAAI;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,SAAS,8BACP,YACwC;AACxC,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI,GAAG,0BAA0B,UAAU,EAAG,QAAO;AACrD,MAAI,GAAG,eAAe,UAAU,KAAK,GAAG,0BAA0B,UAAU,GAAG;AAC7E,WAAO,8BAA8B,WAAW,UAAU;AAAA,EAC5D;AACA,MAAI,GAAG,0BAA0B,UAAU,GAAG;AAC5C,WAAO,8BAA8B,WAAW,UAAU;AAAA,EAC5D;AACA,SAAO;AACT;AAEA,SAAS,wBACP,eACA,cAC2B;AAC3B,aAAW,YAAY,cAAc,YAAY;AAC/C,QAAI,CAAC,GAAG,qBAAqB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0B,cAAc,UAAU,MAAM;AAAA,EAC1D;AAGA,QAAM,cAA8B,CAAC;AACrC,aAAW,eAAe,OAAO,OAAO,aAAa,GAAG;AACtD,eAAW,QAAQ,OAAO,OAAO,WAAW,GAAG;AAC7C,iBAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,QAAQ,IAAI,GAAG;AACnD,oBAAY,MAAM,IAAI,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAI,YAAY,MAAM,KAAK,CAAC,GAAI,GAAG,MAAM,CAAC,CAAC;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AACA,2BAAyB,KAAK,KAAK,WAAW,UAAU,GAAG,aAAa,MAAM;AAC9E,4BAA0B,WAAW,aAAa,MAAM;AAExD,SAAO;AACT;AAEA,SAAS,sBAAsB,SAAiB,UAAiC;AAC/E,aAAW,aAAa,wBAAwB;AAC9C,UAAM,YAAY,KAAK,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE;AAC9D,QAAI,GAAG,WAAW,SAAS,EAAG,QAAO;AAAA,EACvC;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -140,9 +140,23 @@ function resolveScannedWidgetPath(roots, fromApp, relPath) {
140
140
  const base = fromApp ? roots.appBase : resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase;
141
141
  return path.join(base, "widgets", "injection", ...relPath.split("/"));
142
142
  }
143
+ function reportUnresolvableWidgetReferences(widgetEntries, tableWidgetRefs) {
144
+ const declaredIds = /* @__PURE__ */ new Set();
145
+ for (const entry of widgetEntries.values()) {
146
+ if (entry.widgetId) declaredIds.add(entry.widgetId);
147
+ }
148
+ for (const [widgetId, modules] of Array.from(tableWidgetRefs.entries()).sort(([a], [b]) => a.localeCompare(b))) {
149
+ if (declaredIds.has(widgetId)) continue;
150
+ const owners = Array.from(modules).sort((left, right) => left.localeCompare(right)).join(", ");
151
+ console.warn(
152
+ `[generate] \u26A0 Injection table in "${owners}" references widget id "${widgetId}", but no scanned widget declares it \u2014 that spot will render nothing. Check the id against the widget's metadata.id, and that the widget lives in a file the scanner reads (widgets/injection/**/widget.ts|tsx \u2014 note that widget.client.tsx alone is not scanned).`
153
+ );
154
+ }
155
+ }
143
156
  function createInjectionWidgetsExtension() {
144
157
  const widgetEntries = /* @__PURE__ */ new Map();
145
158
  const tableEntries = [];
159
+ const tableWidgetRefs = /* @__PURE__ */ new Map();
146
160
  return {
147
161
  id: "registry.injection-widgets",
148
162
  outputFiles: ["injection-widgets.generated.ts", "injection-tables.generated.ts"],
@@ -171,6 +185,11 @@ function createInjectionWidgetsExtension() {
171
185
  if (moduleWidgetEntries.length === 1 && tableWidgetIds.length === 1 && !moduleWidgetEntries[0].widgetId) {
172
186
  moduleWidgetEntries[0].widgetId = tableWidgetIds[0];
173
187
  }
188
+ for (const widgetId of tableWidgetIds) {
189
+ const modules = tableWidgetRefs.get(widgetId) ?? /* @__PURE__ */ new Set();
190
+ modules.add(ctx.moduleId);
191
+ tableWidgetRefs.set(widgetId, modules);
192
+ }
174
193
  for (const entry of moduleWidgetEntries) {
175
194
  const existing = widgetEntries.get(entry.key);
176
195
  if (!existing || existing.source !== "app" && entry.source === "app") {
@@ -186,6 +205,7 @@ function createInjectionWidgetsExtension() {
186
205
  }
187
206
  },
188
207
  generateOutput() {
208
+ reportUnresolvableWidgetReferences(widgetEntries, tableWidgetRefs);
189
209
  const widgetDecls = Array.from(widgetEntries.entries()).sort(([left], [right]) => left.localeCompare(right)).map(
190
210
  ([, entry]) => objectLiteral([
191
211
  { name: "moduleId", value: entry.moduleId },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/generators/extensions/injection-widgets.ts"],
4
- "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport ts from 'typescript-js'\nimport type { GeneratorExtension } from '../extension'\nimport { resolveStandaloneSourceMirrorBase, scanModuleDir, SCAN_CONFIGS, type ModuleRoots } from '../scanner'\nimport {\n arrayLiteral,\n arrowFunction,\n identifier,\n methodCall,\n nullishCoalesce,\n objectLiteral,\n propertyAccess,\n writeValue,\n} from '../ast'\nimport { dynamicImportExpression, emptyObject, namespaceFallback, namespaceImportSpec, renderGeneratedTsSource } from './shared'\n\ntype InjectionWidgetEntry = {\n moduleId: string\n key: string\n source: 'app' | 'package'\n importPath: string\n widgetId?: string\n}\n\ntype InjectionTableEntry = {\n moduleId: string\n importName: string\n importPath: string\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression\n while (\n ts.isParenthesizedExpression(current)\n || ts.isAsExpression(current)\n || ts.isTypeAssertionExpression(current)\n || ts.isSatisfiesExpression(current)\n ) {\n current = current.expression\n }\n return current\n}\n\nfunction getPropertyNameText(name: ts.PropertyName): string | null {\n if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNoSubstitutionTemplateLiteral(name)) {\n return name.text\n }\n return null\n}\n\nfunction collectObjectDeclarations(sourceFile: ts.SourceFile): Map<string, ts.ObjectLiteralExpression> {\n const declarations = new Map<string, ts.ObjectLiteralExpression>()\n for (const statement of sourceFile.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n const initializer = unwrapExpression(declaration.initializer)\n if (ts.isObjectLiteralExpression(initializer)) {\n declarations.set(declaration.name.text, initializer)\n }\n }\n }\n return declarations\n}\n\nfunction resolveObjectExpression(\n expression: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n): ts.ObjectLiteralExpression | null {\n const unwrapped = unwrapExpression(expression)\n if (ts.isObjectLiteralExpression(unwrapped)) return unwrapped\n if (ts.isIdentifier(unwrapped)) return declarations.get(unwrapped.text) ?? null\n return null\n}\n\nfunction getObjectPropertyExpression(object: ts.ObjectLiteralExpression, propertyName: string): ts.Expression | null {\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n if (getPropertyNameText(property.name) === propertyName) return property.initializer\n }\n return null\n}\n\nfunction getStringPropertyValue(object: ts.ObjectLiteralExpression, propertyName: string): string | null {\n const expression = getObjectPropertyExpression(object, propertyName)\n if (!expression) return null\n const unwrapped = unwrapExpression(expression)\n if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) return unwrapped.text\n return null\n}\n\nfunction extractMetadataId(object: ts.ObjectLiteralExpression): string | null {\n const metadata = getObjectPropertyExpression(object, 'metadata')\n if (!metadata) return null\n const unwrapped = unwrapExpression(metadata)\n if (!ts.isObjectLiteralExpression(unwrapped)) return null\n return getStringPropertyValue(unwrapped, 'id')\n}\n\nfunction extractWidgetMetadataId(absolutePath: string): string | null {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n\n for (const statement of sourceFile.statements) {\n if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue\n const object = resolveObjectExpression(statement.expression, declarations)\n if (!object) continue\n const id = extractMetadataId(object)\n if (id) return id\n }\n\n for (const object of declarations.values()) {\n const id = extractMetadataId(object)\n if (id) return id\n }\n } catch {\n return null\n }\n return null\n}\n\nfunction collectWidgetIdsFromTableValue(\n value: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n ids: Set<string>,\n) {\n const expression = unwrapExpression(value)\n if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n ids.add(expression.text)\n return\n }\n if (ts.isArrayLiteralExpression(expression)) {\n for (const element of expression.elements) {\n if (ts.isExpression(element)) collectWidgetIdsFromTableValue(element, declarations, ids)\n }\n return\n }\n const object = resolveObjectExpression(expression, declarations)\n if (!object) return\n const widgetId = getStringPropertyValue(object, 'widgetId')\n if (widgetId) ids.add(widgetId)\n}\n\nfunction extractInjectionTableWidgetIds(absolutePath: string): string[] {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n let tableObject: ts.ObjectLiteralExpression | null = null\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'injectionTable' || !declaration.initializer) {\n continue\n }\n tableObject = resolveObjectExpression(declaration.initializer, declarations)\n }\n }\n if (ts.isExportAssignment(statement) && !statement.isExportEquals) {\n tableObject ??= resolveObjectExpression(statement.expression, declarations)\n }\n }\n\n if (!tableObject) return []\n const ids = new Set<string>()\n for (const property of tableObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n collectWidgetIdsFromTableValue(property.initializer, declarations, ids)\n }\n return Array.from(ids)\n } catch {\n return []\n }\n}\n\nfunction resolveScannedWidgetPath(roots: ModuleRoots, fromApp: boolean, relPath: string): string {\n const base = fromApp ? roots.appBase : (resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase)\n return path.join(base, 'widgets', 'injection', ...relPath.split('/'))\n}\n\nexport function createInjectionWidgetsExtension(): GeneratorExtension {\n const widgetEntries = new Map<string, InjectionWidgetEntry>()\n const tableEntries: InjectionTableEntry[] = []\n\n return {\n id: 'registry.injection-widgets',\n outputFiles: ['injection-widgets.generated.ts', 'injection-tables.generated.ts'],\n scanModule(ctx) {\n const files = scanModuleDir(ctx.roots, SCAN_CONFIGS.injectionWidgets)\n const moduleWidgetEntries: InjectionWidgetEntry[] = []\n for (const { relPath, fromApp } of files) {\n const segments = relPath.split('/')\n const file = segments.pop() ?? ''\n const base = file.replace(/\\.(t|j)sx?$/, '')\n const importPath = ctx.sanitizeGeneratedModuleSpecifier(\n `${fromApp ? ctx.imps.appBase : ctx.imps.pkgBase}/widgets/injection/${[...segments, base].join('/')}`\n )\n const key = [ctx.moduleId, ...segments, base].filter(Boolean).join(':')\n const entry: InjectionWidgetEntry = {\n moduleId: ctx.moduleId,\n key,\n source: fromApp ? 'app' : 'package',\n importPath,\n widgetId: extractWidgetMetadataId(resolveScannedWidgetPath(ctx.roots, fromApp, relPath)) ?? undefined,\n }\n moduleWidgetEntries.push(entry)\n }\n\n const table = ctx.resolveModuleFile(ctx.roots, ctx.imps, 'widgets/injection-table.ts')\n const tableWidgetIds = table ? extractInjectionTableWidgetIds(table.absolutePath) : []\n if (moduleWidgetEntries.length === 1 && tableWidgetIds.length === 1 && !moduleWidgetEntries[0].widgetId) {\n moduleWidgetEntries[0].widgetId = tableWidgetIds[0]\n }\n\n for (const entry of moduleWidgetEntries) {\n const existing = widgetEntries.get(entry.key)\n if (!existing || (existing.source !== 'app' && entry.source === 'app')) {\n widgetEntries.set(entry.key, entry)\n }\n }\n\n if (table) {\n tableEntries.push({\n moduleId: ctx.moduleId,\n importName: `InjTable_${ctx.moduleId.replace(/[^a-zA-Z0-9_]/g, '_')}_${ctx.importIdRef.value++}`,\n importPath: ctx.sanitizeGeneratedModuleSpecifier(table.importPath),\n })\n }\n },\n generateOutput() {\n const widgetDecls = Array.from(widgetEntries.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([, entry]) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n { name: 'key', value: entry.key },\n { name: 'source', value: entry.source },\n ...(entry.widgetId ? [{ name: 'widgetId', value: entry.widgetId }] : []),\n {\n name: 'loader',\n value: arrowFunction({\n body: methodCall(dynamicImportExpression(entry.importPath), 'then', [\n arrowFunction({\n parameters: ['mod'],\n body: nullishCoalesce([\n propertyAccess(identifier('mod'), 'default'),\n identifier('mod'),\n ]),\n }),\n ]),\n }),\n },\n ]),\n )\n\n const widgetsOutput = renderGeneratedTsSource({\n fileName: 'injection-widgets.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionWidgetEntry', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/registry' },\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionWidgetEntries',\n type: 'ModuleInjectionWidgetEntry[]',\n initializer: arrayLiteral(widgetDecls, writeValue),\n },\n ],\n })\n },\n })\n\n const tableImports = tableEntries.map((entry) => namespaceImportSpec(entry.importName, entry.importPath))\n const tableDecls = tableEntries.map((entry) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n {\n name: 'table',\n value: namespaceFallback({\n importName: entry.importName,\n members: ['default', 'injectionTable'],\n fallback: emptyObject(),\n castType: 'ModuleInjectionTable',\n }),\n },\n ]),\n )\n const tablesOutput = renderGeneratedTsSource({\n fileName: 'injection-tables.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionTable', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/widgets/injection' },\n ...tableImports,\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionTables',\n type: 'Array<{ moduleId: string; table: ModuleInjectionTable }>',\n initializer: arrayLiteral(tableDecls, writeValue),\n },\n ],\n })\n },\n })\n\n return new Map([\n ['injection-widgets.generated.ts', widgetsOutput],\n ['injection-tables.generated.ts', tablesOutput],\n ])\n },\n }\n}\n"],
5
- "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,+BAA+B;AACxC,OAAO,QAAQ;AAEf,SAAS,mCAAmC,eAAe,oBAAsC;AACjG;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB,aAAa,mBAAmB,qBAAqB,+BAA+B;AAgBtH,SAAS,iBAAiB,YAA0C;AAClE,MAAI,UAAU;AACd,SACE,GAAG,0BAA0B,OAAO,KACjC,GAAG,eAAe,OAAO,KACzB,GAAG,0BAA0B,OAAO,KACp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AA,EACF;AACF;",
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport ts from 'typescript-js'\nimport type { GeneratorExtension } from '../extension'\nimport { resolveStandaloneSourceMirrorBase, scanModuleDir, SCAN_CONFIGS, type ModuleRoots } from '../scanner'\nimport {\n arrayLiteral,\n arrowFunction,\n identifier,\n methodCall,\n nullishCoalesce,\n objectLiteral,\n propertyAccess,\n writeValue,\n} from '../ast'\nimport { dynamicImportExpression, emptyObject, namespaceFallback, namespaceImportSpec, renderGeneratedTsSource } from './shared'\n\ntype InjectionWidgetEntry = {\n moduleId: string\n key: string\n source: 'app' | 'package'\n importPath: string\n widgetId?: string\n}\n\ntype InjectionTableEntry = {\n moduleId: string\n importName: string\n importPath: string\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression\n while (\n ts.isParenthesizedExpression(current)\n || ts.isAsExpression(current)\n || ts.isTypeAssertionExpression(current)\n || ts.isSatisfiesExpression(current)\n ) {\n current = current.expression\n }\n return current\n}\n\nfunction getPropertyNameText(name: ts.PropertyName): string | null {\n if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNoSubstitutionTemplateLiteral(name)) {\n return name.text\n }\n return null\n}\n\nfunction collectObjectDeclarations(sourceFile: ts.SourceFile): Map<string, ts.ObjectLiteralExpression> {\n const declarations = new Map<string, ts.ObjectLiteralExpression>()\n for (const statement of sourceFile.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n const initializer = unwrapExpression(declaration.initializer)\n if (ts.isObjectLiteralExpression(initializer)) {\n declarations.set(declaration.name.text, initializer)\n }\n }\n }\n return declarations\n}\n\nfunction resolveObjectExpression(\n expression: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n): ts.ObjectLiteralExpression | null {\n const unwrapped = unwrapExpression(expression)\n if (ts.isObjectLiteralExpression(unwrapped)) return unwrapped\n if (ts.isIdentifier(unwrapped)) return declarations.get(unwrapped.text) ?? null\n return null\n}\n\nfunction getObjectPropertyExpression(object: ts.ObjectLiteralExpression, propertyName: string): ts.Expression | null {\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n if (getPropertyNameText(property.name) === propertyName) return property.initializer\n }\n return null\n}\n\nfunction getStringPropertyValue(object: ts.ObjectLiteralExpression, propertyName: string): string | null {\n const expression = getObjectPropertyExpression(object, propertyName)\n if (!expression) return null\n const unwrapped = unwrapExpression(expression)\n if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) return unwrapped.text\n return null\n}\n\nfunction extractMetadataId(object: ts.ObjectLiteralExpression): string | null {\n const metadata = getObjectPropertyExpression(object, 'metadata')\n if (!metadata) return null\n const unwrapped = unwrapExpression(metadata)\n if (!ts.isObjectLiteralExpression(unwrapped)) return null\n return getStringPropertyValue(unwrapped, 'id')\n}\n\nfunction extractWidgetMetadataId(absolutePath: string): string | null {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n\n for (const statement of sourceFile.statements) {\n if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue\n const object = resolveObjectExpression(statement.expression, declarations)\n if (!object) continue\n const id = extractMetadataId(object)\n if (id) return id\n }\n\n for (const object of declarations.values()) {\n const id = extractMetadataId(object)\n if (id) return id\n }\n } catch {\n return null\n }\n return null\n}\n\nfunction collectWidgetIdsFromTableValue(\n value: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n ids: Set<string>,\n) {\n const expression = unwrapExpression(value)\n if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n ids.add(expression.text)\n return\n }\n if (ts.isArrayLiteralExpression(expression)) {\n for (const element of expression.elements) {\n if (ts.isExpression(element)) collectWidgetIdsFromTableValue(element, declarations, ids)\n }\n return\n }\n const object = resolveObjectExpression(expression, declarations)\n if (!object) return\n const widgetId = getStringPropertyValue(object, 'widgetId')\n if (widgetId) ids.add(widgetId)\n}\n\nfunction extractInjectionTableWidgetIds(absolutePath: string): string[] {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n let tableObject: ts.ObjectLiteralExpression | null = null\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'injectionTable' || !declaration.initializer) {\n continue\n }\n tableObject = resolveObjectExpression(declaration.initializer, declarations)\n }\n }\n if (ts.isExportAssignment(statement) && !statement.isExportEquals) {\n tableObject ??= resolveObjectExpression(statement.expression, declarations)\n }\n }\n\n if (!tableObject) return []\n const ids = new Set<string>()\n for (const property of tableObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n collectWidgetIdsFromTableValue(property.initializer, declarations, ids)\n }\n return Array.from(ids)\n } catch {\n return []\n }\n}\n\nfunction resolveScannedWidgetPath(roots: ModuleRoots, fromApp: boolean, relPath: string): string {\n const base = fromApp ? roots.appBase : (resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase)\n return path.join(base, 'widgets', 'injection', ...relPath.split('/'))\n}\n\n/**\n * A widget's `metadata.id` and the injection-table entry that mounts it are two hand-typed string\n * literals in two different files, and nothing links them. A typo in either fails silently: the spot\n * resolves to no widget and nothing is logged, so it only surfaces as \"why isn't my widget\n * rendering\" during manual QA.\n *\n * Reports table entries whose `widgetId` no scanned widget declares. Diagnostics only \u2014 generated\n * output is unchanged and the build is not failed, since a table entry may legitimately point at a\n * widget supplied by a module that is not enabled in this app.\n *\n * Deliberately one-directional. The mirror check (\"a widget nothing references is never mounted\")\n * cannot be done reliably yet: `extractInjectionTableWidgetIds` only reads statically-analyzable\n * object literals, so a table assembled by composition or computation contributes **no** visible\n * ids \u2014 `example` exports `cond ? { ...a, ...b } : a` and `translations` exports\n * `buildInjectionTable()`, and both would have every one of their widgets reported as unreferenced.\n * Under-reporting is harmless in the direction implemented here (a reference the extractor never saw\n * cannot produce a warning) but fatal in the other. Teaching the extractor to resolve spreads,\n * conditionals and call expressions is the prerequisite for adding it.\n */\nfunction reportUnresolvableWidgetReferences(\n widgetEntries: Map<string, InjectionWidgetEntry>,\n tableWidgetRefs: Map<string, Set<string>>,\n): void {\n const declaredIds = new Set<string>()\n for (const entry of widgetEntries.values()) {\n if (entry.widgetId) declaredIds.add(entry.widgetId)\n }\n\n for (const [widgetId, modules] of Array.from(tableWidgetRefs.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n if (declaredIds.has(widgetId)) continue\n const owners = Array.from(modules).sort((left, right) => left.localeCompare(right)).join(', ')\n console.warn(\n `[generate] \u26A0 Injection table in \"${owners}\" references widget id \"${widgetId}\", but no scanned ` +\n 'widget declares it \u2014 that spot will render nothing. Check the id against the widget\\'s ' +\n 'metadata.id, and that the widget lives in a file the scanner reads ' +\n '(widgets/injection/**/widget.ts|tsx \u2014 note that widget.client.tsx alone is not scanned).',\n )\n }\n}\n\nexport function createInjectionWidgetsExtension(): GeneratorExtension {\n const widgetEntries = new Map<string, InjectionWidgetEntry>()\n const tableEntries: InjectionTableEntry[] = []\n // widgetId -> module ids whose injection table references it. Collected across every module so a\n // table may legitimately reference a widget another module owns.\n const tableWidgetRefs = new Map<string, Set<string>>()\n\n return {\n id: 'registry.injection-widgets',\n outputFiles: ['injection-widgets.generated.ts', 'injection-tables.generated.ts'],\n scanModule(ctx) {\n const files = scanModuleDir(ctx.roots, SCAN_CONFIGS.injectionWidgets)\n const moduleWidgetEntries: InjectionWidgetEntry[] = []\n for (const { relPath, fromApp } of files) {\n const segments = relPath.split('/')\n const file = segments.pop() ?? ''\n const base = file.replace(/\\.(t|j)sx?$/, '')\n const importPath = ctx.sanitizeGeneratedModuleSpecifier(\n `${fromApp ? ctx.imps.appBase : ctx.imps.pkgBase}/widgets/injection/${[...segments, base].join('/')}`\n )\n const key = [ctx.moduleId, ...segments, base].filter(Boolean).join(':')\n const entry: InjectionWidgetEntry = {\n moduleId: ctx.moduleId,\n key,\n source: fromApp ? 'app' : 'package',\n importPath,\n widgetId: extractWidgetMetadataId(resolveScannedWidgetPath(ctx.roots, fromApp, relPath)) ?? undefined,\n }\n moduleWidgetEntries.push(entry)\n }\n\n const table = ctx.resolveModuleFile(ctx.roots, ctx.imps, 'widgets/injection-table.ts')\n const tableWidgetIds = table ? extractInjectionTableWidgetIds(table.absolutePath) : []\n if (moduleWidgetEntries.length === 1 && tableWidgetIds.length === 1 && !moduleWidgetEntries[0].widgetId) {\n moduleWidgetEntries[0].widgetId = tableWidgetIds[0]\n }\n\n for (const widgetId of tableWidgetIds) {\n const modules = tableWidgetRefs.get(widgetId) ?? new Set<string>()\n modules.add(ctx.moduleId)\n tableWidgetRefs.set(widgetId, modules)\n }\n\n for (const entry of moduleWidgetEntries) {\n const existing = widgetEntries.get(entry.key)\n if (!existing || (existing.source !== 'app' && entry.source === 'app')) {\n widgetEntries.set(entry.key, entry)\n }\n }\n\n if (table) {\n tableEntries.push({\n moduleId: ctx.moduleId,\n importName: `InjTable_${ctx.moduleId.replace(/[^a-zA-Z0-9_]/g, '_')}_${ctx.importIdRef.value++}`,\n importPath: ctx.sanitizeGeneratedModuleSpecifier(table.importPath),\n })\n }\n },\n generateOutput() {\n reportUnresolvableWidgetReferences(widgetEntries, tableWidgetRefs)\n\n const widgetDecls = Array.from(widgetEntries.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([, entry]) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n { name: 'key', value: entry.key },\n { name: 'source', value: entry.source },\n ...(entry.widgetId ? [{ name: 'widgetId', value: entry.widgetId }] : []),\n {\n name: 'loader',\n value: arrowFunction({\n body: methodCall(dynamicImportExpression(entry.importPath), 'then', [\n arrowFunction({\n parameters: ['mod'],\n body: nullishCoalesce([\n propertyAccess(identifier('mod'), 'default'),\n identifier('mod'),\n ]),\n }),\n ]),\n }),\n },\n ]),\n )\n\n const widgetsOutput = renderGeneratedTsSource({\n fileName: 'injection-widgets.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionWidgetEntry', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/registry' },\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionWidgetEntries',\n type: 'ModuleInjectionWidgetEntry[]',\n initializer: arrayLiteral(widgetDecls, writeValue),\n },\n ],\n })\n },\n })\n\n const tableImports = tableEntries.map((entry) => namespaceImportSpec(entry.importName, entry.importPath))\n const tableDecls = tableEntries.map((entry) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n {\n name: 'table',\n value: namespaceFallback({\n importName: entry.importName,\n members: ['default', 'injectionTable'],\n fallback: emptyObject(),\n castType: 'ModuleInjectionTable',\n }),\n },\n ]),\n )\n const tablesOutput = renderGeneratedTsSource({\n fileName: 'injection-tables.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionTable', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/widgets/injection' },\n ...tableImports,\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionTables',\n type: 'Array<{ moduleId: string; table: ModuleInjectionTable }>',\n initializer: arrayLiteral(tableDecls, writeValue),\n },\n ],\n })\n },\n })\n\n return new Map([\n ['injection-widgets.generated.ts', widgetsOutput],\n ['injection-tables.generated.ts', tablesOutput],\n ])\n },\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,+BAA+B;AACxC,OAAO,QAAQ;A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BACE,MAAM;AAAA,gBACN,MAAM;AAAA,gBACN,aAAa,aAAa,aAAa,UAAU;AAAA,cACnD;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAED,YAAM,eAAe,aAAa,IAAI,CAAC,UAAU,oBAAoB,MAAM,YAAY,MAAM,UAAU,CAAC;AACxG,YAAM,aAAa,aAAa;AAAA,QAAI,CAAC,UACnC,cAAc;AAAA,UACZ,EAAE,MAAM,YAAY,OAAO,MAAM,SAAS;AAAA,UAC1C;AAAA,YACE,MAAM;AAAA,YACN,OAAO,kBAAkB;AAAA,cACvB,YAAY,MAAM;AAAA,cAClB,SAAS,CAAC,WAAW,gBAAgB;AAAA,cACrC,UAAU,YAAY;AAAA,cACtB,UAAU;AAAA,YACZ,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AACA,YAAM,eAAe,wBAAwB;AAAA,QAC3C,UAAU;AAAA,QACV,SAAS;AAAA,UACP,EAAE,cAAc,CAAC,EAAE,MAAM,wBAAwB,YAAY,KAAK,CAAC,GAAG,iBAAiB,iDAAiD;AAAA,UACxI,GAAG;AAAA,QACL;AAAA,QACA,MAAM,YAAY;AAChB,qBAAW,qBAAqB;AAAA,YAC9B,iBAAiB,wBAAwB;AAAA,YACzC,YAAY;AAAA,YACZ,cAAc;AAAA,cACZ;AAAA,gBACE,MAAM;AAAA,gBACN,MAAM;AAAA,gBACN,aAAa,aAAa,YAAY,UAAU;AAAA,cAClD;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAED,aAAO,oBAAI,IAAI;AAAA,QACb,CAAC,kCAAkC,aAAa;AAAA,QAChD,CAAC,iCAAiC,YAAY;AAAA,MAChD,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -3,13 +3,9 @@ import path from "node:path";
3
3
  import { StructureKind, VariableDeclarationKind } from "ts-morph";
4
4
  import { MODULE_CODE_EXTENSIONS } from "./scanner.js";
5
5
  import {
6
- calculateChecksum,
7
- readChecksumRecord,
8
- writeChecksumRecord,
9
- ensureDir,
10
6
  toVar,
11
- logGenerationResult,
12
- createGeneratorResult
7
+ createGeneratorResult,
8
+ writeGeneratedFile
13
9
  } from "../utils.js";
14
10
  import {
15
11
  addAutoGeneratedComment,
@@ -79,23 +75,14 @@ async function generateModuleDi(options) {
79
75
  expression: "diRegistrars"
80
76
  });
81
77
  const output = getSourceText(sourceFile);
82
- const newChecksum = calculateChecksum(output);
83
- let shouldWrite = true;
84
- const existingRecord = readChecksumRecord(checksumFile);
85
- if (existingRecord && existingRecord.content === newChecksum) {
86
- shouldWrite = false;
87
- }
88
- if (shouldWrite) {
89
- ensureDir(outFile);
90
- fs.writeFileSync(outFile, output);
91
- writeChecksumRecord(checksumFile, { content: newChecksum, structure: "" });
92
- result.filesWritten.push(outFile);
93
- if (!quiet) {
94
- logGenerationResult(path.relative(process.cwd(), outFile), true);
95
- }
96
- } else {
97
- result.filesUnchanged.push(outFile);
98
- }
78
+ writeGeneratedFile({
79
+ outFile,
80
+ checksumFile,
81
+ content: output,
82
+ structureChecksum: "",
83
+ result,
84
+ quiet
85
+ });
99
86
  return result;
100
87
  }
101
88
  function resolveModuleConventionFile(baseDir, basename) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/generators/module-di.ts"],
4
- "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS } from './scanner'\nimport {\n calculateChecksum,\n readChecksumRecord,\n writeChecksumRecord,\n ensureDir,\n toVar,\n logGenerationResult,\n type GeneratorResult,\n createGeneratorResult,\n} from '../utils'\nimport {\n addAutoGeneratedComment,\n addImportSpec,\n arrayLiteral,\n createGeneratedSourceFile,\n getSourceText,\n identifier,\n methodCall,\n parenthesized,\n} from './ast'\n\nexport interface ModuleDiOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\nexport async function generateModuleDi(options: ModuleDiOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'di.generated.ts')\n const checksumFile = path.join(outputDir, 'di.generated.checksum')\n\n const mods = resolver.loadEnabledModules()\n const imports: Array<{ name: string; moduleSpecifier: string }> = []\n const registrars: string[] = []\n let i = 0\n\n for (const entry of mods) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imp = resolver.getModuleImportBase(entry)\n const isAppModule = entry.from === '@app'\n\n const useApp = resolveModuleConventionFile(roots.appBase, 'di')\n const usePkg = resolveModuleConventionFile(roots.pkgBase, 'di')\n const importName = `D_${toVar(modId)}_${i++}`\n\n if (useApp) {\n // For @app modules, use relative path to work in both Next.js and Node.js CLI context\n // From .mercato/generated/, go up two levels (../..) to reach the app root, then into src/modules/\n const importPath = isAppModule ? `../../src/modules/${modId}/di` : `${imp.appBase}/di`\n imports.push({ name: importName, moduleSpecifier: importPath })\n registrars.push(`${importName}.register`)\n } else if (usePkg) {\n imports.push({ name: importName, moduleSpecifier: `${imp.pkgBase}/di` })\n registrars.push(`${importName}.register`)\n }\n }\n\n const sourceFile = createGeneratedSourceFile('di.generated.ts')\n addAutoGeneratedComment(sourceFile, 'di')\n imports.forEach((entry) => {\n addImportSpec(sourceFile, {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: entry.name,\n moduleSpecifier: entry.moduleSpecifier,\n })\n })\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'diRegistrars',\n type: '(((c: any) => void) | undefined)[]',\n initializer: methodCall(\n parenthesized(arrayLiteral(registrars, (currentWriter, registrar) => identifier(registrar)(currentWriter))),\n 'filter',\n [identifier('Boolean')],\n ),\n },\n ],\n })\n sourceFile.addExportDeclaration({\n namedExports: ['diRegistrars'],\n })\n sourceFile.addExportAssignment({\n isExportEquals: false,\n expression: 'diRegistrars',\n })\n const output = getSourceText(sourceFile)\n\n // Check if content has changed\n const newChecksum = calculateChecksum(output)\n let shouldWrite = true\n\n const existingRecord = readChecksumRecord(checksumFile)\n if (existingRecord && existingRecord.content === newChecksum) {\n shouldWrite = false\n }\n\n if (shouldWrite) {\n ensureDir(outFile)\n fs.writeFileSync(outFile, output)\n writeChecksumRecord(checksumFile, { content: newChecksum, structure: '' })\n result.filesWritten.push(outFile)\n if (!quiet) {\n logGenerationResult(path.relative(process.cwd(), outFile), true)\n }\n } else {\n result.filesUnchanged.push(outFile)\n }\n\n return result\n}\n\nfunction resolveModuleConventionFile(baseDir: string, basename: string): boolean {\n return MODULE_CODE_EXTENSIONS.some((extension) => fs.existsSync(path.join(baseDir, `${basename}${extension}`)))\n}\n"],
5
- "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,eAAe,+BAA+B;AAEvD,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,eAAsB,iBAAiB,SAAoD;AACzF,QAAM,EAAE,UAAU,QAAQ,MAAM,IAAI;AACpC,QAAM,SAAS,sBAAsB;AAErC,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,UAAU,KAAK,KAAK,WAAW,iBAAiB;AACtD,QAAM,eAAe,KAAK,KAAK,WAAW,uBAAuB;AAEjE,QAAM,OAAO,SAAS,mBAAmB;AACzC,QAAM,UAA4D,CAAC;AACnE,QAAM,aAAuB,CAAC;AAC9B,MAAI,IAAI;AAER,aAAW,SAAS,MAAM;AACxB,UAAM,QAAQ,MAAM;AACpB,UAAM,QAAQ,SAAS,eAAe,KAAK;AAC3C,UAAM,MAAM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QAAM,SAAS,cAAc,UAAU;AAGvC,QAAM,cAAc,kBAAkB,MAAM;AAC5C,MAAI,cAAc;AAElB,QAAM,iBAAiB,mBAAmB,YAAY;AACtD,MAAI,kBAAkB,eAAe,YAAY,aAAa;AAC5D,kBAAc;AAAA,EAChB;AAEA,MAAI,aAAa;AACf,cAAU,OAAO;AACjB,OAAG,cAAc,SAAS,MAAM;AAChC,wBAAoB,cAAc,EAAE,SAAS,aAAa,WAAW,GAAG,CAAC;AACzE,WAAO,aAAa,KAAK,OAAO;AAChC,QAAI,CAAC,OAAO;AACV,0BAAoB,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,GAAG,IAAI;AAAA,IACjE;AAAA,EACF,OAAO;AACL,WAAO,eAAe,KAAK,OAAO;AAAA,EACpC;AAEA,SAAO;AACT;AAEA,SAAS,4BAA4B,SAAiB,UAA2B;AAC/E,SAAO,uBAAuB,KAAK,CAAC,cAAc,GAAG,WAAW,KAAK,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE,CAAC,CAAC;AAChH;",
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS } from './scanner'\nimport {\n toVar,\n type GeneratorResult,\n createGeneratorResult,\n writeGeneratedFile,\n} from '../utils'\nimport {\n addAutoGeneratedComment,\n addImportSpec,\n arrayLiteral,\n createGeneratedSourceFile,\n getSourceText,\n identifier,\n methodCall,\n parenthesized,\n} from './ast'\n\nexport interface ModuleDiOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\nexport async function generateModuleDi(options: ModuleDiOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'di.generated.ts')\n const checksumFile = path.join(outputDir, 'di.generated.checksum')\n\n const mods = resolver.loadEnabledModules()\n const imports: Array<{ name: string; moduleSpecifier: string }> = []\n const registrars: string[] = []\n let i = 0\n\n for (const entry of mods) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imp = resolver.getModuleImportBase(entry)\n const isAppModule = entry.from === '@app'\n\n const useApp = resolveModuleConventionFile(roots.appBase, 'di')\n const usePkg = resolveModuleConventionFile(roots.pkgBase, 'di')\n const importName = `D_${toVar(modId)}_${i++}`\n\n if (useApp) {\n // For @app modules, use relative path to work in both Next.js and Node.js CLI context\n // From .mercato/generated/, go up two levels (../..) to reach the app root, then into src/modules/\n const importPath = isAppModule ? `../../src/modules/${modId}/di` : `${imp.appBase}/di`\n imports.push({ name: importName, moduleSpecifier: importPath })\n registrars.push(`${importName}.register`)\n } else if (usePkg) {\n imports.push({ name: importName, moduleSpecifier: `${imp.pkgBase}/di` })\n registrars.push(`${importName}.register`)\n }\n }\n\n const sourceFile = createGeneratedSourceFile('di.generated.ts')\n addAutoGeneratedComment(sourceFile, 'di')\n imports.forEach((entry) => {\n addImportSpec(sourceFile, {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: entry.name,\n moduleSpecifier: entry.moduleSpecifier,\n })\n })\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'diRegistrars',\n type: '(((c: any) => void) | undefined)[]',\n initializer: methodCall(\n parenthesized(arrayLiteral(registrars, (currentWriter, registrar) => identifier(registrar)(currentWriter))),\n 'filter',\n [identifier('Boolean')],\n ),\n },\n ],\n })\n sourceFile.addExportDeclaration({\n namedExports: ['diRegistrars'],\n })\n sourceFile.addExportAssignment({\n isExportEquals: false,\n expression: 'diRegistrars',\n })\n const output = getSourceText(sourceFile)\n\n writeGeneratedFile({\n outFile,\n checksumFile,\n content: output,\n structureChecksum: '',\n result,\n quiet,\n })\n\n return result\n}\n\nfunction resolveModuleConventionFile(baseDir: string, basename: string): boolean {\n return MODULE_CODE_EXTENSIONS.some((extension) => fs.existsSync(path.join(baseDir, `${basename}${ext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;AAEA,QAAM,aAAa,0BAA0B,iBAAiB;AAC9D,0BAAwB,YAAY,IAAI;AACxC,UAAQ,QAAQ,CAAC,UAAU;AACzB,kBAAc,YAAY;AAAA,MACxB,MAAM,cAAc;AAAA,MACpB,iBAAiB,MAAM;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB,CAAC;AAAA,EACH,CAAC;AACD,aAAW,qBAAqB;AAAA,IAC9B,iBAAiB,wBAAwB;AAAA,IACzC,cAAc;AAAA,MACZ;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,aAAa;AAAA,UACX,cAAc,aAAa,YAAY,CAAC,eAAe,cAAc,WAAW,SAAS,EAAE,aAAa,CAAC,CAAC;AAAA,UAC1G;AAAA,UACA,CAAC,WAAW,SAAS,CAAC;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACD,aAAW,qBAAqB;AAAA,IAC9B,cAAc,CAAC,cAAc;AAAA,EAC/B,CAAC;AACD,aAAW,oBAAoB;AAAA,IAC7B,gBAAgB;AAAA,IAChB,YAAY;AAAA,EACd,CAAC;AACD,QAAM,SAAS,cAAc,UAAU;AAEvC,qBAAmB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,SAAS,4BAA4B,SAAiB,UAA2B;AAC/E,SAAO,uBAAuB,KAAK,CAAC,cAAc,GAAG,WAAW,KAAK,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE,CAAC,CAAC;AAChH;",
6
6
  "names": []
7
7
  }
@@ -3,13 +3,9 @@ import path from "node:path";
3
3
  import { StructureKind, VariableDeclarationKind } from "ts-morph";
4
4
  import { MODULE_CODE_EXTENSIONS, stripModuleCodeExtension } from "./scanner.js";
5
5
  import {
6
- calculateChecksum,
7
- readChecksumRecord,
8
- writeChecksumRecord,
9
- ensureDir,
10
6
  toVar,
11
- logGenerationResult,
12
- createGeneratorResult
7
+ createGeneratorResult,
8
+ writeGeneratedFile
13
9
  } from "../utils.js";
14
10
  import {
15
11
  addAutoGeneratedComment,
@@ -185,23 +181,14 @@ async function generateModuleEntities(options) {
185
181
  ]
186
182
  });
187
183
  const output = getSourceText(sourceFile);
188
- const newChecksum = calculateChecksum(output);
189
- let shouldWrite = true;
190
- const existingRecord = readChecksumRecord(checksumFile);
191
- if (existingRecord && existingRecord.content === newChecksum) {
192
- shouldWrite = false;
193
- }
194
- if (shouldWrite) {
195
- ensureDir(outFile);
196
- fs.writeFileSync(outFile, output);
197
- writeChecksumRecord(checksumFile, { content: newChecksum, structure: "" });
198
- result.filesWritten.push(outFile);
199
- if (!quiet) {
200
- logGenerationResult(path.relative(process.cwd(), outFile), true);
201
- }
202
- } else {
203
- result.filesUnchanged.push(outFile);
204
- }
184
+ writeGeneratedFile({
185
+ outFile,
186
+ checksumFile,
187
+ content: output,
188
+ structureChecksum: "",
189
+ result,
190
+ quiet
191
+ });
205
192
  return result;
206
193
  }
207
194
  function resolveConventionFile(baseDir, basename) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/generators/module-entities.ts"],
4
- "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS, stripModuleCodeExtension } from './scanner'\nimport {\n calculateChecksum,\n readChecksumRecord,\n writeChecksumRecord,\n ensureDir,\n toVar,\n logGenerationResult,\n type GeneratorResult,\n createGeneratorResult,\n} from '../utils'\nimport {\n addAutoGeneratedComment,\n addImportSpec,\n asExpression,\n arrayLiteral,\n arrowFunction,\n binaryExpression,\n callExpression,\n createGeneratedSourceFile,\n expressionStatement,\n getSourceText,\n identifier,\n ifStatement,\n logicalAnd,\n methodCall,\n objectEntries,\n objectLiteral,\n prefixExpression,\n propertyAccess,\n returnStatement,\n spreadExpression,\n templateLiteral,\n variableStatement,\n} from './ast'\n\nexport interface ModuleEntitiesOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\nexport async function generateModuleEntities(options: ModuleEntitiesOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.generated.checksum')\n\n const mods = resolver.loadEnabledModules()\n const imports: Array<{ name: string; moduleSpecifier: string }> = []\n const entitySources: Array<{ importName: string; moduleId: string }> = []\n let n = 0\n\n for (const entry of mods) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imp = resolver.getModuleImportBase(entry)\n const isAppModule = entry.from === '@app'\n\n // prefer app override data/, fallback to core data/, then legacy db/\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override', 'entities', 'schema']\n\n let found: { base: string; file: string } | null = null\n for (const base of bases) {\n for (const f of candidates) {\n const p = resolveConventionFile(base, f)\n if (p) {\n found = { base, file: path.basename(p) }\n break\n }\n }\n if (found) break\n }\n if (!found) continue\n\n const importName = `E_${toVar(modId)}_${n++}`\n const sub = path.basename(found.base) // 'data' or 'db'\n const fromApp = found.base.startsWith(roots.appBase)\n // For @app modules, use relative path to ensure it works both in Next.js and Node.js CLI context\n // From .mercato/generated/, the relative path to src/modules/ is ../src/modules/\n let relImport: string\n if (isAppModule && fromApp) {\n // From .mercato/generated/, go up two levels (../..) to reach the app root, then into src/modules/\n relImport = `../../src/modules/${modId}/${sub}/${stripModuleCodeExtension(found.file)}`\n } else {\n const baseImport = fromApp ? imp.appBase : imp.pkgBase\n relImport = `${baseImport}/${sub}/${stripModuleCodeExtension(found.file)}`\n }\n imports.push({ name: importName, moduleSpecifier: relImport })\n entitySources.push({ importName, moduleId: modId })\n }\n\n const sourceFile = createGeneratedSourceFile('entities.generated.ts')\n addAutoGeneratedComment(sourceFile, 'entities')\n imports.forEach((entry) => {\n addImportSpec(sourceFile, {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: entry.name,\n moduleSpecifier: entry.moduleSpecifier,\n })\n })\n sourceFile.addFunction({\n name: 'enhanceEntities',\n parameters: [\n { name: 'namespace', type: 'Record<string, unknown>' },\n { name: 'moduleId', type: 'string' },\n ],\n returnType: 'any[]',\n statements: [\n returnStatement(\n methodCall(\n methodCall(objectEntries(identifier('namespace')), 'filter', [\n arrowFunction({\n parameters: ['[, value]'],\n body: binaryExpression(\n prefixExpression('typeof ', identifier('value')),\n '===',\n 'function',\n ),\n }),\n ]),\n 'map',\n [\n arrowFunction({\n parameters: ['[exportName, value]'],\n body: (writer) => {\n writer.block(() => {\n variableStatement({\n name: 'entity',\n initializer: asExpression(identifier('value'), '{ entityName?: string }'),\n })(writer)\n writer.newLine()\n ifStatement({\n condition: logicalAnd([\n identifier('entity'),\n binaryExpression(\n prefixExpression('typeof ', identifier('entity')),\n '===',\n 'function',\n ),\n binaryExpression(\n methodCall(\n propertyAccess(\n propertyAccess(identifier('Object'), 'prototype'),\n 'hasOwnProperty',\n ),\n 'call',\n [identifier('entity'), 'entityName'],\n ),\n '===',\n false,\n ),\n ]),\n thenStatements: [\n expressionStatement(\n callExpression(propertyAccess(identifier('Object'), 'defineProperty'), [\n identifier('entity'),\n 'entityName',\n objectLiteral([\n {\n name: 'value',\n value: templateLiteral([\n identifier('moduleId'),\n '.',\n identifier('exportName'),\n ]),\n },\n { name: 'configurable', value: true },\n { name: 'enumerable', value: false },\n { name: 'writable', value: false },\n ]),\n ]),\n ),\n ],\n })(writer)\n writer.newLine()\n returnStatement(identifier('entity'))(writer)\n })\n },\n }),\n ],\n ),\n ),\n ],\n })\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'entities',\n initializer: arrayLiteral(entitySources, (writer, entry) =>\n spreadExpression(callExpression(identifier('enhanceEntities'), [identifier(entry.importName), entry.moduleId]))(writer)),\n },\n ],\n })\n const output = getSourceText(sourceFile)\n\n // Check if content has changed\n const newChecksum = calculateChecksum(output)\n let shouldWrite = true\n\n const existingRecord = readChecksumRecord(checksumFile)\n if (existingRecord && existingRecord.content === newChecksum) {\n shouldWrite = false\n }\n\n if (shouldWrite) {\n ensureDir(outFile)\n fs.writeFileSync(outFile, output)\n writeChecksumRecord(checksumFile, { content: newChecksum, structure: '' })\n result.filesWritten.push(outFile)\n if (!quiet) {\n logGenerationResult(path.relative(process.cwd(), outFile), true)\n }\n } else {\n result.filesUnchanged.push(outFile)\n }\n\n return result\n}\n\nfunction resolveConventionFile(baseDir: string, basename: string): string | null {\n for (const extension of MODULE_CODE_EXTENSIONS) {\n const candidate = path.join(baseDir, `${basename}${extension}`)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n"],
5
- "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,eAAe,+BAA+B;AAEvD,SAAS,wBAAwB,gCAAgC;AACjE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,eAAsB,uBAAuB,SAA0D;AACrG,QAAM,EAAE,UAAU,QAAQ,MAAM,IAAI;AACpC,QAAM,SAAS,sBAAsB;AAErC,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,UAAU,KAAK,KAAK,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AAA,IACF;AAAA,EACF,CAAC;AACD,QAAM,SAAS,cAAc,UAAU;AAGvC,QAAM,cAAc,kBAAkB,MAAM;AAC5C,MAAI,cAAc;AAElB,QAAM,iBAAiB,mBAAmB,YAAY;AACtD,MAAI,kBAAkB,eAAe,YAAY,aAAa;AAC5D,kBAAc;AAAA,EAChB;AAEA,MAAI,aAAa;AACf,cAAU,OAAO;AACjB,OAAG,cAAc,SAAS,MAAM;AAChC,wBAAoB,cAAc,EAAE,SAAS,aAAa,WAAW,GAAG,CAAC;AACzE,WAAO,aAAa,KAAK,OAAO;AAChC,QAAI,CAAC,OAAO;AACV,0BAAoB,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,GAAG,IAAI;AAAA,IACjE;AAAA,EACF,OAAO;AACL,WAAO,eAAe,KAAK,OAAO;AAAA,EACpC;AAEA,SAAO;AACT;AAEA,SAAS,sBAAsB,SAAiB,UAAiC;AAC/E,aAAW,aAAa,wBAAwB;AAC9C,UAAM,YAAY,KAAK,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE;AAC9D,QAAI,GAAG,WAAW,SAAS,EAAG,QAAO;AAAA,EACvC;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { StructureKind, VariableDeclarationKind } from 'ts-morph'\nimport type { PackageResolver } from '../resolver'\nimport { MODULE_CODE_EXTENSIONS, stripModuleCodeExtension } from './scanner'\nimport {\n toVar,\n type GeneratorResult,\n createGeneratorResult,\n writeGeneratedFile,\n} from '../utils'\nimport {\n addAutoGeneratedComment,\n addImportSpec,\n asExpression,\n arrayLiteral,\n arrowFunction,\n binaryExpression,\n callExpression,\n createGeneratedSourceFile,\n expressionStatement,\n getSourceText,\n identifier,\n ifStatement,\n logicalAnd,\n methodCall,\n objectEntries,\n objectLiteral,\n prefixExpression,\n propertyAccess,\n returnStatement,\n spreadExpression,\n templateLiteral,\n variableStatement,\n} from './ast'\n\nexport interface ModuleEntitiesOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\nexport async function generateModuleEntities(options: ModuleEntitiesOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.generated.checksum')\n\n const mods = resolver.loadEnabledModules()\n const imports: Array<{ name: string; moduleSpecifier: string }> = []\n const entitySources: Array<{ importName: string; moduleId: string }> = []\n let n = 0\n\n for (const entry of mods) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imp = resolver.getModuleImportBase(entry)\n const isAppModule = entry.from === '@app'\n\n // prefer app override data/, fallback to core data/, then legacy db/\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override', 'entities', 'schema']\n\n let found: { base: string; file: string } | null = null\n for (const base of bases) {\n for (const f of candidates) {\n const p = resolveConventionFile(base, f)\n if (p) {\n found = { base, file: path.basename(p) }\n break\n }\n }\n if (found) break\n }\n if (!found) continue\n\n const importName = `E_${toVar(modId)}_${n++}`\n const sub = path.basename(found.base) // 'data' or 'db'\n const fromApp = found.base.startsWith(roots.appBase)\n // For @app modules, use relative path to ensure it works both in Next.js and Node.js CLI context\n // From .mercato/generated/, the relative path to src/modules/ is ../src/modules/\n let relImport: string\n if (isAppModule && fromApp) {\n // From .mercato/generated/, go up two levels (../..) to reach the app root, then into src/modules/\n relImport = `../../src/modules/${modId}/${sub}/${stripModuleCodeExtension(found.file)}`\n } else {\n const baseImport = fromApp ? imp.appBase : imp.pkgBase\n relImport = `${baseImport}/${sub}/${stripModuleCodeExtension(found.file)}`\n }\n imports.push({ name: importName, moduleSpecifier: relImport })\n entitySources.push({ importName, moduleId: modId })\n }\n\n const sourceFile = createGeneratedSourceFile('entities.generated.ts')\n addAutoGeneratedComment(sourceFile, 'entities')\n imports.forEach((entry) => {\n addImportSpec(sourceFile, {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: entry.name,\n moduleSpecifier: entry.moduleSpecifier,\n })\n })\n sourceFile.addFunction({\n name: 'enhanceEntities',\n parameters: [\n { name: 'namespace', type: 'Record<string, unknown>' },\n { name: 'moduleId', type: 'string' },\n ],\n returnType: 'any[]',\n statements: [\n returnStatement(\n methodCall(\n methodCall(objectEntries(identifier('namespace')), 'filter', [\n arrowFunction({\n parameters: ['[, value]'],\n body: binaryExpression(\n prefixExpression('typeof ', identifier('value')),\n '===',\n 'function',\n ),\n }),\n ]),\n 'map',\n [\n arrowFunction({\n parameters: ['[exportName, value]'],\n body: (writer) => {\n writer.block(() => {\n variableStatement({\n name: 'entity',\n initializer: asExpression(identifier('value'), '{ entityName?: string }'),\n })(writer)\n writer.newLine()\n ifStatement({\n condition: logicalAnd([\n identifier('entity'),\n binaryExpression(\n prefixExpression('typeof ', identifier('entity')),\n '===',\n 'function',\n ),\n binaryExpression(\n methodCall(\n propertyAccess(\n propertyAccess(identifier('Object'), 'prototype'),\n 'hasOwnProperty',\n ),\n 'call',\n [identifier('entity'), 'entityName'],\n ),\n '===',\n false,\n ),\n ]),\n thenStatements: [\n expressionStatement(\n callExpression(propertyAccess(identifier('Object'), 'defineProperty'), [\n identifier('entity'),\n 'entityName',\n objectLiteral([\n {\n name: 'value',\n value: templateLiteral([\n identifier('moduleId'),\n '.',\n identifier('exportName'),\n ]),\n },\n { name: 'configurable', value: true },\n { name: 'enumerable', value: false },\n { name: 'writable', value: false },\n ]),\n ]),\n ),\n ],\n })(writer)\n writer.newLine()\n returnStatement(identifier('entity'))(writer)\n })\n },\n }),\n ],\n ),\n ),\n ],\n })\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'entities',\n initializer: arrayLiteral(entitySources, (writer, entry) =>\n spreadExpression(callExpression(identifier('enhanceEntities'), [identifier(entry.importName), entry.moduleId]))(writer)),\n },\n ],\n })\n const output = getSourceText(sourceFile)\n\n writeGeneratedFile({\n outFile,\n checksumFile,\n content: output,\n structureChecksum: '',\n result,\n quiet,\n })\n\n return result\n}\n\nfunction resolveConventionFile(baseDir: string, basename: string): string | null {\n for (const extension of MODULE_CODE_EXTENSIONS) {\n const candidate = path.join(baseDir, `${basename}${extension}`)\n if (fs.existsSync(candidate)) return candidate\n }\n return null\n}\n"],
5
+ "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,eAAe,+BAA+B;AAEvD,SAAS,wBAAwB,gCAAgC;AACjE;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,eAAsB,uBAAuB,SAA0D;AACrG,QAAM,EAAE,UAAU,QAAQ,MAAM,IAAI;AACpC,QAAM,SAAS,sBAAsB;AAErC,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,UAAU,KAAK,KAAK,WAAW,uBAAuB;AAC5D,QAAM,eAAe,KAAK,KAAK,WAAW,6BAA6B;AAEvE,QAAM,OAAO,SAAS,mBAAmB;AACzC,QAAM,UAA4D,CAAC;AACnE,QAAM,gBAAiE,CAAC;AACxE,MAAI,IAAI;AAER,aAAW,SAAS,MAAM;AACxB,UAAM,QAAQ,MAAM;AACpB,UAAM,QAAQ,SAAS,eAAe,KAAK;AAC3C,UAAM,MAAM,SAAS,oBAAoB,KAAK;AAC9C,UAAM,cAAc,MAAM,SAAS;AAGnC,UAAM,UAAU,KAAK,KAAK,MAAM,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