@geekmidas/cli 10.0.0-alpha.9 → 10.0.0-alpha.90

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 (457) hide show
  1. package/README.md +315 -414
  2. package/bin/adjacent-tsconfig.mjs +46 -8
  3. package/bin/gkm.mjs +11 -3
  4. package/bin/owning-tsconfig-jsx-register.mjs +18 -0
  5. package/bin/owning-tsconfig-jsx.mjs +108 -0
  6. package/dist/EndpointGenerator-CVc6Oi1Y.mjs +1021 -0
  7. package/dist/EndpointGenerator-CVc6Oi1Y.mjs.map +1 -0
  8. package/dist/EndpointGenerator-CwLjBCFE.cjs +1080 -0
  9. package/dist/EndpointGenerator-CwLjBCFE.cjs.map +1 -0
  10. package/dist/GoDaddyProvider-DSStJVAv.mjs +387 -0
  11. package/dist/GoDaddyProvider-DSStJVAv.mjs.map +1 -0
  12. package/dist/GoDaddyProvider-DqZ1qD_F.cjs +387 -0
  13. package/dist/GoDaddyProvider-DqZ1qD_F.cjs.map +1 -0
  14. package/dist/{HostingerProvider-Cft7lEYr.mjs → HostingerProvider-BI6J7oJr.mjs} +22 -23
  15. package/dist/HostingerProvider-BI6J7oJr.mjs.map +1 -0
  16. package/dist/{HostingerProvider-h3EbEp-Z.cjs → HostingerProvider-CyTpG_jy.cjs} +22 -23
  17. package/dist/HostingerProvider-CyTpG_jy.cjs.map +1 -0
  18. package/dist/LegacyStateStore-DXmNA7hy.cjs +89 -0
  19. package/dist/LegacyStateStore-DXmNA7hy.cjs.map +1 -0
  20. package/dist/LegacyStateStore-ZkdmiUFZ.mjs +89 -0
  21. package/dist/LegacyStateStore-ZkdmiUFZ.mjs.map +1 -0
  22. package/dist/LocalStateStore-BBeTlRTH.cjs +178 -0
  23. package/dist/LocalStateStore-BBeTlRTH.cjs.map +1 -0
  24. package/dist/LocalStateStore-CU-O0SBp.mjs +167 -0
  25. package/dist/LocalStateStore-CU-O0SBp.mjs.map +1 -0
  26. package/dist/OpenApiTsGenerator-B--HV-sW.cjs +541 -0
  27. package/dist/OpenApiTsGenerator-B--HV-sW.cjs.map +1 -0
  28. package/dist/OpenApiTsGenerator-CkvsPdgg.mjs +536 -0
  29. package/dist/OpenApiTsGenerator-CkvsPdgg.mjs.map +1 -0
  30. package/dist/{Route53Provider-di2fMM5N.cjs → Route53Provider-Bllus2NR.cjs} +21 -22
  31. package/dist/Route53Provider-Bllus2NR.cjs.map +1 -0
  32. package/dist/{Route53Provider-RdpUDJQk.mjs → Route53Provider-QXxjkZO1.mjs} +13 -13
  33. package/dist/Route53Provider-QXxjkZO1.mjs.map +1 -0
  34. package/dist/S3StateStore-Br8VMY22.cjs +160 -0
  35. package/dist/S3StateStore-Br8VMY22.cjs.map +1 -0
  36. package/dist/S3StateStore-bwxcI_wQ.mjs +161 -0
  37. package/dist/S3StateStore-bwxcI_wQ.mjs.map +1 -0
  38. package/dist/SSMStateStore-CsOS0W1y.mjs +154 -0
  39. package/dist/SSMStateStore-CsOS0W1y.mjs.map +1 -0
  40. package/dist/SSMStateStore-DoZE1Wi1.cjs +153 -0
  41. package/dist/SSMStateStore-DoZE1Wi1.cjs.map +1 -0
  42. package/dist/SubscriberGenerator-BPqQf8fB.mjs +448 -0
  43. package/dist/SubscriberGenerator-BPqQf8fB.mjs.map +1 -0
  44. package/dist/SubscriberGenerator-BVn7cQ-2.cjs +489 -0
  45. package/dist/SubscriberGenerator-BVn7cQ-2.cjs.map +1 -0
  46. package/dist/add-CNMF0Q3m.cjs +594 -0
  47. package/dist/add-CNMF0Q3m.cjs.map +1 -0
  48. package/dist/add-DHk1roh_.mjs +592 -0
  49. package/dist/add-DHk1roh_.mjs.map +1 -0
  50. package/dist/appPorts-C9z9Pzn9.mjs +223 -0
  51. package/dist/appPorts-C9z9Pzn9.mjs.map +1 -0
  52. package/dist/appPorts-Cu79hJF6.cjs +264 -0
  53. package/dist/appPorts-Cu79hJF6.cjs.map +1 -0
  54. package/dist/aws-B-6uEhgP.mjs +71 -0
  55. package/dist/aws-B-6uEhgP.mjs.map +1 -0
  56. package/dist/aws-BTawF0F-.cjs +82 -0
  57. package/dist/aws-BTawF0F-.cjs.map +1 -0
  58. package/dist/awsStore-7VmS_cZR.cjs +54 -0
  59. package/dist/awsStore-7VmS_cZR.cjs.map +1 -0
  60. package/dist/awsStore-B529csle.mjs +43 -0
  61. package/dist/awsStore-B529csle.mjs.map +1 -0
  62. package/dist/{backup-provisioner-Bgj5Vi_L.mjs → backup-provisioner-C8DnCmxK.mjs} +11 -8
  63. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  64. package/dist/{backup-provisioner-BrsHwYG0.cjs → backup-provisioner-oDEsPj02.cjs} +22 -20
  65. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  66. package/dist/{bundler-BY1OmV1e.cjs → bundler-BQJiB7Ub.cjs} +38 -35
  67. package/dist/bundler-BQJiB7Ub.cjs.map +1 -0
  68. package/dist/{bundler-Be8Zg4Wd.mjs → bundler-D6eBfVkl.mjs} +36 -32
  69. package/dist/bundler-D6eBfVkl.mjs.map +1 -0
  70. package/dist/cli-BE9mqeX8.cjs +69 -0
  71. package/dist/cli-BE9mqeX8.cjs.map +1 -0
  72. package/dist/cli-DD-Yk-I5.mjs +69 -0
  73. package/dist/cli-DD-Yk-I5.mjs.map +1 -0
  74. package/dist/compose-Bhmf0n4o.mjs +3140 -0
  75. package/dist/compose-Bhmf0n4o.mjs.map +1 -0
  76. package/dist/compose-CvpU6ooi.cjs +3265 -0
  77. package/dist/compose-CvpU6ooi.cjs.map +1 -0
  78. package/dist/config-CdEcTrjG.d.mts +269 -0
  79. package/dist/config-CdEcTrjG.d.mts.map +1 -0
  80. package/dist/config-pST7E0CS.d.cts +269 -0
  81. package/dist/config-pST7E0CS.d.cts.map +1 -0
  82. package/dist/config.cjs +420 -11
  83. package/dist/config.cjs.map +1 -0
  84. package/dist/config.d.cts +4 -120
  85. package/dist/config.d.mts +4 -120
  86. package/dist/config.mjs +404 -4
  87. package/dist/config.mjs.map +1 -0
  88. package/dist/credentialSchemas-BJqRJNK4.mjs +236 -0
  89. package/dist/credentialSchemas-BJqRJNK4.mjs.map +1 -0
  90. package/dist/credentialSchemas-DCR4Wd1W.cjs +271 -0
  91. package/dist/credentialSchemas-DCR4Wd1W.cjs.map +1 -0
  92. package/dist/credentials-BKfIugu2.cjs +513 -0
  93. package/dist/credentials-BKfIugu2.cjs.map +1 -0
  94. package/dist/credentials-CnVqoXMb.mjs +388 -0
  95. package/dist/credentials-CnVqoXMb.mjs.map +1 -0
  96. package/dist/databases-BY-pEImp.cjs +597 -0
  97. package/dist/databases-BY-pEImp.cjs.map +1 -0
  98. package/dist/databases-CzszQV0N.mjs +494 -0
  99. package/dist/databases-CzszQV0N.mjs.map +1 -0
  100. package/dist/define-DR8xGYfL.mjs +97 -0
  101. package/dist/define-DR8xGYfL.mjs.map +1 -0
  102. package/dist/define-DzRz8FgH.cjs +144 -0
  103. package/dist/define-DzRz8FgH.cjs.map +1 -0
  104. package/dist/deploy/public.cjs +208 -0
  105. package/dist/deploy/public.cjs.map +1 -0
  106. package/dist/deploy/public.d.cts +649 -0
  107. package/dist/deploy/public.d.cts.map +1 -0
  108. package/dist/deploy/public.d.mts +649 -0
  109. package/dist/deploy/public.d.mts.map +1 -0
  110. package/dist/deploy/public.mjs +142 -0
  111. package/dist/deploy/public.mjs.map +1 -0
  112. package/dist/deploy/sniffer-envkit-patch.cjs +18 -10
  113. package/dist/deploy/sniffer-envkit-patch.cjs.map +1 -1
  114. package/dist/deploy/sniffer-envkit-patch.d.cts +0 -2
  115. package/dist/deploy/sniffer-envkit-patch.d.cts.map +1 -1
  116. package/dist/deploy/sniffer-envkit-patch.d.mts +0 -2
  117. package/dist/deploy/sniffer-envkit-patch.d.mts.map +1 -1
  118. package/dist/deploy/sniffer-envkit-patch.mjs +10 -2
  119. package/dist/deploy/sniffer-envkit-patch.mjs.map +1 -1
  120. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  121. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  122. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  123. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  124. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  125. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  126. package/dist/deploy/sniffer-hooks.cjs +13 -7
  127. package/dist/deploy/sniffer-hooks.cjs.map +1 -1
  128. package/dist/deploy/sniffer-hooks.d.cts +1 -2
  129. package/dist/deploy/sniffer-hooks.d.cts.map +1 -1
  130. package/dist/deploy/sniffer-hooks.d.mts +1 -2
  131. package/dist/deploy/sniffer-hooks.d.mts.map +1 -1
  132. package/dist/deploy/sniffer-hooks.mjs +10 -3
  133. package/dist/deploy/sniffer-hooks.mjs.map +1 -1
  134. package/dist/deploy/sniffer-loader.cjs +16 -7
  135. package/dist/deploy/sniffer-loader.cjs.map +1 -1
  136. package/dist/deploy/sniffer-loader.d.cts +1 -1
  137. package/dist/deploy/sniffer-loader.d.mts +1 -1
  138. package/dist/deploy/sniffer-loader.mjs +14 -3
  139. package/dist/deploy/sniffer-loader.mjs.map +1 -1
  140. package/dist/deploy/sniffer-routes-worker.cjs +11 -11
  141. package/dist/deploy/sniffer-routes-worker.cjs.map +1 -1
  142. package/dist/deploy/sniffer-routes-worker.d.cts +1 -1
  143. package/dist/deploy/sniffer-routes-worker.d.mts +1 -1
  144. package/dist/deploy/sniffer-routes-worker.mjs +4 -4
  145. package/dist/deploy/sniffer-routes-worker.mjs.map +1 -1
  146. package/dist/deploy/sniffer-worker.cjs +15 -6
  147. package/dist/deploy/sniffer-worker.cjs.map +1 -1
  148. package/dist/deploy/sniffer-worker.d.cts +1 -3
  149. package/dist/deploy/sniffer-worker.d.cts.map +1 -1
  150. package/dist/deploy/sniffer-worker.d.mts +1 -3
  151. package/dist/deploy/sniffer-worker.d.mts.map +1 -1
  152. package/dist/deploy/sniffer-worker.mjs +15 -4
  153. package/dist/deploy/sniffer-worker.mjs.map +1 -1
  154. package/dist/deploy-CuHasEA4.cjs +554 -0
  155. package/dist/deploy-CuHasEA4.cjs.map +1 -0
  156. package/dist/deploy-QNtx_eWR.mjs +525 -0
  157. package/dist/deploy-QNtx_eWR.mjs.map +1 -0
  158. package/dist/derive-B4vDpzgP.mjs +150 -0
  159. package/dist/derive-B4vDpzgP.mjs.map +1 -0
  160. package/dist/derive-DAbo49sm.cjs +161 -0
  161. package/dist/derive-DAbo49sm.cjs.map +1 -0
  162. package/dist/discover-BPelzeGW.mjs +526 -0
  163. package/dist/discover-BPelzeGW.mjs.map +1 -0
  164. package/dist/discover-CU0paUyH.d.cts +108 -0
  165. package/dist/discover-CU0paUyH.d.cts.map +1 -0
  166. package/dist/discover-D1It5r_h.cjs +599 -0
  167. package/dist/discover-D1It5r_h.cjs.map +1 -0
  168. package/dist/discover-DFiJxwfv.d.mts +108 -0
  169. package/dist/discover-DFiJxwfv.d.mts.map +1 -0
  170. package/dist/dokploy-CYcMLh9-.mjs +38 -0
  171. package/dist/dokploy-CYcMLh9-.mjs.map +1 -0
  172. package/dist/dokploy-DIowwyIB.cjs +38 -0
  173. package/dist/dokploy-DIowwyIB.cjs.map +1 -0
  174. package/dist/drivers-DTZzxeIl.mjs +177 -0
  175. package/dist/drivers-DTZzxeIl.mjs.map +1 -0
  176. package/dist/drivers-LYSdQDmd.cjs +200 -0
  177. package/dist/drivers-LYSdQDmd.cjs.map +1 -0
  178. package/dist/{emit-CiZS_5Ub.mjs → emit-C1e8qD08.mjs} +13 -26
  179. package/dist/emit-C1e8qD08.mjs.map +1 -0
  180. package/dist/{emit-CbcRolsa.cjs → emit-Dmc1nvdS.cjs} +31 -57
  181. package/dist/emit-Dmc1nvdS.cjs.map +1 -0
  182. package/dist/encryption-BrEef7Jk.mjs +88 -0
  183. package/dist/encryption-BrEef7Jk.mjs.map +1 -0
  184. package/dist/encryption-CjYdUb2s.cjs +89 -0
  185. package/dist/encryption-CjYdUb2s.cjs.map +1 -0
  186. package/dist/engine-2h4k5ICq.mjs +3085 -0
  187. package/dist/engine-2h4k5ICq.mjs.map +1 -0
  188. package/dist/engine-BhJ7ZP9K.cjs +3198 -0
  189. package/dist/engine-BhJ7ZP9K.cjs.map +1 -0
  190. package/dist/github-B5Bw4HIu.cjs +669 -0
  191. package/dist/github-B5Bw4HIu.cjs.map +1 -0
  192. package/dist/github-BCDF6xVH.mjs +669 -0
  193. package/dist/github-BCDF6xVH.mjs.map +1 -0
  194. package/dist/{index-C6e-ULLx.d.mts → index-D-F_hTDz.d.cts} +39 -24
  195. package/dist/index-D-F_hTDz.d.cts.map +1 -0
  196. package/dist/{index-CR5urhWX.d.cts → index-YFNxR5Ns.d.mts} +39 -24
  197. package/dist/index-YFNxR5Ns.d.mts.map +1 -0
  198. package/dist/index.cjs +9487 -12080
  199. package/dist/index.cjs.map +1 -1
  200. package/dist/index.d.cts +1 -1
  201. package/dist/index.d.mts +1 -1
  202. package/dist/index.mjs +9420 -12026
  203. package/dist/index.mjs.map +1 -1
  204. package/dist/local-BjxDfPvy.cjs +241 -0
  205. package/dist/local-BjxDfPvy.cjs.map +1 -0
  206. package/dist/local-IuoIF3CT.mjs +224 -0
  207. package/dist/local-IuoIF3CT.mjs.map +1 -0
  208. package/dist/migrate-CGaancHY.cjs +93 -0
  209. package/dist/migrate-CGaancHY.cjs.map +1 -0
  210. package/dist/migrate-DWZz9kah.mjs +93 -0
  211. package/dist/migrate-DWZz9kah.mjs.map +1 -0
  212. package/dist/migrate-DbtcuOr_.mjs +265 -0
  213. package/dist/migrate-DbtcuOr_.mjs.map +1 -0
  214. package/dist/migrate-q2YYLJLE.cjs +270 -0
  215. package/dist/migrate-q2YYLJLE.cjs.map +1 -0
  216. package/dist/openapi.cjs +214 -10
  217. package/dist/openapi.cjs.map +1 -0
  218. package/dist/openapi.d.cts +47 -17
  219. package/dist/openapi.d.cts.map +1 -1
  220. package/dist/openapi.d.mts +47 -17
  221. package/dist/openapi.d.mts.map +1 -1
  222. package/dist/openapi.mjs +208 -5
  223. package/dist/openapi.mjs.map +1 -0
  224. package/dist/provider-C9_-45d5.cjs +56 -0
  225. package/dist/provider-C9_-45d5.cjs.map +1 -0
  226. package/dist/provider-q4lsYzYG.mjs +45 -0
  227. package/dist/provider-q4lsYzYG.mjs.map +1 -0
  228. package/dist/ready-BpNbORRB.cjs +402 -0
  229. package/dist/ready-BpNbORRB.cjs.map +1 -0
  230. package/dist/ready-b6vm0-W-.mjs +373 -0
  231. package/dist/ready-b6vm0-W-.mjs.map +1 -0
  232. package/dist/reconcile/public.cjs +3 -5
  233. package/dist/reconcile/public.d.cts +11 -87
  234. package/dist/reconcile/public.d.cts.map +1 -1
  235. package/dist/reconcile/public.d.mts +11 -87
  236. package/dist/reconcile/public.d.mts.map +1 -1
  237. package/dist/reconcile/public.mjs +3 -4
  238. package/dist/{reconcile-D0pimNiy.cjs → reconcile-CuCQBa5-.cjs} +5 -8
  239. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  240. package/dist/{reconcile-CFs8C_1a.mjs → reconcile-Dh1Jk7WE.mjs} +4 -7
  241. package/dist/reconcile-Dh1Jk7WE.mjs.map +1 -0
  242. package/dist/resolve-Cns0v6dN.cjs +315 -0
  243. package/dist/resolve-Cns0v6dN.cjs.map +1 -0
  244. package/dist/resolve-DNg0icnh.mjs +262 -0
  245. package/dist/resolve-DNg0icnh.mjs.map +1 -0
  246. package/dist/rollback-CFrNLmxs.mjs +132 -0
  247. package/dist/rollback-CFrNLmxs.mjs.map +1 -0
  248. package/dist/rollback-UIjS25F1.cjs +161 -0
  249. package/dist/rollback-UIjS25F1.cjs.map +1 -0
  250. package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
  251. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-C0BPl7ul.cjs} +23 -10
  252. package/dist/runtime-CN_kmqxo.d.cts +90 -0
  253. package/dist/runtime-CN_kmqxo.d.cts.map +1 -0
  254. package/dist/runtime-Cjvon3oj.d.mts +90 -0
  255. package/dist/runtime-Cjvon3oj.d.mts.map +1 -0
  256. package/dist/sandbox/config-worker.cjs +43 -0
  257. package/dist/sandbox/config-worker.cjs.map +1 -0
  258. package/dist/sandbox/config-worker.d.cts +1 -0
  259. package/dist/sandbox/config-worker.d.mts +1 -0
  260. package/dist/sandbox/config-worker.mjs +44 -0
  261. package/dist/sandbox/config-worker.mjs.map +1 -0
  262. package/dist/sandbox/credentials-worker.cjs +54 -0
  263. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  264. package/dist/sandbox/credentials-worker.d.cts +1 -0
  265. package/dist/sandbox/credentials-worker.d.mts +1 -0
  266. package/dist/sandbox/credentials-worker.mjs +55 -0
  267. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  268. package/dist/sandbox/discover-worker.cjs +47 -0
  269. package/dist/sandbox/discover-worker.cjs.map +1 -0
  270. package/dist/sandbox/discover-worker.d.cts +1 -0
  271. package/dist/sandbox/discover-worker.d.mts +1 -0
  272. package/dist/sandbox/discover-worker.mjs +48 -0
  273. package/dist/sandbox/discover-worker.mjs.map +1 -0
  274. package/dist/sandbox/migrate-worker.cjs +75 -0
  275. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  276. package/dist/sandbox/migrate-worker.d.cts +1 -0
  277. package/dist/sandbox/migrate-worker.d.mts +1 -0
  278. package/dist/sandbox/migrate-worker.mjs +76 -0
  279. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  280. package/dist/sandbox-CL--ZDui.cjs +164 -0
  281. package/dist/sandbox-CL--ZDui.cjs.map +1 -0
  282. package/dist/sandbox-Dm247NGx.mjs +117 -0
  283. package/dist/sandbox-Dm247NGx.mjs.map +1 -0
  284. package/dist/sandbox-M8UnLhXE.d.cts +126 -0
  285. package/dist/sandbox-M8UnLhXE.d.cts.map +1 -0
  286. package/dist/sandbox-M8UnLhXE.d.mts +126 -0
  287. package/dist/sandbox-M8UnLhXE.d.mts.map +1 -0
  288. package/dist/{workspace-zoqRbihZ.mjs → schemas-BObwxB_t.cjs} +998 -1659
  289. package/dist/schemas-BObwxB_t.cjs.map +1 -0
  290. package/dist/{workspace-C6VJQVtG.cjs → schemas-D-xeKJDD.mjs} +913 -1842
  291. package/dist/schemas-D-xeKJDD.mjs.map +1 -0
  292. package/dist/secretsManager-Chs9VV2r.mjs +76 -0
  293. package/dist/secretsManager-Chs9VV2r.mjs.map +1 -0
  294. package/dist/secretsManager-DcMlHnRC.cjs +87 -0
  295. package/dist/secretsManager-DcMlHnRC.cjs.map +1 -0
  296. package/dist/seeds-CkIPFGNO.cjs +10560 -0
  297. package/dist/seeds-CkIPFGNO.cjs.map +1 -0
  298. package/dist/seeds-odfgSCmu.mjs +9538 -0
  299. package/dist/seeds-odfgSCmu.mjs.map +1 -0
  300. package/dist/sniffer-BTtX3NUM.mjs +1262 -0
  301. package/dist/sniffer-BTtX3NUM.mjs.map +1 -0
  302. package/dist/sniffer-IAQEpsQb.cjs +1333 -0
  303. package/dist/sniffer-IAQEpsQb.cjs.map +1 -0
  304. package/dist/sst-BgcOsaBi.cjs +453 -0
  305. package/dist/sst-BgcOsaBi.cjs.map +1 -0
  306. package/dist/sst-CJzvyrEz.mjs +430 -0
  307. package/dist/sst-CJzvyrEz.mjs.map +1 -0
  308. package/dist/stages-CUn6gvXL.cjs +174 -0
  309. package/dist/stages-CUn6gvXL.cjs.map +1 -0
  310. package/dist/stages-CnZRYmkI.mjs +174 -0
  311. package/dist/stages-CnZRYmkI.mjs.map +1 -0
  312. package/dist/target/public.cjs +15 -0
  313. package/dist/target/public.d.cts +28 -0
  314. package/dist/target/public.d.cts.map +1 -0
  315. package/dist/target/public.d.mts +28 -0
  316. package/dist/target/public.d.mts.map +1 -0
  317. package/dist/target/public.mjs +4 -0
  318. package/dist/terminal-D8TPK7o9.mjs +84 -0
  319. package/dist/terminal-D8TPK7o9.mjs.map +1 -0
  320. package/dist/terminal-DuapRxh6.cjs +84 -0
  321. package/dist/terminal-DuapRxh6.cjs.map +1 -0
  322. package/dist/types-NqX1Hz4P.d.cts +7454 -0
  323. package/dist/types-NqX1Hz4P.d.cts.map +1 -0
  324. package/dist/types-ZHuZ89hv.d.mts +7453 -0
  325. package/dist/types-ZHuZ89hv.d.mts.map +1 -0
  326. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  327. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  328. package/dist/utils-D_fxUqvU.mjs +156 -0
  329. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  330. package/dist/vitest.cjs +65 -0
  331. package/dist/vitest.cjs.map +1 -0
  332. package/dist/vitest.d.cts +29 -0
  333. package/dist/vitest.d.cts.map +1 -0
  334. package/dist/vitest.d.mts +29 -0
  335. package/dist/vitest.d.mts.map +1 -0
  336. package/dist/vitest.mjs +65 -0
  337. package/dist/vitest.mjs.map +1 -0
  338. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  339. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  340. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  341. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  342. package/dist/workspace/index.cjs +8 -4
  343. package/dist/workspace/index.d.cts +3 -3
  344. package/dist/workspace/index.d.mts +3 -3
  345. package/dist/workspace/index.mjs +2 -3
  346. package/dist/workspace-CJ0lKFq-.mjs +1979 -0
  347. package/dist/workspace-CJ0lKFq-.mjs.map +1 -0
  348. package/dist/workspace-CwW3Gkru.cjs +2355 -0
  349. package/dist/workspace-CwW3Gkru.cjs.map +1 -0
  350. package/package.json +53 -22
  351. package/dist/CachedStateProvider-BLo7zv7S.cjs +0 -3
  352. package/dist/CachedStateProvider-BxoAm-B2.mjs +0 -3
  353. package/dist/CachedStateProvider-CqPdW7CB.cjs +0 -60
  354. package/dist/CachedStateProvider-CqPdW7CB.cjs.map +0 -1
  355. package/dist/CachedStateProvider-DTniehMP.mjs +0 -54
  356. package/dist/CachedStateProvider-DTniehMP.mjs.map +0 -1
  357. package/dist/HostingerProvider-Cft7lEYr.mjs.map +0 -1
  358. package/dist/HostingerProvider-h3EbEp-Z.cjs.map +0 -1
  359. package/dist/LocalStateProvider-Bn6tS-oL.mjs +0 -42
  360. package/dist/LocalStateProvider-Bn6tS-oL.mjs.map +0 -1
  361. package/dist/LocalStateProvider-Db9SEjyH.cjs +0 -43
  362. package/dist/LocalStateProvider-Db9SEjyH.cjs.map +0 -1
  363. package/dist/Route53Provider-RdpUDJQk.mjs.map +0 -1
  364. package/dist/Route53Provider-di2fMM5N.cjs.map +0 -1
  365. package/dist/SSMStateProvider-BRt2py-A.mjs +0 -66
  366. package/dist/SSMStateProvider-BRt2py-A.mjs.map +0 -1
  367. package/dist/SSMStateProvider-DyX8s9HI.cjs +0 -66
  368. package/dist/SSMStateProvider-DyX8s9HI.cjs.map +0 -1
  369. package/dist/backup-provisioner-Bgj5Vi_L.mjs.map +0 -1
  370. package/dist/backup-provisioner-BrsHwYG0.cjs.map +0 -1
  371. package/dist/bundler-BY1OmV1e.cjs.map +0 -1
  372. package/dist/bundler-Be8Zg4Wd.mjs.map +0 -1
  373. package/dist/chunk-Duj1WY3L.mjs +0 -7
  374. package/dist/config-BZ1F0WuA.cjs +0 -462
  375. package/dist/config-BZ1F0WuA.cjs.map +0 -1
  376. package/dist/config-DVVph9yz.mjs +0 -402
  377. package/dist/config-DVVph9yz.mjs.map +0 -1
  378. package/dist/config.d.cts.map +0 -1
  379. package/dist/config.d.mts.map +0 -1
  380. package/dist/credentials-B5zRHdAl.mjs +0 -141
  381. package/dist/credentials-B5zRHdAl.mjs.map +0 -1
  382. package/dist/credentials-BapzjyV5.cjs +0 -195
  383. package/dist/credentials-BapzjyV5.cjs.map +0 -1
  384. package/dist/credentials-Xamqe_NJ.cjs +0 -2681
  385. package/dist/credentials-Xamqe_NJ.cjs.map +0 -1
  386. package/dist/credentials-dP8vRVRv.mjs +0 -2549
  387. package/dist/credentials-dP8vRVRv.mjs.map +0 -1
  388. package/dist/discover-CAlFgYec.mjs +0 -229
  389. package/dist/discover-CAlFgYec.mjs.map +0 -1
  390. package/dist/discover-DTmFeloL.cjs +0 -271
  391. package/dist/discover-DTmFeloL.cjs.map +0 -1
  392. package/dist/dokploy-api-BS2xnJLZ.mjs +0 -3
  393. package/dist/dokploy-api-BsVH0y_s.cjs +0 -718
  394. package/dist/dokploy-api-BsVH0y_s.cjs.map +0 -1
  395. package/dist/dokploy-api-BuxDRo3l.cjs +0 -3
  396. package/dist/dokploy-api-aTFPz7_4.mjs +0 -706
  397. package/dist/dokploy-api-aTFPz7_4.mjs.map +0 -1
  398. package/dist/emit-CbcRolsa.cjs.map +0 -1
  399. package/dist/emit-CiZS_5Ub.mjs.map +0 -1
  400. package/dist/encryption-C6jaU0hE.cjs +0 -54
  401. package/dist/encryption-C6jaU0hE.cjs.map +0 -1
  402. package/dist/encryption-CHzzeR8a.cjs +0 -4
  403. package/dist/encryption-CQUncu7v.mjs +0 -3
  404. package/dist/encryption-D-abyhZx.mjs +0 -42
  405. package/dist/encryption-D-abyhZx.mjs.map +0 -1
  406. package/dist/fullstack-secrets-C-GGohke.cjs +0 -111
  407. package/dist/fullstack-secrets-C-GGohke.cjs.map +0 -1
  408. package/dist/fullstack-secrets-D1o9-G5l.mjs +0 -87
  409. package/dist/fullstack-secrets-D1o9-G5l.mjs.map +0 -1
  410. package/dist/generator-CNzBw7g5.cjs +0 -289
  411. package/dist/generator-CNzBw7g5.cjs.map +0 -1
  412. package/dist/generator-VE2JrFlY.mjs +0 -253
  413. package/dist/generator-VE2JrFlY.mjs.map +0 -1
  414. package/dist/index-C6e-ULLx.d.mts.map +0 -1
  415. package/dist/index-CR5urhWX.d.cts.map +0 -1
  416. package/dist/openapi-SjsgARie.cjs +0 -2075
  417. package/dist/openapi-SjsgARie.cjs.map +0 -1
  418. package/dist/openapi-Xx0A7Wg0.mjs +0 -2021
  419. package/dist/openapi-Xx0A7Wg0.mjs.map +0 -1
  420. package/dist/openapi-react-query-Byltvm_7.mjs +0 -167
  421. package/dist/openapi-react-query-Byltvm_7.mjs.map +0 -1
  422. package/dist/openapi-react-query-CmJ1xDbn.cjs +0 -173
  423. package/dist/openapi-react-query-CmJ1xDbn.cjs.map +0 -1
  424. package/dist/openapi-react-query.cjs +0 -4
  425. package/dist/openapi-react-query.d.cts +0 -11
  426. package/dist/openapi-react-query.d.cts.map +0 -1
  427. package/dist/openapi-react-query.d.mts +0 -11
  428. package/dist/openapi-react-query.d.mts.map +0 -1
  429. package/dist/openapi-react-query.mjs +0 -4
  430. package/dist/reconcile-CFs8C_1a.mjs.map +0 -1
  431. package/dist/reconcile-D0pimNiy.cjs.map +0 -1
  432. package/dist/setup-BA8ciTPU.mjs +0 -11
  433. package/dist/setup-BsZvZP6f.cjs +0 -11
  434. package/dist/setup-C8KOx8_8.mjs +0 -443
  435. package/dist/setup-C8KOx8_8.mjs.map +0 -1
  436. package/dist/setup-hC6hI86f.cjs +0 -473
  437. package/dist/setup-hC6hI86f.cjs.map +0 -1
  438. package/dist/storage-BJmzYxt8.cjs +0 -363
  439. package/dist/storage-BJmzYxt8.cjs.map +0 -1
  440. package/dist/storage-BM9hGpgv.cjs +0 -7
  441. package/dist/storage-Bi24WfoW.mjs +0 -297
  442. package/dist/storage-Bi24WfoW.mjs.map +0 -1
  443. package/dist/storage-CYlGwWTj.mjs +0 -3
  444. package/dist/sync-CmEuNZsB.mjs +0 -76
  445. package/dist/sync-CmEuNZsB.mjs.map +0 -1
  446. package/dist/sync-D306yOWu.cjs +0 -4
  447. package/dist/sync-SizaChmC.cjs +0 -93
  448. package/dist/sync-SizaChmC.cjs.map +0 -1
  449. package/dist/sync-hOqAWHR6.mjs +0 -3
  450. package/dist/types-6pkp2RRj.d.mts +0 -2220
  451. package/dist/types-6pkp2RRj.d.mts.map +0 -1
  452. package/dist/types-Y3fKQSAK.d.cts +0 -2220
  453. package/dist/types-Y3fKQSAK.d.cts.map +0 -1
  454. package/dist/workspace-BzrG_2SI.mjs +0 -8
  455. package/dist/workspace-C6VJQVtG.cjs.map +0 -1
  456. package/dist/workspace-XXtNhqJl.cjs +0 -9
  457. package/dist/workspace-zoqRbihZ.mjs.map +0 -1
@@ -0,0 +1,1021 @@
1
+ import { u as ConstructGenerator } from "./discover-BPelzeGW.mjs";
2
+ import { dirname, join, relative, resolve } from "node:path";
3
+ import { existsSync, realpathSync } from "node:fs";
4
+ import { mkdir, writeFile } from "node:fs/promises";
5
+ import { Endpoint } from "@geekmidas/constructs/endpoints";
6
+ //#region src/generators/telemetry.ts
7
+ /** Each endpoint's own `.telemetry({ ignore, attributes })`, as routes. */
8
+ function routeTelemetry(endpoints) {
9
+ return endpoints.flatMap((endpoint) => endpoint.telemetry ? [{
10
+ method: endpoint.method,
11
+ path: endpoint.route,
12
+ ...endpoint.telemetry
13
+ }] : []);
14
+ }
15
+ /**
16
+ * Every package `@geekmidas/telescope/instrumentation` loads at runtime.
17
+ *
18
+ * All of them, rather than one as a proxy: the production bundle follows each
19
+ * import, and a single missing one fails the build rather than the telemetry.
20
+ */
21
+ const TELEMETRY_PACKAGES = [
22
+ "@opentelemetry/api",
23
+ "@opentelemetry/auto-instrumentations-node",
24
+ "@opentelemetry/exporter-logs-otlp-http",
25
+ "@opentelemetry/exporter-trace-otlp-http",
26
+ "@opentelemetry/instrumentation-pino",
27
+ "@opentelemetry/resources",
28
+ "@opentelemetry/sdk-logs",
29
+ "@opentelemetry/sdk-node",
30
+ "@opentelemetry/sdk-trace-base",
31
+ "@opentelemetry/sdk-trace-node",
32
+ "@opentelemetry/semantic-conventions"
33
+ ];
34
+ /**
35
+ * The directory of `name` as `node_modules` lookup finds it from `fromDir`,
36
+ * symlinks resolved — or undefined.
37
+ *
38
+ * The directory walk alone, not `require.resolve`: that also searches
39
+ * `NODE_PATH`, which a package manager's bin shim sets to its own store, so a
40
+ * `gkm build` run through one would find packages the app never installed —
41
+ * and the bundler, which does not look there, would then fail on them.
42
+ */
43
+ function packageDir(fromDir, name) {
44
+ for (let dir = resolve(fromDir);; dir = dirname(dir)) {
45
+ const candidate = join(dir, "node_modules", name);
46
+ if (existsSync(join(candidate, "package.json"))) return realpathSync(candidate);
47
+ if (dirname(dir) === dir) return void 0;
48
+ }
49
+ }
50
+ /**
51
+ * The telemetry packages that do not resolve the way the bundler will resolve
52
+ * them — telescope from the app, and the OpenTelemetry packages from
53
+ * telescope, where a peer is linked under pnpm, which need not be where the
54
+ * app sees it. Empty when every one does.
55
+ */
56
+ function missingTelemetryPackages(appRoot) {
57
+ const telescope = packageDir(appRoot, "@geekmidas/telescope");
58
+ if (!telescope) return ["@geekmidas/telescope", ...TELEMETRY_PACKAGES];
59
+ return TELEMETRY_PACKAGES.filter((pkg) => !packageDir(telescope, pkg));
60
+ }
61
+ /**
62
+ * An app uses a `Telemetry` construct and cannot load what it needs to.
63
+ *
64
+ * Failed at build, not at startup: a process that was given telemetry and
65
+ * quietly ran without it is an outage nobody can see into.
66
+ */
67
+ var TelemetryPackagesMissing = class extends Error {
68
+ app;
69
+ missing;
70
+ dir;
71
+ command;
72
+ constructor(app, missing, dir) {
73
+ const command = `pnpm --dir ${dir || "."} add ${missing.join(" ")}`;
74
+ super(`'${app}' uses a Telemetry construct, and ${missing.join(", ")} ${missing.length === 1 ? "does" : "do"} not resolve from it — its server would start without exporting a span. Add them to the app and build again:\n\n ${command}\n`);
75
+ this.app = app;
76
+ this.missing = missing;
77
+ this.dir = dir;
78
+ this.name = "TelemetryPackagesMissing";
79
+ this.command = command;
80
+ }
81
+ };
82
+ /**
83
+ * The telemetry half of a build context: undefined for a process with no
84
+ * edge to a `Telemetry` node, and — for one with an edge — what its entry
85
+ * starts with, once every package it needs resolves.
86
+ */
87
+ function telemetryFor(options) {
88
+ const { node } = options;
89
+ if (!node) return void 0;
90
+ const missing = missingTelemetryPackages(options.appRoot);
91
+ if (missing.length > 0) throw new TelemetryPackagesMissing(options.app, missing, relative(options.cwd ?? process.cwd(), options.appRoot));
92
+ return {
93
+ serviceName: options.serviceName,
94
+ ...options.workspaceName && { serviceNamespace: options.workspaceName },
95
+ ignorePaths: [...node.ignorePaths ?? []],
96
+ attributes: { ...node.attributes },
97
+ routes: [...options.routes ?? []]
98
+ };
99
+ }
100
+ const HEADER = `/**
101
+ * Generated by gkm, for the production entry and the \`gkm dev\` one alike.
102
+ *
103
+ * Starts OpenTelemetry when OTEL_EXPORTER_OTLP_ENDPOINT names a collector, and
104
+ * does nothing otherwise: without it, the telemetry packages are not loaded.
105
+ * The standard OTEL_* variables (OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG,
106
+ * OTEL_EXPORTER_OTLP_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME)
107
+ * configure the rest.
108
+ */
109
+
110
+ import type { MiddlewareHandler } from 'hono';
111
+
112
+ export interface StartTelemetryOptions {
113
+ /** Requests whose spans would only be noise: health checks, by default. */
114
+ ignorePaths?: string[];
115
+ /**
116
+ * The API's own sites — the origins its CORS allows — read on each request.
117
+ * Their \`traceparent\` is continued, as is an internal caller's; anyone
118
+ * else's starts a new trace linked to the one it claimed.
119
+ */
120
+ trustedOrigins?: () => readonly string[];
121
+ }
122
+ `;
123
+ /** `/users/:id` as a pattern over a request's path. */
124
+ function routePattern(path) {
125
+ return `^${path.split("/").map((segment) => {
126
+ if (segment.startsWith(":")) return "[^/]+";
127
+ if (segment === "*") return ".*";
128
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
129
+ }).join("/")}/?$`;
130
+ }
131
+ /**
132
+ * The entry's `telemetry.ts`: a `startTelemetry()` the server awaits before it
133
+ * imports the app, so the libraries the app loads are instrumented. It returns
134
+ * the Hono middleware that traces each request, or undefined when telemetry is
135
+ * off — the server mounts it ahead of every route.
136
+ *
137
+ * Without a context — a process with no edge to a `Telemetry` node — it is a
138
+ * stub that loads nothing and says nothing: telemetry is not something that
139
+ * process was given.
140
+ *
141
+ * Failing to start telemetry warns (a named `TelemetryUnavailable`, through
142
+ * `process.emitWarning`) and never stops the server: an outage in observability
143
+ * is not a reason to have an outage in the service.
144
+ */
145
+ function generateTelemetryModule(telemetry) {
146
+ if (!telemetry) return `${HEADER}
147
+ // This process has no Telemetry construct, so there is nothing to start.
148
+ export async function startTelemetry(
149
+ _options: StartTelemetryOptions = {},
150
+ ): Promise<MiddlewareHandler | undefined> {
151
+ return undefined;
152
+ }
153
+ `;
154
+ const options = [
155
+ `serviceName: ${JSON.stringify(telemetry.serviceName)},`,
156
+ ...telemetry.serviceNamespace ? [`serviceNamespace: ${JSON.stringify(telemetry.serviceNamespace)},`] : [],
157
+ "deploymentEnvironment: process.env.STAGE,",
158
+ ...Object.keys(telemetry.attributes).length ? [`resourceAttributes: ${JSON.stringify(telemetry.attributes)},`] : [],
159
+ "handleSignals: false,",
160
+ "instrumentPino: false,",
161
+ "incomingHttpSpans: false,"
162
+ ];
163
+ const routes = telemetry.routes.map((route) => ({
164
+ method: route.method.toUpperCase(),
165
+ pattern: routePattern(route.path),
166
+ ...route.ignore ? { ignore: true } : {},
167
+ ...route.attributes && Object.keys(route.attributes).length ? { attributes: route.attributes } : {}
168
+ }));
169
+ const withAttributes = routes.some((route) => "attributes" in route);
170
+ return `${HEADER}
171
+ /** Telemetry was asked for and cannot start. The server runs without it. */
172
+ export class TelemetryUnavailable extends Error {
173
+ constructor(readonly reason: string, options?: { cause?: unknown }) {
174
+ super(
175
+ \`OTEL_EXPORTER_OTLP_ENDPOINT is set, but \${reason} This server exports no traces or logs until that is fixed.\`,
176
+ options,
177
+ );
178
+ this.name = 'TelemetryUnavailable';
179
+ }
180
+ }
181
+
182
+ /** The Telemetry construct's own ignored paths, beside the entry's. */
183
+ const IGNORE_PATHS: string[] = ${JSON.stringify(telemetry.ignorePaths)};
184
+
185
+ /** Each route's own .telemetry({ ignore, attributes }). */
186
+ const ROUTES: {
187
+ method: string;
188
+ pattern: string;
189
+ ignore?: boolean;
190
+ attributes?: Record<string, string>;
191
+ }[] = ${JSON.stringify(routes)};
192
+
193
+ const MATCHERS = ROUTES.map((route) => ({ ...route, regex: new RegExp(route.pattern) }));
194
+
195
+ function routeOf(method: string, path: string) {
196
+ return MATCHERS.find(
197
+ (route) => (route.method === method || route.method === 'ALL' || route.method === 'ANY') && route.regex.test(path),
198
+ );
199
+ }
200
+
201
+ export async function startTelemetry(
202
+ options: StartTelemetryOptions = {},
203
+ ): Promise<MiddlewareHandler | undefined> {
204
+ if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) return undefined;
205
+
206
+ let instrumentation;
207
+ try {
208
+ instrumentation = await import('@geekmidas/telescope/instrumentation');
209
+ } catch (cause) {
210
+ process.emitWarning(
211
+ new TelemetryUnavailable(
212
+ '@geekmidas/telescope/instrumentation or an @opentelemetry package it needs could not be loaded. Install them in the app and rebuild.',
213
+ { cause },
214
+ ),
215
+ );
216
+ return undefined;
217
+ }
218
+
219
+ instrumentation.setupTelemetry({
220
+ ${options.join("\n ")}
221
+ });
222
+
223
+ // Flush what is buffered when the process is told to stop. When nothing
224
+ // else handles the signal, re-raise it once flushed, so the process still
225
+ // stops the way it would have without this listener.
226
+ for (const signal of ['SIGTERM', 'SIGINT'] as const) {
227
+ process.once(signal, () => {
228
+ void instrumentation.flushTelemetry().finally(() => {
229
+ if (process.listenerCount(signal) === 0) process.kill(process.pid, signal);
230
+ });
231
+ });
232
+ }
233
+
234
+ // A SERVER span per request, opened by the app itself rather than by
235
+ // hooking node:http: \`GET /users/:id\`, continuing an incoming traceparent
236
+ // from the API's own sites and internal callers (a new, linked trace from
237
+ // anyone else), with the handler — its logs, fetches and queries — running
238
+ // inside it.
239
+ const spans = instrumentation.honoTelemetryMiddleware({
240
+ ignorePaths: [...(options.ignorePaths ?? []), ...IGNORE_PATHS],
241
+ trustedOrigins: options.trustedOrigins,
242
+ ...(MATCHERS.some((route) => route.ignore)
243
+ ? { shouldSkip: (c) => routeOf(c.req.method, c.req.path)?.ignore === true }
244
+ : {}),
245
+ });
246
+ ${withAttributes ? `
247
+ // A route's own attributes, on the span the middleware just opened.
248
+ const { trace } = await import('@opentelemetry/api');
249
+ return (c, next) =>
250
+ spans(c, async () => {
251
+ const attributes = routeOf(c.req.method, c.req.path)?.attributes;
252
+ if (attributes) trace.getActiveSpan()?.setAttributes(attributes);
253
+ await next();
254
+ });
255
+ ` : ` return spans;
256
+ `}}
257
+ `;
258
+ }
259
+ /**
260
+ * What an entry starts telemetry with, before it imports the app — shared by
261
+ * the production server, a self-serving surface's server and the `gkm dev`
262
+ * entry, so the three cannot start it differently. Defines `requestSpans`.
263
+ */
264
+ function startTelemetryCode(ignorePaths) {
265
+ return `// The API's own sites, known once the app has read its configuration: the
266
+ // origins its CORS allows are the ones whose trace context is continued.
267
+ let trustedOrigins: readonly string[] = [];
268
+
269
+ // Before the app is imported, so the libraries it loads are instrumented.
270
+ const { startTelemetry } = await import('./telemetry.js');
271
+ const requestSpans = await startTelemetry({
272
+ ignorePaths: ${JSON.stringify(ignorePaths)},
273
+ trustedOrigins: () => trustedOrigins,
274
+ });
275
+ `;
276
+ }
277
+ /** Mounts `requestSpans` on `app` ahead of every route. */
278
+ function mountRequestSpansCode(app) {
279
+ return `// The span middleware goes on before any route, so every request runs in it.
280
+ if (requestSpans) ${app}.use('*', requestSpans);
281
+ `;
282
+ }
283
+ /** Writes the entry's `telemetry.ts` beside it. */
284
+ async function writeTelemetryModule(outputDir, telemetry) {
285
+ await mkdir(outputDir, { recursive: true });
286
+ await writeFile(join(outputDir, "telemetry.ts"), generateTelemetryModule(telemetry));
287
+ }
288
+ //#endregion
289
+ //#region src/generators/clientTelemetry.ts
290
+ /** A `sampleRate` outside 0–1, which no sampler can honour. */
291
+ var InvalidClientTelemetrySampleRate = class extends Error {
292
+ sampleRate;
293
+ constructor(sampleRate) {
294
+ super(`The client's telemetry sample rate must be a number from 0 to 1, got ${sampleRate}. Pass the stage's rate, such as 0.1, or leave it out for 1.`);
295
+ this.sampleRate = sampleRate;
296
+ this.name = "InvalidClientTelemetrySampleRate";
297
+ }
298
+ };
299
+ /** The `telemetry` default as the generated module prints it. */
300
+ function printTelemetryDefault(telemetry) {
301
+ if (typeof telemetry === "boolean") return String(telemetry);
302
+ const { sampleRate } = telemetry;
303
+ if (!Number.isFinite(sampleRate) || sampleRate < 0 || sampleRate > 1) throw new InvalidClientTelemetrySampleRate(sampleRate);
304
+ return `{ sampleRate: ${sampleRate} }`;
305
+ }
306
+ /**
307
+ * `--telemetry [rate]` for a client default, as `gkm openapi` takes it — and
308
+ * as a site's Dockerfile passes it to the `gkm openapi --app` it runs.
309
+ */
310
+ function telemetryArgs(telemetry) {
311
+ if (!telemetry) return [];
312
+ if (telemetry === true) return ["--telemetry"];
313
+ return ["--telemetry", String(telemetry.sampleRate)];
314
+ }
315
+ /** What `--telemetry [rate]` parsed to: on, at a rate when one was given. */
316
+ function parseTelemetryFlag(value) {
317
+ if (value === void 0 || value === false) return void 0;
318
+ if (value === true) return true;
319
+ return { sampleRate: Number(value) };
320
+ }
321
+ //#endregion
322
+ //#region src/generators/EndpointGenerator.ts
323
+ /**
324
+ * How a generated entry gets its logger and environment parser.
325
+ *
326
+ * From the surface it serves, when there is one: the surface holds both as
327
+ * *objects*, and discovery already recorded which module declares it, so the
328
+ * entry imports that module and reads them off it.
329
+ *
330
+ * The alternative — the shape this replaces — was naming both in config as
331
+ * module paths, `envParser: './config/env#envParser'`, and printing an import
332
+ * for each. Two strings per app, checked by nothing, describing files the
333
+ * surface was already holding the contents of.
334
+ *
335
+ * Falls back to the configured paths for an app that declares no surface.
336
+ */
337
+ function runtimeFor(context, fromDir, owner) {
338
+ const module = owner ? context.owners?.[owner] ?? context.surface?.module : context.surface?.module;
339
+ if (module) {
340
+ const specifier = importSpecifier(fromDir, module.specifier);
341
+ return {
342
+ imports: `import { ${module.exportName} as __surface } from '${specifier}';`,
343
+ bindings: [
344
+ "// What this construct was declared with. Objects, not module paths:",
345
+ "// the entry imports the owner, so there is nothing to print.",
346
+ "const envParser = __surface.envParser;",
347
+ "const logger = __surface.logger;"
348
+ ].join("\n")
349
+ };
350
+ }
351
+ throw new Error(`No owner to take a logger and an environment parser from${owner ? ` for "${owner}"` : ""}. Build it from a \`RestApi\` or a \`Worker\`.`);
352
+ }
353
+ /** A relative specifier ESM will accept: always prefixed, never bare. */
354
+ function importSpecifier(fromDir, target) {
355
+ const rel = relative(fromDir, target).replace(/\.ts$/, ".js");
356
+ return rel.startsWith(".") ? rel : `./${rel}`;
357
+ }
358
+ /**
359
+ * CORS for a surface, derived rather than hand-written.
360
+ *
361
+ * Who may call a surface is already in the graph — every construct that
362
+ * declared an edge to it — and reaches the process as one comma-separated
363
+ * value. An application that maintained this by hand maintained a list that was
364
+ * wrong in two directions at once: it trusted origins nothing was serving, and
365
+ * it could not name hosts a deploy had not chosen yet.
366
+ *
367
+ * Only the parts a graph cannot answer are configurable, and every one has a
368
+ * default: a surface that says nothing about CORS still gets it.
369
+ */
370
+ function corsFor(surface) {
371
+ if (!surface) return {
372
+ imports: "",
373
+ setup: ""
374
+ };
375
+ const cors = surface.cors ?? {};
376
+ const allowHeaders = [.../* @__PURE__ */ new Set([
377
+ "content-type",
378
+ "authorization",
379
+ "traceparent",
380
+ "tracestate",
381
+ ...cors.allowHeaders ?? []
382
+ ])];
383
+ return {
384
+ imports: `import { cors } from 'hono/cors';`,
385
+ setup: `
386
+ // Who may call ${surface.id}, read off the graph rather than listed here.
387
+ {
388
+ const { origins } = envParser
389
+ .create((get) => ({
390
+ origins: get('${surface.trustedOriginsKey}')
391
+ .string()
392
+ .default('')
393
+ .transform((value: string) =>
394
+ value.split(',').map((origin) => origin.trim()).filter(Boolean),
395
+ ),
396
+ }))
397
+ .parse();
398
+
399
+ // The same origins are the ones whose trace context the request spans
400
+ // continue — the server reads them back from \`createApp\`.
401
+ trustedOrigins.push(...origins);
402
+
403
+ honoApp.use('*', cors({
404
+ origin: origins,
405
+ allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
406
+ allowHeaders: ${JSON.stringify(allowHeaders)},${cors.exposeHeaders ? `\n exposeHeaders: ${JSON.stringify(cors.exposeHeaders)},` : ""}
407
+ credentials: ${cors.credentials ?? true},
408
+ maxAge: ${cors.maxAge ?? 86400},
409
+ }));
410
+ }
411
+ `
412
+ };
413
+ }
414
+ var EndpointGenerator = class extends ConstructGenerator {
415
+ isConstruct(value) {
416
+ return Endpoint.isEndpoint(value);
417
+ }
418
+ async build(context, constructs, outputDir, options) {
419
+ const target = options?.target ?? "aws";
420
+ const root = options?.root ?? process.cwd();
421
+ const enableOpenApi = options?.enableOpenApi || false;
422
+ const logger = console;
423
+ const routes = [];
424
+ if (constructs.length === 0) return routes;
425
+ if (target === "server") {
426
+ await this.generateEndpointsFile(outputDir, constructs);
427
+ const appFile = await this.generateAppFile(outputDir, context);
428
+ routes.push({
429
+ path: "*",
430
+ method: "ALL",
431
+ handler: relative(root, appFile),
432
+ authorizer: "none"
433
+ });
434
+ logger.log(`Generated server with ${constructs.length} endpoints${enableOpenApi ? " (OpenAPI enabled)" : ""}`);
435
+ return routes;
436
+ }
437
+ const routesDir = join(outputDir, "routes");
438
+ await mkdir(routesDir, { recursive: true });
439
+ for (const { key, construct, path } of constructs) {
440
+ const handlerFile = await this.generateHandlerFile(routesDir, path.relative, key, context);
441
+ const routeInfo = {
442
+ path: construct._path,
443
+ method: construct.method,
444
+ handler: relative(root, handlerFile).replace(/\.ts$/, ".handler"),
445
+ timeout: construct.timeout,
446
+ memorySize: construct.memorySize,
447
+ environment: await construct.getEnvironment({ markOptional: context.markOptional }),
448
+ dependencies: construct.constructs,
449
+ authorizer: construct.authorizer?.name ?? "none"
450
+ };
451
+ routes.push(routeInfo);
452
+ logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
453
+ }
454
+ return routes;
455
+ }
456
+ async generateHandlerFile(outputDir, sourceFile, exportName, context) {
457
+ const handlerPath = join(outputDir, `${exportName}.ts`);
458
+ const importPath = relative(dirname(handlerPath), sourceFile).replace(/\.ts$/, ".js");
459
+ await writeFile(handlerPath, this.generateAWSApiGatewayV2Handler(importPath, exportName, context.storageDrivers));
460
+ return handlerPath;
461
+ }
462
+ async generateEndpointsFile(outputDir, endpoints) {
463
+ const endpointsPath = join(outputDir, "endpoints.ts");
464
+ const importsByFile = /* @__PURE__ */ new Map();
465
+ for (const { path, key } of endpoints) {
466
+ const importPath = relative(dirname(endpointsPath), path.relative).replace(/\.ts$/, ".js");
467
+ if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
468
+ importsByFile.get(importPath)?.push(key);
469
+ }
470
+ const content = `import type { EnvironmentParser } from '@geekmidas/envkit';
471
+ import type { Logger } from '@geekmidas/logger';
472
+ import { HonoEndpoint } from '@geekmidas/constructs/hono';
473
+ import { Endpoint } from '@geekmidas/constructs/endpoints';
474
+ import { ServiceDiscovery } from '@geekmidas/services';
475
+ import type { Hono } from 'hono';
476
+ ${Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n")}
477
+
478
+ export const endpoints: Endpoint<any, any, any, any, any, any, any, any, any, any, any, any>[] = [
479
+ ${endpoints.map(({ key }) => key).join(",\n ")}
480
+ ];
481
+
482
+ export async function setupEndpoints(
483
+ app: Hono,
484
+ envParser: EnvironmentParser<any>,
485
+ logger: Logger,
486
+ enableOpenApi: boolean = true,
487
+ ): Promise<void> {
488
+ const serviceDiscovery = ServiceDiscovery.getInstance(envParser);
489
+
490
+ // Configure OpenAPI options based on enableOpenApi flag
491
+ const openApiOptions: any = enableOpenApi ? {
492
+ docsPath: '/__docs',
493
+ openApiOptions: {
494
+ title: 'API Documentation',
495
+ version: '1.0.0',
496
+ description: 'Generated API documentation'
497
+ }
498
+ } : { docsPath: false };
499
+
500
+ HonoEndpoint.addRoutes(endpoints, serviceDiscovery, app, openApiOptions);
501
+
502
+ // Add Swagger UI if OpenAPI is enabled
503
+ if (enableOpenApi) {
504
+ try {
505
+ const { swaggerUI } = await import('@hono/swagger-ui');
506
+ app.get('/__docs/ui', swaggerUI({ url: '/__docs' }));
507
+ } catch {
508
+ // @hono/swagger-ui not installed, skip Swagger UI
509
+ }
510
+ }
511
+ }
512
+ `;
513
+ await writeFile(endpointsPath, content);
514
+ return endpointsPath;
515
+ }
516
+ async generateAppFile(outputDir, context) {
517
+ await writeTelemetryModule(outputDir, context.telemetry);
518
+ if (context.production?.enabled) return this.generateProductionAppFile(outputDir, context);
519
+ const appPath = join(outputDir, "app.ts");
520
+ const runtime = runtimeFor(context, dirname(appPath));
521
+ const telescopeEnabled = context.telescope?.enabled;
522
+ const telescopeWebSocketEnabled = context.telescope?.websocket;
523
+ const usesExternalTelescope = !!context.telescope?.telescopePath;
524
+ const telescopeFromSurface = !!context.surface?.module && !usesExternalTelescope;
525
+ let telescopeImports = "";
526
+ if (telescopeEnabled) {
527
+ if (telescopeFromSurface) telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
528
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
529
+ else if (usesExternalTelescope) {
530
+ const relativeTelescopePath = relative(dirname(appPath), context.telescope?.telescopePath);
531
+ telescopeImports = `import ${context.telescope?.telescopeImportPattern} from '${relativeTelescopePath}';
532
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
533
+ } else telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
534
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
535
+ }
536
+ const databaseApi = context.databaseApi;
537
+ const databaseApiImports = databaseApi ? `import { snifferContext } from '@geekmidas/constructs';
538
+ import { createIntrospectionHandler } from '@geekmidas/db/introspect';
539
+ import { ${databaseApi.database.exportName} as __introspectedDb } from '${importSpecifier(dirname(appPath), databaseApi.database.specifier)}';` : "";
540
+ const cors = corsFor(context.surface);
541
+ let hooksImports = "";
542
+ let beforeSetupCall = "";
543
+ let afterSetupCall = "";
544
+ if (context.hooks?.serverHooksPath) {
545
+ hooksImports = `import * as serverHooks from '${relative(dirname(appPath), context.hooks.serverHooksPath)}';`;
546
+ beforeSetupCall = `
547
+ // Call beforeSetup hook if defined
548
+ if (typeof serverHooks.beforeSetup === 'function') {
549
+ await serverHooks.beforeSetup(honoApp, { envParser, logger });
550
+ }
551
+ `;
552
+ afterSetupCall = `
553
+ // Call afterSetup hook if defined
554
+ if (typeof serverHooks.afterSetup === 'function') {
555
+ await serverHooks.afterSetup(honoApp, { envParser, logger });
556
+ }
557
+ `;
558
+ }
559
+ const telescopeWebSocketSetupCode = telescopeWebSocketEnabled ? `
560
+ // Setup WebSocket for real-time telescope updates
561
+ try {
562
+ const { createNodeWebSocket } = await import('@hono/node-ws');
563
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app: honoApp });
564
+ // Add WebSocket route directly to main app (sub-app routes don't support WS upgrade)
565
+ honoApp.get('${context.telescope?.path}/ws', upgradeWebSocket(() => ({
566
+ onOpen: (_event: Event, ws: any) => {
567
+ telescope.addWsClient(ws);
568
+ },
569
+ onClose: (_event: Event, ws: any) => {
570
+ telescope.removeWsClient(ws);
571
+ },
572
+ onMessage: (event: MessageEvent, ws: any) => {
573
+ try {
574
+ const data = JSON.parse(event.data);
575
+ if (data.type === 'ping') {
576
+ ws.send(JSON.stringify({ type: 'pong' }));
577
+ }
578
+ } catch {
579
+ // Ignore invalid messages
580
+ }
581
+ },
582
+ })));
583
+ // Store injectWebSocket for server entry to call after serve()
584
+ (honoApp as any).__injectWebSocket = injectWebSocket;
585
+ logger.info('Telescope WebSocket enabled');
586
+ } catch (e) {
587
+ logger.warn({ err: e }, 'WebSocket support not available - install @hono/node-ws for real-time updates');
588
+ }
589
+ ` : "";
590
+ let telescopeSetup = "";
591
+ if (telescopeEnabled) {
592
+ if (telescopeFromSurface || usesExternalTelescope) telescopeSetup = `
593
+ ${telescopeWebSocketSetupCode}
594
+ // Add telescope middleware (before endpoints to capture all requests)
595
+ honoApp.use('*', createMiddleware(telescope));
596
+
597
+ // Mount Telescope's JSON API
598
+ const telescopeApi = createApi(telescope);
599
+ honoApp.route('${context.telescope?.path}', telescopeApi);
600
+ `;
601
+ else telescopeSetup = `
602
+ // Setup Telescope for debugging/monitoring
603
+ const telescopeStorage = new InMemoryStorage({ maxEntries: ${context.telescope?.maxEntries} });
604
+ const telescope = new Telescope({
605
+ enabled: true,
606
+ path: '${context.telescope?.path}',
607
+ ignorePatterns: ${JSON.stringify(context.telescope?.ignore)},
608
+ recordBody: ${context.telescope?.recordBody},
609
+ storage: telescopeStorage,
610
+ });
611
+ ${telescopeWebSocketSetupCode}
612
+ // Add telescope middleware (before endpoints to capture all requests)
613
+ honoApp.use('*', createMiddleware(telescope));
614
+
615
+ // Mount Telescope's JSON API
616
+ const telescopeApi = createApi(telescope);
617
+ honoApp.route('${context.telescope?.path}', telescopeApi);
618
+ `;
619
+ }
620
+ const databaseApiSetup = databaseApi ? `
621
+ // The database's structure and rows as JSON, read-only, for whatever tool
622
+ // the developer points at it. Dev only: it answers anyone who can reach the
623
+ // port.
624
+ const databaseApi = createIntrospectionHandler({
625
+ db: await __introspectedDb.service.register({ envParser, context: snifferContext }),
626
+ basePath: '${databaseApi.path}',
627
+ });
628
+ honoApp.all('${databaseApi.path}/*', (c) => databaseApi(c.req.raw));
629
+ ` : "";
630
+ const content = `/**
631
+ * Generated server application
632
+ *
633
+ * ⚠️ WARNING: This is for LOCAL DEVELOPMENT ONLY
634
+ * The subscriber polling mechanism is not production-ready.
635
+ * For production, use AWS Lambda with SQS/SNS event sources.
636
+ */
637
+ import { Hono } from 'hono';
638
+ import type { Hono as HonoType } from 'hono';
639
+ import { setupEndpoints } from './endpoints.js';
640
+ import { setupSubscribers } from './subscribers.js';
641
+ import { setupQueues } from './queues.js';
642
+ import { setupCrons } from './crons.js';
643
+ ${runtime.imports}
644
+ ${telescopeImports}
645
+ ${databaseApiImports}
646
+ ${hooksImports}
647
+ ${cors.imports}
648
+ ${context.storageDrivers?.imports ?? ""}
649
+
650
+ ${runtime.bindings}
651
+ ${telescopeEnabled && telescopeFromSurface ? `// The surface's own Telescope, or the one \`telescope\` config describes.
652
+ const telescope =
653
+ __surface.telescope ??
654
+ new Telescope({
655
+ enabled: true,
656
+ path: '${context.telescope?.path}',
657
+ ignorePatterns: ${JSON.stringify(context.telescope?.ignore)},
658
+ recordBody: ${context.telescope?.recordBody},
659
+ storage: new InMemoryStorage({ maxEntries: ${context.telescope?.maxEntries} }),
660
+ });` : ""}
661
+
662
+ ${context.storageDrivers?.setup ? `// Which drivers exist — storage, cache, events — is the entry point's
663
+ // decision: the scheme in each injected URL picks one, so no construct and no
664
+ // application module names a provider.
665
+ ${context.storageDrivers.setup}
666
+ ` : ""}
667
+ ${context.surface ? `// Who this server is to Postgres: application_name on every connection.
668
+ process.env.GKM_APP_NAME ??= ${JSON.stringify(context.surface.id)};
669
+
670
+ ` : ""}export interface ServerApp {
671
+ app: HonoType;
672
+ /** The origins this API's CORS allows: its own sites. */
673
+ trustedOrigins: readonly string[];
674
+ start: (options?: {
675
+ port?: number;
676
+ /** Returns the server, so a shutdown can stop it taking requests. */
677
+ serve: (app: HonoType, port: number) => unknown;
678
+ }) => Promise<void>;
679
+ }
680
+
681
+ /**
682
+ * Create and configure the Hono application
683
+ *
684
+ * @param app - Optional Hono app instance to configure (creates new one if not provided)
685
+ * @param enableOpenApi - Enable OpenAPI documentation (default: true)
686
+ * @returns Server app with configured Hono app and start function
687
+ *
688
+ * @example
689
+ * // With Bun
690
+ * import { createApp } from './.gkm/server/app.js';
691
+ *
692
+ * const { app, start } = await createApp();
693
+ *
694
+ * await start({
695
+ * port: 3000,
696
+ * serve: (app, port) => {
697
+ * Bun.serve({ port, fetch: app.fetch });
698
+ * }
699
+ * });
700
+ *
701
+ * @example
702
+ * // With Node.js (using @hono/node-server)
703
+ * import { serve } from '@hono/node-server';
704
+ * import { createApp } from './.gkm/server/app.js';
705
+ *
706
+ * const { app, start } = await createApp();
707
+ *
708
+ * await start({
709
+ * port: 3000,
710
+ * serve: (app, port) => {
711
+ * serve({ fetch: app.fetch, port });
712
+ * }
713
+ * });
714
+ */
715
+ export async function createApp(app?: HonoType, enableOpenApi: boolean = true): Promise<ServerApp> {
716
+ const honoApp = app || new Hono();
717
+ const trustedOrigins: string[] = [];
718
+ ${telescopeSetup}${cors.setup}${beforeSetupCall}${databaseApiSetup}
719
+ // Setup HTTP endpoints
720
+ await setupEndpoints(honoApp, envParser, logger, enableOpenApi);
721
+ ${afterSetupCall}
722
+
723
+ return {
724
+ app: honoApp,
725
+ trustedOrigins,
726
+ async start(options) {
727
+ if (!options?.serve) {
728
+ throw new Error(
729
+ 'serve function is required. Pass a serve function for your runtime:\\n' +
730
+ ' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\n' +
731
+ ' - Node: (app, port) => serve({ fetch: app.fetch, port })'
732
+ );
733
+ }
734
+
735
+ const port = options.port ?? 3000;
736
+
737
+ // Mount pushed subscribers' routes and start polled ones. What comes
738
+ // back subscribes the routes, once the server can answer them.
739
+ const subscribeForPush = await setupSubscribers(honoApp, envParser, logger).catch((error) => {
740
+ logger.error({ err: error }, 'Failed to start subscribers');
741
+ return async (_port: number) => {};
742
+ });
743
+
744
+ // Start queue workers in background (non-blocking, local development only)
745
+ await setupQueues(envParser, logger).catch((error) => {
746
+ logger.error({ err: error }, 'Failed to start queue workers');
747
+ });
748
+
749
+ // Schedule this app's crons. Caught like the others: a scheduler that
750
+ // cannot start is not a reason for the HTTP server not to.
751
+ await setupCrons(envParser, logger).catch((error) => {
752
+ logger.error({ err: error }, 'Failed to schedule crons');
753
+ });
754
+
755
+ logger.info({ port }, 'Starting server');
756
+
757
+ // Start HTTP server using provided serve function
758
+ await options.serve(honoApp, port);
759
+
760
+ logger.info({ port }, 'Server started');
761
+
762
+ await subscribeForPush(port);
763
+ }
764
+ };
765
+ }
766
+
767
+ // Default export for convenience
768
+ export default createApp;
769
+ `;
770
+ await writeFile(appPath, content);
771
+ return appPath;
772
+ }
773
+ /**
774
+ * One Lambda, one endpoint — and no environment import.
775
+ *
776
+ * The endpoint was built from its surface, so it carries the parser the
777
+ * adaptor needs. This used to read
778
+ * `import { envParser } from '../../config/env'`, a line the build wrote
779
+ * because a generator can print a module specifier and cannot print an
780
+ * object. Nothing has to be printed now, which is also why nothing has to be
781
+ * named in config.
782
+ */
783
+ generateAWSApiGatewayV2Handler(importPath, exportName, drivers) {
784
+ return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/constructs/aws';
785
+ import { ${exportName} } from '${importPath}';
786
+ ${drivers?.imports ?? ""}
787
+ ${drivers?.setup ? `\n// The handler registers the drivers its target needs.\n${drivers.setup}\n` : ""}
788
+ const adapter = new AmazonApiGatewayV2Endpoint(${exportName});
789
+
790
+ export const handler = adapter.handler;
791
+ `;
792
+ }
793
+ /**
794
+ * Generate a production-optimized app.ts file
795
+ * No dev tools (Telescope, Studio, WebSocket), includes health checks and graceful shutdown
796
+ */
797
+ async generateProductionAppFile(outputDir, context) {
798
+ const appPath = join(outputDir, "app.ts");
799
+ const runtime = runtimeFor(context, dirname(appPath));
800
+ const production = context.production;
801
+ const healthCheckPath = production.healthCheck;
802
+ const enableGracefulShutdown = production.gracefulShutdown;
803
+ const enableOpenApi = production.openapi;
804
+ const includeSubscribers = production.subscribers === "include";
805
+ const cors = corsFor(context.surface);
806
+ let hooksImports = "";
807
+ let beforeSetupCall = "";
808
+ let afterSetupCall = "";
809
+ if (context.hooks?.serverHooksPath) {
810
+ hooksImports = `import * as serverHooks from '${relative(dirname(appPath), context.hooks.serverHooksPath)}';`;
811
+ beforeSetupCall = `
812
+ // Call beforeSetup hook if defined
813
+ if (typeof serverHooks.beforeSetup === 'function') {
814
+ await serverHooks.beforeSetup(honoApp, { envParser, logger });
815
+ }
816
+ `;
817
+ afterSetupCall = `
818
+ // Call afterSetup hook if defined
819
+ if (typeof serverHooks.afterSetup === 'function') {
820
+ await serverHooks.afterSetup(honoApp, { envParser, logger });
821
+ }
822
+ `;
823
+ }
824
+ const subscriberSetup = includeSubscribers ? `
825
+ // Mount pushed subscribers' routes and start polled ones. What comes
826
+ // back subscribes the routes, once the server can answer them.
827
+ const subscribeForPush = await setupSubscribers(honoApp, envParser, logger).catch((error) => {
828
+ logger.error({ err: error }, 'Failed to start subscribers');
829
+ return async (_port: number) => {};
830
+ });
831
+
832
+ // Start queue workers in background
833
+ await setupQueues(envParser, logger).catch((error) => {
834
+ logger.error({ err: error }, 'Failed to start queue workers');
835
+ });
836
+
837
+ // Schedule this app's crons. Caught like the others: a scheduler that
838
+ // cannot start is not a reason for the HTTP server not to.
839
+ await setupCrons(envParser, logger).catch((error) => {
840
+ logger.error({ err: error }, 'Failed to schedule crons');
841
+ });
842
+ ` : "";
843
+ const subscriberImport = includeSubscribers ? `import { setupSubscribers } from './subscribers.js';
844
+ import { setupQueues } from './queues.js';
845
+ import { setupCrons } from './crons.js';` : "";
846
+ const gracefulShutdownCode = enableGracefulShutdown ? `
847
+ // Graceful shutdown: stop taking requests, let in-flight ones finish, then
848
+ // close what constructs opened (database pools) — so a rolling deploy does
849
+ // not leave the old task holding connections. Bounded by
850
+ // GKM_SHUTDOWN_TIMEOUT_MS, 8s by default: under Docker's 10s stop timeout,
851
+ // so the process exits on its own terms rather than being killed mid-drain.
852
+ let isShuttingDown = false;
853
+
854
+ const shutdown = async () => {
855
+ if (isShuttingDown) return;
856
+ isShuttingDown = true;
857
+ const deadline = Number(process.env.GKM_SHUTDOWN_TIMEOUT_MS) || 8000;
858
+ logger.info({ deadline }, 'Graceful shutdown initiated');
859
+ setTimeout(() => {
860
+ logger.warn({ deadline }, 'Shutdown deadline reached, exiting');
861
+ process.exit(1);
862
+ }, deadline).unref();
863
+ await new Promise<void>((resolve) => {
864
+ const close = (server as { close?: (done: () => void) => void } | undefined)?.close;
865
+ if (typeof close === 'function') close.call(server, () => resolve());
866
+ else resolve();
867
+ });
868
+ await runShutdownHooks((error) => logger.error({ err: error }, 'Shutdown hook failed'));
869
+ process.exit(0);
870
+ };
871
+
872
+ process.on('SIGTERM', shutdown);
873
+ process.on('SIGINT', shutdown);
874
+ ` : "";
875
+ const content = `/**
876
+ * Generated production server application
877
+ *
878
+ * This is a production-optimized build without dev tools.
879
+ * - No Telescope debugging dashboard
880
+ * - No Studio database browser
881
+ * - No WebSocket updates
882
+ * - Includes health checks and graceful shutdown
883
+ */
884
+ import { Hono } from 'hono';
885
+ import type { Hono as HonoType } from 'hono';
886
+ ${enableGracefulShutdown ? "import { runShutdownHooks } from '@geekmidas/constructs';\n" : ""}import { setupEndpoints } from './endpoints.js';
887
+ ${subscriberImport}
888
+ ${runtime.imports}
889
+ ${runtime.bindings}
890
+ ${hooksImports}
891
+ ${cors.imports}
892
+ ${context.storageDrivers?.imports ?? ""}
893
+
894
+ ${context.storageDrivers?.setup ? `// The entry point registers the drivers its target needs.
895
+ ${context.storageDrivers.setup}
896
+ ` : ""}
897
+ ${context.surface ? `// Who this server is to Postgres: application_name on every connection.
898
+ process.env.GKM_APP_NAME ??= ${JSON.stringify(context.surface.id)};
899
+
900
+ ` : ""}export interface ServerApp {
901
+ app: HonoType;
902
+ /** The origins this API's CORS allows: its own sites. */
903
+ trustedOrigins: readonly string[];
904
+ start: (options?: {
905
+ port?: number;
906
+ serve: (app: HonoType, port: number) => void | Promise<void>;
907
+ }) => Promise<void>;
908
+ }
909
+
910
+ /**
911
+ * Create and configure the production Hono application
912
+ */
913
+ export async function createApp(app?: HonoType): Promise<ServerApp> {
914
+ const honoApp = app || new Hono();
915
+ const trustedOrigins: string[] = [];
916
+
917
+ // Health check endpoint (always first)
918
+ honoApp.get('${healthCheckPath}', (c) => c.json({ status: 'ok', timestamp: Date.now() }));
919
+ honoApp.get('/ready', (c) => c.json({ ready: true }));
920
+
921
+ // An HttpError a handler or a session callback throws — a 401, a 404 —
922
+ // answers with its own status, as it does under gkm dev. The optimized
923
+ // handlers do not catch, so without this every one of them was a 500.
924
+ // Anything else is a 500 that says nothing about why, and is logged.
925
+ honoApp.onError((error, c) => {
926
+ const http = error as {
927
+ isHttpError?: boolean;
928
+ statusCode?: number;
929
+ statusMessage?: string;
930
+ code?: string;
931
+ details?: unknown;
932
+ };
933
+ if (http.isHttpError === true && typeof http.statusCode === 'number') {
934
+ return c.json(
935
+ {
936
+ name: error.name,
937
+ message: error.message,
938
+ statusCode: http.statusCode,
939
+ statusMessage: http.statusMessage,
940
+ code: http.code,
941
+ details: http.details,
942
+ },
943
+ http.statusCode as 500,
944
+ );
945
+ }
946
+ logger.error({ err: error }, 'Unhandled error');
947
+ return c.json({ message: 'Internal Server Error' }, 500);
948
+ });
949
+ ${cors.setup}${beforeSetupCall}
950
+ // Setup HTTP endpoints (OpenAPI: ${enableOpenApi})
951
+ await setupEndpoints(honoApp, envParser, logger, ${enableOpenApi});
952
+ ${afterSetupCall}
953
+ return {
954
+ app: honoApp,
955
+ trustedOrigins,
956
+ async start(options) {
957
+ if (!options?.serve) {
958
+ throw new Error(
959
+ 'serve function is required. Pass a serve function for your runtime:\\n' +
960
+ ' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\n' +
961
+ ' - Node: (app, port) => serve({ fetch: app.fetch, port })'
962
+ );
963
+ }
964
+
965
+ const port = options.port ?? Number(process.env.PORT) ?? 3000;
966
+ let server: unknown;
967
+ ${gracefulShutdownCode}${subscriberSetup}
968
+ logger.info({ port }, 'Starting production server');
969
+
970
+ // Start HTTP server using provided serve function
971
+ server = await options.serve(honoApp, port);
972
+
973
+ logger.info({ port }, 'Production server started');
974
+ ${includeSubscribers ? "\n await subscribeForPush(port);" : ""}
975
+ }
976
+ };
977
+ }
978
+
979
+ // Default export for convenience
980
+ export default createApp;
981
+ `;
982
+ await writeFile(appPath, content);
983
+ await this.generateProductionServerEntry(outputDir, context);
984
+ return appPath;
985
+ }
986
+ /**
987
+ * Generate production server.ts entry point
988
+ */
989
+ async generateProductionServerEntry(outputDir, context) {
990
+ const serverPath = join(outputDir, "server.ts");
991
+ const content = `#!/usr/bin/env node
992
+ /**
993
+ * Production server entry point
994
+ * Generated by 'gkm build --production'
995
+ */
996
+ import { serve } from '@hono/node-server';
997
+ import { Hono } from 'hono';
998
+
999
+ ${startTelemetryCode([context.production?.healthCheck ?? "/health", "/ready"])}
1000
+ const { createApp } = await import('./app.js');
1001
+
1002
+ const port = Number(process.env.PORT) || 3000;
1003
+
1004
+ const app = new Hono();
1005
+ ${mountRequestSpansCode("app")}
1006
+ const created = await createApp(app);
1007
+ trustedOrigins = created.trustedOrigins;
1008
+ const { start } = created;
1009
+
1010
+ await start({
1011
+ port,
1012
+ serve: (app, port) => serve({ fetch: app.fetch, port }),
1013
+ });
1014
+ `;
1015
+ await writeFile(serverPath, content);
1016
+ }
1017
+ };
1018
+ //#endregion
1019
+ export { telemetryArgs as a, startTelemetryCode as c, printTelemetryDefault as i, telemetryFor as l, runtimeFor as n, mountRequestSpansCode as o, parseTelemetryFlag as r, routeTelemetry as s, EndpointGenerator as t, writeTelemetryModule as u };
1020
+
1021
+ //# sourceMappingURL=EndpointGenerator-CVc6Oi1Y.mjs.map