@geekmidas/cli 10.0.0-alpha.19 → 10.0.0-alpha.190

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 (436) hide show
  1. package/README.md +323 -380
  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-CBKH87_b.mjs +1043 -0
  7. package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
  8. package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
  9. package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
  10. package/dist/LegacyStateStore-CWiswz6T.mjs +124 -0
  11. package/dist/LegacyStateStore-CWiswz6T.mjs.map +1 -0
  12. package/dist/LegacyStateStore-CuSe37fl.cjs +124 -0
  13. package/dist/LegacyStateStore-CuSe37fl.cjs.map +1 -0
  14. package/dist/LocalStateStore-BciJ_DF0.cjs +178 -0
  15. package/dist/LocalStateStore-BciJ_DF0.cjs.map +1 -0
  16. package/dist/LocalStateStore-CLHasLJI.mjs +167 -0
  17. package/dist/LocalStateStore-CLHasLJI.mjs.map +1 -0
  18. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
  19. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
  20. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
  21. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
  22. package/dist/S3StateStore-BHLRjoj3.cjs +222 -0
  23. package/dist/S3StateStore-BHLRjoj3.cjs.map +1 -0
  24. package/dist/S3StateStore-CTiv2_ON.mjs +223 -0
  25. package/dist/S3StateStore-CTiv2_ON.mjs.map +1 -0
  26. package/dist/SSMStateStore-BqT3MXXb.cjs +204 -0
  27. package/dist/SSMStateStore-BqT3MXXb.cjs.map +1 -0
  28. package/dist/SSMStateStore-D6qqaem2.mjs +205 -0
  29. package/dist/SSMStateStore-D6qqaem2.mjs.map +1 -0
  30. package/dist/SubscriberGenerator-Cfoz8uTY.mjs +787 -0
  31. package/dist/SubscriberGenerator-Cfoz8uTY.mjs.map +1 -0
  32. package/dist/SubscriberGenerator-CxzECrfj.cjs +852 -0
  33. package/dist/SubscriberGenerator-CxzECrfj.cjs.map +1 -0
  34. package/dist/add-B2OmIQzs.cjs +712 -0
  35. package/dist/add-B2OmIQzs.cjs.map +1 -0
  36. package/dist/add-CXwL549o.mjs +710 -0
  37. package/dist/add-CXwL549o.mjs.map +1 -0
  38. package/dist/appPorts-BoXMwolc.mjs +249 -0
  39. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  40. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  41. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  42. package/dist/aws-BXfiWNbi.cjs +108 -0
  43. package/dist/aws-BXfiWNbi.cjs.map +1 -0
  44. package/dist/aws-BjvSTTcE.mjs +97 -0
  45. package/dist/aws-BjvSTTcE.mjs.map +1 -0
  46. package/dist/awsStore-BYYCmXiq.mjs +121 -0
  47. package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
  48. package/dist/awsStore-DKQUElJL.cjs +138 -0
  49. package/dist/awsStore-DKQUElJL.cjs.map +1 -0
  50. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  51. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  52. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  53. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  54. package/dist/backups/runner.cjs +1007 -0
  55. package/dist/backups/runner.cjs.map +1 -0
  56. package/dist/backups/runner.d.cts +187 -0
  57. package/dist/backups/runner.d.cts.map +1 -0
  58. package/dist/backups/runner.d.mts +187 -0
  59. package/dist/backups/runner.d.mts.map +1 -0
  60. package/dist/backups/runner.mjs +984 -0
  61. package/dist/backups/runner.mjs.map +1 -0
  62. package/dist/{bundler-mwH7WOb1.mjs → bundler-CHXyJFsS.mjs} +68 -15
  63. package/dist/bundler-CHXyJFsS.mjs.map +1 -0
  64. package/dist/{bundler-mjqGAvu1.cjs → bundler-CLoVtcBi.cjs} +67 -14
  65. package/dist/bundler-CLoVtcBi.cjs.map +1 -0
  66. package/dist/cli-Bjua3PaZ.mjs +80 -0
  67. package/dist/cli-Bjua3PaZ.mjs.map +1 -0
  68. package/dist/cli-DiuUr1Am.cjs +80 -0
  69. package/dist/cli-DiuUr1Am.cjs.map +1 -0
  70. package/dist/clientTelemetry-DXuYNH-J.d.cts +10 -0
  71. package/dist/clientTelemetry-DXuYNH-J.d.cts.map +1 -0
  72. package/dist/clientTelemetry-eC8VQ6nB.d.mts +10 -0
  73. package/dist/clientTelemetry-eC8VQ6nB.d.mts.map +1 -0
  74. package/dist/compose-DUOETDhc.mjs +2855 -0
  75. package/dist/compose-DUOETDhc.mjs.map +1 -0
  76. package/dist/compose-gnNrY3NQ.cjs +2939 -0
  77. package/dist/compose-gnNrY3NQ.cjs.map +1 -0
  78. package/dist/config-1zirYXeO.d.mts +300 -0
  79. package/dist/config-1zirYXeO.d.mts.map +1 -0
  80. package/dist/config-rSlB-bXj.d.cts +300 -0
  81. package/dist/config-rSlB-bXj.d.cts.map +1 -0
  82. package/dist/config.cjs +462 -9
  83. package/dist/config.cjs.map +1 -0
  84. package/dist/config.d.cts +4 -117
  85. package/dist/config.d.mts +4 -117
  86. package/dist/config.mjs +446 -3
  87. package/dist/config.mjs.map +1 -0
  88. package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
  89. package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
  90. package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
  91. package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
  92. package/dist/credentials-BI52H1ad.cjs +2911 -0
  93. package/dist/credentials-BI52H1ad.cjs.map +1 -0
  94. package/dist/credentials-Cp09PIsc.cjs +1451 -0
  95. package/dist/credentials-Cp09PIsc.cjs.map +1 -0
  96. package/dist/credentials-DbjLhvix.mjs +1140 -0
  97. package/dist/credentials-DbjLhvix.mjs.map +1 -0
  98. package/dist/credentials-VLP_959f.mjs +2390 -0
  99. package/dist/credentials-VLP_959f.mjs.map +1 -0
  100. package/dist/databases-CV22HzrI.mjs +588 -0
  101. package/dist/databases-CV22HzrI.mjs.map +1 -0
  102. package/dist/databases-DwYYH2mX.cjs +703 -0
  103. package/dist/databases-DwYYH2mX.cjs.map +1 -0
  104. package/dist/dbTunnel-CLsqWr7o.mjs +153 -0
  105. package/dist/dbTunnel-CLsqWr7o.mjs.map +1 -0
  106. package/dist/dbTunnel-DQcdaaLi.cjs +153 -0
  107. package/dist/dbTunnel-DQcdaaLi.cjs.map +1 -0
  108. package/dist/define-BfrNaY82.mjs +106 -0
  109. package/dist/define-BfrNaY82.mjs.map +1 -0
  110. package/dist/define-zKgLY65H.cjs +153 -0
  111. package/dist/define-zKgLY65H.cjs.map +1 -0
  112. package/dist/deploy/public.cjs +210 -0
  113. package/dist/deploy/public.cjs.map +1 -0
  114. package/dist/deploy/public.d.cts +659 -0
  115. package/dist/deploy/public.d.cts.map +1 -0
  116. package/dist/deploy/public.d.mts +659 -0
  117. package/dist/deploy/public.d.mts.map +1 -0
  118. package/dist/deploy/public.mjs +143 -0
  119. package/dist/deploy/public.mjs.map +1 -0
  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 +1 -1
  127. package/dist/deploy/sniffer-hooks.mjs +1 -1
  128. package/dist/deploy/sniffer-loader.cjs +2 -2
  129. package/dist/deploy/sniffer-loader.mjs +1 -1
  130. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  131. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  132. package/dist/deploy-DhIy2Ftj.mjs +3854 -0
  133. package/dist/deploy-DhIy2Ftj.mjs.map +1 -0
  134. package/dist/deploy-DpQ_4Pu1.cjs +3910 -0
  135. package/dist/deploy-DpQ_4Pu1.cjs.map +1 -0
  136. package/dist/destroy-DmTDT6V7.cjs +791 -0
  137. package/dist/destroy-DmTDT6V7.cjs.map +1 -0
  138. package/dist/destroy-wV9yNLQV.mjs +790 -0
  139. package/dist/destroy-wV9yNLQV.mjs.map +1 -0
  140. package/dist/discover-Dfmn6HQ7.mjs +940 -0
  141. package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
  142. package/dist/discover-OXczlq08.cjs +1085 -0
  143. package/dist/discover-OXczlq08.cjs.map +1 -0
  144. package/dist/dokploy-B61ww4Yb.cjs +38 -0
  145. package/dist/dokploy-B61ww4Yb.cjs.map +1 -0
  146. package/dist/dokploy-Jhl3sPd4.mjs +38 -0
  147. package/dist/dokploy-Jhl3sPd4.mjs.map +1 -0
  148. package/dist/drivers-BQRb3KsL.mjs +294 -0
  149. package/dist/drivers-BQRb3KsL.mjs.map +1 -0
  150. package/dist/drivers-DP7__dJX.cjs +377 -0
  151. package/dist/drivers-DP7__dJX.cjs.map +1 -0
  152. package/dist/eas-BmvO40xS.mjs +334 -0
  153. package/dist/eas-BmvO40xS.mjs.map +1 -0
  154. package/dist/eas-X09Gz8_E.cjs +337 -0
  155. package/dist/eas-X09Gz8_E.cjs.map +1 -0
  156. package/dist/emit-C4KSXOeS.mjs +153 -0
  157. package/dist/emit-C4KSXOeS.mjs.map +1 -0
  158. package/dist/emit-DiW0kbue.cjs +164 -0
  159. package/dist/emit-DiW0kbue.cjs.map +1 -0
  160. package/dist/encryption-BBIUewnL.cjs +90 -0
  161. package/dist/encryption-BBIUewnL.cjs.map +1 -0
  162. package/dist/encryption-BOmswIgE.mjs +89 -0
  163. package/dist/encryption-BOmswIgE.mjs.map +1 -0
  164. package/dist/engine-BhjhShKf.cjs +3333 -0
  165. package/dist/engine-BhjhShKf.cjs.map +1 -0
  166. package/dist/engine-DW2H3KNa.mjs +3220 -0
  167. package/dist/engine-DW2H3KNa.mjs.map +1 -0
  168. package/dist/errors-C9uIyIDt.mjs +27 -0
  169. package/dist/errors-C9uIyIDt.mjs.map +1 -0
  170. package/dist/errors-D1x8duqI.cjs +38 -0
  171. package/dist/errors-D1x8duqI.cjs.map +1 -0
  172. package/dist/github-Ptbigbrq.mjs +986 -0
  173. package/dist/github-Ptbigbrq.mjs.map +1 -0
  174. package/dist/github-xUtu4Ur7.cjs +987 -0
  175. package/dist/github-xUtu4Ur7.cjs.map +1 -0
  176. package/dist/googlePlay-B4xhz5xT.cjs +931 -0
  177. package/dist/googlePlay-B4xhz5xT.cjs.map +1 -0
  178. package/dist/googlePlay-C9rrwN5b.mjs +931 -0
  179. package/dist/googlePlay-C9rrwN5b.mjs.map +1 -0
  180. package/dist/iam-D7mXd6by.cjs +521 -0
  181. package/dist/iam-D7mXd6by.cjs.map +1 -0
  182. package/dist/iam-DNlbVN_l.mjs +442 -0
  183. package/dist/iam-DNlbVN_l.mjs.map +1 -0
  184. package/dist/{index-RCUizGxL.d.cts → index-B1gfXH5K.d.mts} +38 -14
  185. package/dist/index-B1gfXH5K.d.mts.map +1 -0
  186. package/dist/{index-B4H4XF7A.d.mts → index-CunkOPOu.d.cts} +38 -14
  187. package/dist/index-CunkOPOu.d.cts.map +1 -0
  188. package/dist/index.cjs +15566 -13457
  189. package/dist/index.cjs.map +1 -1
  190. package/dist/index.mjs +15249 -13138
  191. package/dist/index.mjs.map +1 -1
  192. package/dist/local-CvC-z86k.mjs +224 -0
  193. package/dist/local-CvC-z86k.mjs.map +1 -0
  194. package/dist/local-DAJrhvSC.cjs +241 -0
  195. package/dist/local-DAJrhvSC.cjs.map +1 -0
  196. package/dist/migrate-0-A4BOcd.cjs +272 -0
  197. package/dist/migrate-0-A4BOcd.cjs.map +1 -0
  198. package/dist/migrate-C_36JSwV.mjs +181 -0
  199. package/dist/migrate-C_36JSwV.mjs.map +1 -0
  200. package/dist/migrate-DHbXzZIJ.mjs +267 -0
  201. package/dist/migrate-DHbXzZIJ.mjs.map +1 -0
  202. package/dist/migrate-fGWfv2DV.cjs +181 -0
  203. package/dist/migrate-fGWfv2DV.cjs.map +1 -0
  204. package/dist/next.cjs +59 -0
  205. package/dist/next.cjs.map +1 -0
  206. package/dist/next.d.cts +44 -0
  207. package/dist/next.d.cts.map +1 -0
  208. package/dist/next.d.mts +44 -0
  209. package/dist/next.d.mts.map +1 -0
  210. package/dist/next.mjs +58 -0
  211. package/dist/next.mjs.map +1 -0
  212. package/dist/openapi.cjs +213 -7
  213. package/dist/openapi.cjs.map +1 -0
  214. package/dist/openapi.d.cts +27 -8
  215. package/dist/openapi.d.cts.map +1 -1
  216. package/dist/openapi.d.mts +27 -8
  217. package/dist/openapi.d.mts.map +1 -1
  218. package/dist/openapi.mjs +208 -2
  219. package/dist/openapi.mjs.map +1 -0
  220. package/dist/projectBucket-BAoFOQtA.cjs +263 -0
  221. package/dist/projectBucket-BAoFOQtA.cjs.map +1 -0
  222. package/dist/projectBucket-Dxub09V1.mjs +222 -0
  223. package/dist/projectBucket-Dxub09V1.mjs.map +1 -0
  224. package/dist/provider-BvjDbsTR.mjs +46 -0
  225. package/dist/provider-BvjDbsTR.mjs.map +1 -0
  226. package/dist/provider-DLhgo-mB.cjs +57 -0
  227. package/dist/provider-DLhgo-mB.cjs.map +1 -0
  228. package/dist/publish-BX8_zXaf.cjs +124 -0
  229. package/dist/publish-BX8_zXaf.cjs.map +1 -0
  230. package/dist/publish-DE_yBzlz.mjs +123 -0
  231. package/dist/publish-DE_yBzlz.mjs.map +1 -0
  232. package/dist/ready-DCvnFZnJ.cjs +404 -0
  233. package/dist/ready-DCvnFZnJ.cjs.map +1 -0
  234. package/dist/ready-sSPuiZ7N.mjs +375 -0
  235. package/dist/ready-sSPuiZ7N.mjs.map +1 -0
  236. package/dist/reconcile/public.cjs +3 -5
  237. package/dist/reconcile/public.d.cts +33 -89
  238. package/dist/reconcile/public.d.cts.map +1 -1
  239. package/dist/reconcile/public.d.mts +33 -89
  240. package/dist/reconcile/public.d.mts.map +1 -1
  241. package/dist/reconcile/public.mjs +3 -3
  242. package/dist/reconcile--I7V4Klj.mjs +34 -0
  243. package/dist/reconcile--I7V4Klj.mjs.map +1 -0
  244. package/dist/reconcile-CuCQBa5-.cjs +34 -0
  245. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  246. package/dist/resolve-CPB2jkB4.cjs +316 -0
  247. package/dist/resolve-CPB2jkB4.cjs.map +1 -0
  248. package/dist/resolve-DCPtP7-X.mjs +263 -0
  249. package/dist/resolve-DCPtP7-X.mjs.map +1 -0
  250. package/dist/rollback-sefKrjlE.mjs +137 -0
  251. package/dist/rollback-sefKrjlE.mjs.map +1 -0
  252. package/dist/rollback-ygh2qRWo.cjs +166 -0
  253. package/dist/rollback-ygh2qRWo.cjs.map +1 -0
  254. package/dist/runtime-BwiWhqkI.d.cts +82 -0
  255. package/dist/runtime-BwiWhqkI.d.cts.map +1 -0
  256. package/dist/runtime-Dx5F8-IL.d.mts +82 -0
  257. package/dist/runtime-Dx5F8-IL.d.mts.map +1 -0
  258. package/dist/s3-Bcvbg8io.cjs +240 -0
  259. package/dist/s3-Bcvbg8io.cjs.map +1 -0
  260. package/dist/s3-DK1ofU4f.mjs +240 -0
  261. package/dist/s3-DK1ofU4f.mjs.map +1 -0
  262. package/dist/sandbox/config-worker.cjs +43 -0
  263. package/dist/sandbox/config-worker.cjs.map +1 -0
  264. package/dist/sandbox/config-worker.d.cts +1 -0
  265. package/dist/sandbox/config-worker.d.mts +1 -0
  266. package/dist/sandbox/config-worker.mjs +44 -0
  267. package/dist/sandbox/config-worker.mjs.map +1 -0
  268. package/dist/sandbox/credentials-worker.cjs +53 -0
  269. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  270. package/dist/sandbox/credentials-worker.d.cts +1 -0
  271. package/dist/sandbox/credentials-worker.d.mts +1 -0
  272. package/dist/sandbox/credentials-worker.mjs +54 -0
  273. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  274. package/dist/sandbox/discover-worker.cjs +47 -0
  275. package/dist/sandbox/discover-worker.cjs.map +1 -0
  276. package/dist/sandbox/discover-worker.d.cts +1 -0
  277. package/dist/sandbox/discover-worker.d.mts +1 -0
  278. package/dist/sandbox/discover-worker.mjs +48 -0
  279. package/dist/sandbox/discover-worker.mjs.map +1 -0
  280. package/dist/sandbox/migrate-worker.cjs +75 -0
  281. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  282. package/dist/sandbox/migrate-worker.d.cts +1 -0
  283. package/dist/sandbox/migrate-worker.d.mts +1 -0
  284. package/dist/sandbox/migrate-worker.mjs +76 -0
  285. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  286. package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
  287. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  288. package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
  289. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  290. package/dist/secretsManager-CjTo6CRq.mjs +113 -0
  291. package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
  292. package/dist/secretsManager-CvmBGjdM.cjs +124 -0
  293. package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
  294. package/dist/seeds-Bc3niNVb.cjs +382 -0
  295. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  296. package/dist/seeds-Ccn0Ru2T.mjs +299 -0
  297. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  298. package/dist/serverSetup-ClU2iSeU.cjs +686 -0
  299. package/dist/serverSetup-ClU2iSeU.cjs.map +1 -0
  300. package/dist/serverSetup-D68Otrp0.mjs +686 -0
  301. package/dist/serverSetup-D68Otrp0.mjs.map +1 -0
  302. package/dist/sniffer-CFOmQQit.cjs +1997 -0
  303. package/dist/sniffer-CFOmQQit.cjs.map +1 -0
  304. package/dist/sniffer-CRF3eD_B.mjs +1824 -0
  305. package/dist/sniffer-CRF3eD_B.mjs.map +1 -0
  306. package/dist/snsSubscriptions-CwA6Ceg2.mjs +1024 -0
  307. package/dist/snsSubscriptions-CwA6Ceg2.mjs.map +1 -0
  308. package/dist/snsSubscriptions-S_CMCXqI.cjs +1149 -0
  309. package/dist/snsSubscriptions-S_CMCXqI.cjs.map +1 -0
  310. package/dist/sst-BgG7dJJu.cjs +514 -0
  311. package/dist/sst-BgG7dJJu.cjs.map +1 -0
  312. package/dist/sst-CDnHFO3U.mjs +491 -0
  313. package/dist/sst-CDnHFO3U.mjs.map +1 -0
  314. package/dist/stack-BXmLQf3K.mjs +10920 -0
  315. package/dist/stack-BXmLQf3K.mjs.map +1 -0
  316. package/dist/stack-BtnflNSa.cjs +11901 -0
  317. package/dist/stack-BtnflNSa.cjs.map +1 -0
  318. package/dist/stage-BbQidxxa.mjs +302 -0
  319. package/dist/stage-BbQidxxa.mjs.map +1 -0
  320. package/dist/stage-ssuPXLhP.cjs +331 -0
  321. package/dist/stage-ssuPXLhP.cjs.map +1 -0
  322. package/dist/stages-CQwD2QxS.cjs +190 -0
  323. package/dist/stages-CQwD2QxS.cjs.map +1 -0
  324. package/dist/stages-MA2sXnX4.mjs +190 -0
  325. package/dist/stages-MA2sXnX4.mjs.map +1 -0
  326. package/dist/target/public.cjs +15 -0
  327. package/dist/target/public.d.cts +28 -0
  328. package/dist/target/public.d.cts.map +1 -0
  329. package/dist/target/public.d.mts +28 -0
  330. package/dist/target/public.d.mts.map +1 -0
  331. package/dist/target/public.mjs +4 -0
  332. package/dist/terminal-BEGE1AEV.mjs +85 -0
  333. package/dist/terminal-BEGE1AEV.mjs.map +1 -0
  334. package/dist/terminal-BecJpgA3.cjs +85 -0
  335. package/dist/terminal-BecJpgA3.cjs.map +1 -0
  336. package/dist/{types-7R81hu0i.d.mts → types-BvokH0ya.d.cts} +2235 -459
  337. package/dist/types-BvokH0ya.d.cts.map +1 -0
  338. package/dist/{types-N7c2O2m7.d.cts → types-DmLnGeii.d.mts} +2233 -459
  339. package/dist/types-DmLnGeii.d.mts.map +1 -0
  340. package/dist/utils-CdKxD8Lt.mjs +156 -0
  341. package/dist/utils-CdKxD8Lt.mjs.map +1 -0
  342. package/dist/utils-DBqXbB8P.cjs +205 -0
  343. package/dist/utils-DBqXbB8P.cjs.map +1 -0
  344. package/dist/vitest.cjs +65 -0
  345. package/dist/vitest.cjs.map +1 -0
  346. package/dist/vitest.d.cts +29 -0
  347. package/dist/vitest.d.cts.map +1 -0
  348. package/dist/vitest.d.mts +29 -0
  349. package/dist/vitest.d.mts.map +1 -0
  350. package/dist/vitest.mjs +65 -0
  351. package/dist/vitest.mjs.map +1 -0
  352. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  353. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  354. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  355. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  356. package/dist/workspace/index.cjs +6 -2
  357. package/dist/workspace/index.d.cts +3 -3
  358. package/dist/workspace/index.d.mts +3 -3
  359. package/dist/workspace/index.mjs +2 -2
  360. package/dist/workspace-DEmfa9RO.cjs +3689 -0
  361. package/dist/workspace-DEmfa9RO.cjs.map +1 -0
  362. package/dist/workspace-RgU7TBgg.mjs +3133 -0
  363. package/dist/workspace-RgU7TBgg.mjs.map +1 -0
  364. package/package.json +76 -13
  365. package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
  366. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  367. package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
  368. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  369. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  370. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  371. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  372. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  373. package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
  374. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  375. package/dist/Route53Provider-DVILBsvV.cjs +0 -209
  376. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  377. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  378. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  379. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  380. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  381. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  382. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  383. package/dist/bundler-mjqGAvu1.cjs.map +0 -1
  384. package/dist/bundler-mwH7WOb1.mjs.map +0 -1
  385. package/dist/config-DSXI480r.cjs +0 -467
  386. package/dist/config-DSXI480r.cjs.map +0 -1
  387. package/dist/config-DdKkoUE1.mjs +0 -414
  388. package/dist/config-DdKkoUE1.mjs.map +0 -1
  389. package/dist/config.d.cts.map +0 -1
  390. package/dist/config.d.mts.map +0 -1
  391. package/dist/credentials-C6Pfn6GY.cjs +0 -2939
  392. package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
  393. package/dist/credentials-lbv-j0Be.mjs +0 -2802
  394. package/dist/credentials-lbv-j0Be.mjs.map +0 -1
  395. package/dist/discover-BERGFg8v.cjs +0 -288
  396. package/dist/discover-BERGFg8v.cjs.map +0 -1
  397. package/dist/discover-CK-n3w6b.mjs +0 -244
  398. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  399. package/dist/emit-BdoPFjZf.cjs +0 -253
  400. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  401. package/dist/emit-Bzq7JsMP.mjs +0 -224
  402. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  403. package/dist/generator-LfZU7NlU.mjs +0 -247
  404. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  405. package/dist/generator-Wdfp0jCS.cjs +0 -282
  406. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  407. package/dist/github-BvfpvBcW.cjs +0 -216
  408. package/dist/github-BvfpvBcW.cjs.map +0 -1
  409. package/dist/github-DW3CP-4D.mjs +0 -216
  410. package/dist/github-DW3CP-4D.mjs.map +0 -1
  411. package/dist/index-B4H4XF7A.d.mts.map +0 -1
  412. package/dist/index-RCUizGxL.d.cts.map +0 -1
  413. package/dist/openapi-B8bu_OXN.cjs +0 -2038
  414. package/dist/openapi-B8bu_OXN.cjs.map +0 -1
  415. package/dist/openapi-DfjbhrsM.mjs +0 -1991
  416. package/dist/openapi-DfjbhrsM.mjs.map +0 -1
  417. package/dist/reconcile-gb1lz1Dk.mjs +0 -113
  418. package/dist/reconcile-gb1lz1Dk.mjs.map +0 -1
  419. package/dist/reconcile-hx_vBvux.cjs +0 -136
  420. package/dist/reconcile-hx_vBvux.cjs.map +0 -1
  421. package/dist/ssm-BKN1Cg4z.mjs +0 -60
  422. package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
  423. package/dist/ssm-FxeSAt35.cjs +0 -60
  424. package/dist/ssm-FxeSAt35.cjs.map +0 -1
  425. package/dist/storage-DgypfSD6.cjs +0 -351
  426. package/dist/storage-DgypfSD6.cjs.map +0 -1
  427. package/dist/storage-TP0x118M.mjs +0 -304
  428. package/dist/storage-TP0x118M.mjs.map +0 -1
  429. package/dist/transfer-DjFZRgub.mjs +0 -122
  430. package/dist/transfer-DjFZRgub.mjs.map +0 -1
  431. package/dist/transfer-SeiSeKEF.cjs +0 -151
  432. package/dist/transfer-SeiSeKEF.cjs.map +0 -1
  433. package/dist/types-7R81hu0i.d.mts.map +0 -1
  434. package/dist/types-N7c2O2m7.d.cts.map +0 -1
  435. package/dist/workspace-Bu3xNCej.mjs.map +0 -1
  436. package/dist/workspace-CRD9YinV.cjs.map +0 -1
@@ -0,0 +1,1043 @@
1
+ import { t as GkmError } from "./errors-C9uIyIDt.mjs";
2
+ import { r as driversOf } from "./drivers-BQRb3KsL.mjs";
3
+ import { v as ConstructGenerator } from "./discover-Dfmn6HQ7.mjs";
4
+ import { dirname, join, relative, resolve } from "node:path";
5
+ import { existsSync, realpathSync } from "node:fs";
6
+ import { mkdir, writeFile } from "node:fs/promises";
7
+ import { Endpoint } from "@geekmidas/constructs/endpoints";
8
+ //#region src/generators/clientTelemetry.ts
9
+ /**
10
+ * Whether a generated client propagates trace context by default.
11
+ *
12
+ * `false` (the default) prints a client that sends no trace headers unless
13
+ * its caller passes `telemetry`. Anything else prints that default into
14
+ * `createApi`: `true`, or `{ sampleRate }` — the stage's rate, for the page
15
+ * views no OpenTelemetry SDK is tracing. A caller's own `telemetry` option
16
+ * still wins.
17
+ */
18
+ /** A `sampleRate` outside 0–1, which no sampler can honour. */
19
+ var InvalidClientTelemetrySampleRate = class extends GkmError {
20
+ sampleRate;
21
+ constructor(sampleRate) {
22
+ 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.`);
23
+ this.sampleRate = sampleRate;
24
+ this.name = "InvalidClientTelemetrySampleRate";
25
+ }
26
+ };
27
+ /** The `telemetry` default as the generated module prints it. */
28
+ function printTelemetryDefault(telemetry) {
29
+ if (typeof telemetry === "boolean") return String(telemetry);
30
+ const { sampleRate } = telemetry;
31
+ if (!Number.isFinite(sampleRate) || sampleRate < 0 || sampleRate > 1) throw new InvalidClientTelemetrySampleRate(sampleRate);
32
+ return `{ sampleRate: ${sampleRate} }`;
33
+ }
34
+ /**
35
+ * `--telemetry [rate]` for a client default, as `gkm openapi` takes it — and
36
+ * as a site's Dockerfile passes it to the `gkm openapi --app` it runs.
37
+ */
38
+ function telemetryArgs(telemetry) {
39
+ if (!telemetry) return [];
40
+ if (telemetry === true) return ["--telemetry"];
41
+ return ["--telemetry", String(telemetry.sampleRate)];
42
+ }
43
+ /** What `--telemetry [rate]` parsed to: on, at a rate when one was given. */
44
+ function parseTelemetryFlag(value) {
45
+ if (value === void 0 || value === false) return void 0;
46
+ if (value === true) return true;
47
+ return { sampleRate: Number(value) };
48
+ }
49
+ //#endregion
50
+ //#region src/generators/telemetry.ts
51
+ /** Each endpoint's own `.telemetry({ ignore, attributes })`, as routes. */
52
+ function routeTelemetry(endpoints) {
53
+ return endpoints.flatMap((endpoint) => endpoint.telemetry ? [{
54
+ method: endpoint.method,
55
+ path: endpoint.route,
56
+ ...endpoint.telemetry
57
+ }] : []);
58
+ }
59
+ /**
60
+ * Every package `@geekmidas/telescope/instrumentation` loads at runtime.
61
+ *
62
+ * All of them, rather than one as a proxy: the production bundle follows each
63
+ * import, and a single missing one fails the build rather than the telemetry.
64
+ */
65
+ const TELEMETRY_PACKAGES = [
66
+ "@opentelemetry/api",
67
+ "@opentelemetry/auto-instrumentations-node",
68
+ "@opentelemetry/exporter-logs-otlp-http",
69
+ "@opentelemetry/exporter-metrics-otlp-http",
70
+ "@opentelemetry/exporter-trace-otlp-http",
71
+ "@opentelemetry/instrumentation-pino",
72
+ "@opentelemetry/resources",
73
+ "@opentelemetry/sdk-logs",
74
+ "@opentelemetry/sdk-metrics",
75
+ "@opentelemetry/sdk-node",
76
+ "@opentelemetry/sdk-trace-base",
77
+ "@opentelemetry/sdk-trace-node",
78
+ "@opentelemetry/semantic-conventions"
79
+ ];
80
+ /**
81
+ * The directory of `name` as `node_modules` lookup finds it from `fromDir`,
82
+ * symlinks resolved — or undefined.
83
+ *
84
+ * The directory walk alone, not `require.resolve`: that also searches
85
+ * `NODE_PATH`, which a package manager's bin shim sets to its own store, so a
86
+ * `gkm build` run through one would find packages the app never installed —
87
+ * and the bundler, which does not look there, would then fail on them.
88
+ */
89
+ function packageDir(fromDir, name) {
90
+ for (let dir = resolve(fromDir);; dir = dirname(dir)) {
91
+ const candidate = join(dir, "node_modules", name);
92
+ if (existsSync(join(candidate, "package.json"))) return realpathSync(candidate);
93
+ if (dirname(dir) === dir) return void 0;
94
+ }
95
+ }
96
+ /**
97
+ * The telemetry packages that do not resolve the way the bundler will resolve
98
+ * them — telescope from the app, and the OpenTelemetry packages from
99
+ * telescope, where a peer is linked under pnpm, which need not be where the
100
+ * app sees it. Empty when every one does.
101
+ */
102
+ function missingTelemetryPackages(appRoot) {
103
+ const telescope = packageDir(appRoot, "@geekmidas/telescope");
104
+ if (!telescope) return ["@geekmidas/telescope", ...TELEMETRY_PACKAGES];
105
+ return TELEMETRY_PACKAGES.filter((pkg) => !packageDir(telescope, pkg));
106
+ }
107
+ /**
108
+ * An app uses a `Telemetry` construct and cannot load what it needs to.
109
+ *
110
+ * Failed at build, not at startup: a process that was given telemetry and
111
+ * quietly ran without it is an outage nobody can see into.
112
+ */
113
+ var TelemetryPackagesMissing = class extends GkmError {
114
+ app;
115
+ missing;
116
+ dir;
117
+ command;
118
+ constructor(app, missing, dir) {
119
+ const command = `pnpm --dir ${dir || "."} add ${missing.join(" ")}`;
120
+ 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`);
121
+ this.app = app;
122
+ this.missing = missing;
123
+ this.dir = dir;
124
+ this.name = "TelemetryPackagesMissing";
125
+ this.command = command;
126
+ }
127
+ };
128
+ /**
129
+ * The telemetry half of a build context: undefined for a process with no
130
+ * edge to a `Telemetry` node, and — for one with an edge — what its entry
131
+ * starts with, once every package it needs resolves.
132
+ */
133
+ function telemetryFor(options) {
134
+ const { node } = options;
135
+ if (!node) return void 0;
136
+ const missing = missingTelemetryPackages(options.appRoot);
137
+ if (missing.length > 0) throw new TelemetryPackagesMissing(options.app, missing, relative(options.cwd ?? process.cwd(), options.appRoot));
138
+ return {
139
+ serviceName: options.serviceName,
140
+ ...options.workspaceName && { serviceNamespace: options.workspaceName },
141
+ ignorePaths: [...node.ignorePaths ?? []],
142
+ attributes: { ...node.attributes },
143
+ routes: [...options.routes ?? []]
144
+ };
145
+ }
146
+ const HEADER = `/**
147
+ * Generated by gkm, for the production entry and the \`gkm dev\` one alike.
148
+ *
149
+ * Starts OpenTelemetry when OTEL_EXPORTER_OTLP_ENDPOINT names a collector, and
150
+ * does nothing otherwise: without it, the telemetry packages are not loaded.
151
+ * The standard OTEL_* variables (OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG,
152
+ * OTEL_EXPORTER_OTLP_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME)
153
+ * configure the rest.
154
+ */
155
+
156
+ import type { MiddlewareHandler } from 'hono';
157
+
158
+ export interface StartTelemetryOptions {
159
+ /** Requests whose spans would only be noise: health checks, by default. */
160
+ ignorePaths?: string[];
161
+ /**
162
+ * The API's own sites — the origins its CORS allows — read on each request.
163
+ * Their \`traceparent\` is continued, as is an internal caller's; anyone
164
+ * else's starts a new trace linked to the one it claimed.
165
+ */
166
+ trustedOrigins?: () => readonly string[];
167
+ }
168
+ `;
169
+ /** `/users/:id` as a pattern over a request's path. */
170
+ function routePattern(path) {
171
+ return `^${path.split("/").map((segment) => {
172
+ if (segment.startsWith(":")) return "[^/]+";
173
+ if (segment === "*") return ".*";
174
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
175
+ }).join("/")}/?$`;
176
+ }
177
+ /**
178
+ * The entry's `telemetry.ts`: a `startTelemetry()` the server awaits before it
179
+ * imports the app, so the libraries the app loads are instrumented. It returns
180
+ * the Hono middleware that traces each request, or undefined when telemetry is
181
+ * off — the server mounts it ahead of every route.
182
+ *
183
+ * Without a context — a process with no edge to a `Telemetry` node — it is a
184
+ * stub that loads nothing and says nothing: telemetry is not something that
185
+ * process was given.
186
+ *
187
+ * Failing to start telemetry warns (a named `TelemetryUnavailable`, through
188
+ * `process.emitWarning`) and never stops the server: an outage in observability
189
+ * is not a reason to have an outage in the service.
190
+ */
191
+ function generateTelemetryModule(telemetry) {
192
+ if (!telemetry) return `${HEADER}
193
+ // This process has no Telemetry construct, so there is nothing to start.
194
+ export async function startTelemetry(
195
+ _options: StartTelemetryOptions = {},
196
+ ): Promise<MiddlewareHandler | undefined> {
197
+ return undefined;
198
+ }
199
+ `;
200
+ const options = [
201
+ `serviceName: ${JSON.stringify(telemetry.serviceName)},`,
202
+ ...telemetry.serviceNamespace ? [`serviceNamespace: ${JSON.stringify(telemetry.serviceNamespace)},`] : [],
203
+ "deploymentEnvironment: process.env.STAGE,",
204
+ ...Object.keys(telemetry.attributes).length ? [`resourceAttributes: ${JSON.stringify(telemetry.attributes)},`] : [],
205
+ "handleSignals: false,",
206
+ "instrumentPino: false,",
207
+ "incomingHttpSpans: false,"
208
+ ];
209
+ const routes = telemetry.routes.map((route) => ({
210
+ method: route.method.toUpperCase(),
211
+ pattern: routePattern(route.path),
212
+ ...route.ignore ? { ignore: true } : {},
213
+ ...route.attributes && Object.keys(route.attributes).length ? { attributes: route.attributes } : {}
214
+ }));
215
+ const withAttributes = routes.some((route) => "attributes" in route);
216
+ return `${HEADER}
217
+ /** Telemetry was asked for and cannot start. The server runs without it. */
218
+ export class TelemetryUnavailable extends Error {
219
+ constructor(readonly reason: string, options?: { cause?: unknown }) {
220
+ super(
221
+ \`OTEL_EXPORTER_OTLP_ENDPOINT is set, but \${reason} This server exports no traces, metrics or logs until that is fixed.\`,
222
+ options,
223
+ );
224
+ this.name = 'TelemetryUnavailable';
225
+ }
226
+ }
227
+
228
+ /** The Telemetry construct's own ignored paths, beside the entry's. */
229
+ const IGNORE_PATHS: string[] = ${JSON.stringify(telemetry.ignorePaths)};
230
+
231
+ /** Each route's own .telemetry({ ignore, attributes }). */
232
+ const ROUTES: {
233
+ method: string;
234
+ pattern: string;
235
+ ignore?: boolean;
236
+ attributes?: Record<string, string>;
237
+ }[] = ${JSON.stringify(routes)};
238
+
239
+ const MATCHERS = ROUTES.map((route) => ({ ...route, regex: new RegExp(route.pattern) }));
240
+
241
+ function routeOf(method: string, path: string) {
242
+ return MATCHERS.find(
243
+ (route) => (route.method === method || route.method === 'ALL' || route.method === 'ANY') && route.regex.test(path),
244
+ );
245
+ }
246
+
247
+ export async function startTelemetry(
248
+ options: StartTelemetryOptions = {},
249
+ ): Promise<MiddlewareHandler | undefined> {
250
+ if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) return undefined;
251
+
252
+ let instrumentation;
253
+ try {
254
+ instrumentation = await import('@geekmidas/telescope/instrumentation');
255
+ } catch (cause) {
256
+ process.emitWarning(
257
+ new TelemetryUnavailable(
258
+ '@geekmidas/telescope/instrumentation or an @opentelemetry package it needs could not be loaded. Install them in the app and rebuild.',
259
+ { cause },
260
+ ),
261
+ );
262
+ return undefined;
263
+ }
264
+
265
+ instrumentation.setupTelemetry({
266
+ ${options.join("\n ")}
267
+ });
268
+
269
+ // Flush what is buffered when the process is told to stop. When nothing
270
+ // else handles the signal, re-raise it once flushed, so the process still
271
+ // stops the way it would have without this listener.
272
+ for (const signal of ['SIGTERM', 'SIGINT'] as const) {
273
+ process.once(signal, () => {
274
+ void instrumentation.flushTelemetry().finally(() => {
275
+ if (process.listenerCount(signal) === 0) process.kill(process.pid, signal);
276
+ });
277
+ });
278
+ }
279
+
280
+ // A SERVER span per request, opened by the app itself rather than by
281
+ // hooking node:http: \`GET /users/:id\`, continuing an incoming traceparent
282
+ // from the API's own sites and internal callers (a new, linked trace from
283
+ // anyone else), with the handler — its logs, fetches and queries — running
284
+ // inside it.
285
+ const spans = instrumentation.honoTelemetryMiddleware({
286
+ ignorePaths: [...(options.ignorePaths ?? []), ...IGNORE_PATHS],
287
+ trustedOrigins: options.trustedOrigins,
288
+ ...(MATCHERS.some((route) => route.ignore)
289
+ ? { shouldSkip: (c) => routeOf(c.req.method, c.req.path)?.ignore === true }
290
+ : {}),
291
+ });
292
+ ${withAttributes ? `
293
+ // A route's own attributes, on the span the middleware just opened.
294
+ const { trace } = await import('@opentelemetry/api');
295
+ return (c, next) =>
296
+ spans(c, async () => {
297
+ const attributes = routeOf(c.req.method, c.req.path)?.attributes;
298
+ if (attributes) trace.getActiveSpan()?.setAttributes(attributes);
299
+ await next();
300
+ });
301
+ ` : ` return spans;
302
+ `}}
303
+ `;
304
+ }
305
+ /**
306
+ * What an entry starts telemetry with, before it imports the app — shared by
307
+ * the production server, a self-serving surface's server and the `gkm dev`
308
+ * entry, so the three cannot start it differently. Defines `requestSpans`.
309
+ */
310
+ function startTelemetryCode(ignorePaths) {
311
+ return `// The API's own sites, known once the app has read its configuration: the
312
+ // origins its CORS allows are the ones whose trace context is continued.
313
+ let trustedOrigins: readonly string[] = [];
314
+
315
+ // Before the app is imported, so the libraries it loads are instrumented.
316
+ const { startTelemetry } = await import('./telemetry.js');
317
+ const requestSpans = await startTelemetry({
318
+ ignorePaths: ${JSON.stringify(ignorePaths)},
319
+ trustedOrigins: () => trustedOrigins,
320
+ });
321
+ `;
322
+ }
323
+ /** Mounts `requestSpans` on `app` ahead of every route. */
324
+ function mountRequestSpansCode(app) {
325
+ return `// The span middleware goes on before any route, so every request runs in it.
326
+ if (requestSpans) ${app}.use('*', requestSpans);
327
+ `;
328
+ }
329
+ /** Writes the entry's `telemetry.ts` beside it. */
330
+ async function writeTelemetryModule(outputDir, telemetry) {
331
+ await mkdir(outputDir, { recursive: true });
332
+ await writeFile(join(outputDir, "telemetry.ts"), generateTelemetryModule(telemetry));
333
+ }
334
+ //#endregion
335
+ //#region src/generators/EndpointGenerator.ts
336
+ /**
337
+ * How a generated entry gets its logger and environment parser.
338
+ *
339
+ * From the surface it serves, when there is one: the surface holds both as
340
+ * *objects*, and discovery already recorded which module declares it, so the
341
+ * entry imports that module and reads them off it.
342
+ *
343
+ * The alternative — the shape this replaces — was naming both in config as
344
+ * module paths, `envParser: './config/env#envParser'`, and printing an import
345
+ * for each. Two strings per app, checked by nothing, describing files the
346
+ * surface was already holding the contents of.
347
+ *
348
+ * Falls back to the configured paths for an app that declares no surface.
349
+ */
350
+ function runtimeFor(context, fromDir, owner) {
351
+ const module = owner ? context.owners?.[owner] ?? context.surface?.module : context.surface?.module;
352
+ if (module) {
353
+ const specifier = importSpecifier(fromDir, module.specifier);
354
+ return {
355
+ imports: `import { ${module.exportName} as __surface } from '${specifier}';`,
356
+ bindings: [
357
+ "// What this construct was declared with. Objects, not module paths:",
358
+ "// the entry imports the owner, so there is nothing to print.",
359
+ "const envParser = __surface.envParser;",
360
+ "const logger = __surface.logger;"
361
+ ].join("\n")
362
+ };
363
+ }
364
+ 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\`.`);
365
+ }
366
+ /** A relative specifier ESM will accept: always prefixed, never bare. */
367
+ function importSpecifier(fromDir, target) {
368
+ const rel = relative(fromDir, target).replace(/\.ts$/, ".js");
369
+ return rel.startsWith(".") ? rel : `./${rel}`;
370
+ }
371
+ /**
372
+ * CORS for a surface, derived rather than hand-written.
373
+ *
374
+ * Who may call a surface is already in the graph — every construct that
375
+ * declared an edge to it — and reaches the process as one comma-separated
376
+ * value. An application that maintained this by hand maintained a list that was
377
+ * wrong in two directions at once: it trusted origins nothing was serving, and
378
+ * it could not name hosts a deploy had not chosen yet.
379
+ *
380
+ * Only the parts a graph cannot answer are configurable, and every one has a
381
+ * default: a surface that says nothing about CORS still gets it.
382
+ */
383
+ function corsFor(surface) {
384
+ if (!surface) return {
385
+ imports: "",
386
+ setup: ""
387
+ };
388
+ const cors = surface.cors ?? {};
389
+ const allowHeaders = [.../* @__PURE__ */ new Set([
390
+ "content-type",
391
+ "authorization",
392
+ "traceparent",
393
+ "tracestate",
394
+ ...cors.allowHeaders ?? []
395
+ ])];
396
+ return {
397
+ imports: `import { cors } from 'hono/cors';
398
+ import { trustsOrigin } from '@geekmidas/constructs/endpoints';`,
399
+ setup: `
400
+ // Who may call ${surface.id}, read off the graph rather than listed here.
401
+ {
402
+ const { origins } = envParser
403
+ .create((get) => ({
404
+ origins: get('${surface.trustedOriginsKey}')
405
+ .string()
406
+ .default('')
407
+ .transform((value: string) =>
408
+ value.split(',').map((origin) => origin.trim()).filter(Boolean),
409
+ ),
410
+ }))
411
+ .parse();
412
+
413
+ // The same origins are the ones whose trace context the request spans
414
+ // continue — the server reads them back from \`createApp\`.
415
+ trustedOrigins.push(...origins);
416
+
417
+ // An exact origin, or any one label in place of a wildcard site's \`*\`.
418
+ honoApp.use('*', cors({
419
+ origin: (origin) => (trustsOrigin(origin, origins) ? origin : null),
420
+ allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
421
+ allowHeaders: ${JSON.stringify(allowHeaders)},${cors.exposeHeaders ? `\n exposeHeaders: ${JSON.stringify(cors.exposeHeaders)},` : ""}
422
+ credentials: ${cors.credentials ?? true},
423
+ maxAge: ${cors.maxAge ?? 86400},
424
+ }));
425
+ }
426
+ `
427
+ };
428
+ }
429
+ var EndpointGenerator = class extends ConstructGenerator {
430
+ isConstruct(value) {
431
+ return Endpoint.isEndpoint(value);
432
+ }
433
+ async build(context, constructs, outputDir, options) {
434
+ const target = options?.target ?? "aws";
435
+ const root = options?.root ?? process.cwd();
436
+ const enableOpenApi = options?.enableOpenApi || false;
437
+ const logger = console;
438
+ const routes = [];
439
+ if (constructs.length === 0) return routes;
440
+ if (target === "server") {
441
+ await this.generateEndpointsFile(outputDir, constructs);
442
+ const appFile = await this.generateAppFile(outputDir, context);
443
+ routes.push({
444
+ path: "*",
445
+ method: "ALL",
446
+ handler: relative(root, appFile),
447
+ authorizer: "none"
448
+ });
449
+ logger.log(`Generated server with ${constructs.length} endpoints${enableOpenApi ? " (OpenAPI enabled)" : ""}`);
450
+ return routes;
451
+ }
452
+ const routesDir = join(outputDir, "routes");
453
+ await mkdir(routesDir, { recursive: true });
454
+ for (const { key, construct, path } of constructs) {
455
+ const handlerFile = await this.generateHandlerFile(routesDir, path.relative, key, {
456
+ ...context,
457
+ storageDrivers: driversOf(context, construct)
458
+ });
459
+ const routeInfo = {
460
+ path: construct._path,
461
+ method: construct.method,
462
+ handler: relative(root, handlerFile).replace(/\.ts$/, ".handler"),
463
+ timeout: construct.timeout,
464
+ memorySize: construct.memorySize,
465
+ environment: await construct.getEnvironment({ markOptional: context.markOptional }),
466
+ dependencies: construct.constructs,
467
+ authorizer: construct.authorizer?.name ?? "none"
468
+ };
469
+ routes.push(routeInfo);
470
+ logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
471
+ }
472
+ return routes;
473
+ }
474
+ async generateHandlerFile(outputDir, sourceFile, exportName, context) {
475
+ const handlerPath = join(outputDir, `${exportName}.ts`);
476
+ const importPath = relative(dirname(handlerPath), sourceFile).replace(/\.ts$/, ".js");
477
+ await writeFile(handlerPath, this.generateAWSApiGatewayV2Handler(importPath, exportName, context.storageDrivers));
478
+ return handlerPath;
479
+ }
480
+ async generateEndpointsFile(outputDir, endpoints) {
481
+ const endpointsPath = join(outputDir, "endpoints.ts");
482
+ const importsByFile = /* @__PURE__ */ new Map();
483
+ for (const { path, key } of endpoints) {
484
+ const importPath = relative(dirname(endpointsPath), path.relative).replace(/\.ts$/, ".js");
485
+ if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
486
+ importsByFile.get(importPath)?.push(key);
487
+ }
488
+ const content = `import type { EnvironmentParser } from '@geekmidas/envkit';
489
+ import type { Logger } from '@geekmidas/logger';
490
+ import { HonoEndpoint } from '@geekmidas/constructs/hono';
491
+ import { Endpoint } from '@geekmidas/constructs/endpoints';
492
+ import { ServiceDiscovery } from '@geekmidas/services';
493
+ import type { Hono } from 'hono';
494
+ ${Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n")}
495
+
496
+ export const endpoints: Endpoint<any, any, any, any, any, any, any, any, any, any, any, any>[] = [
497
+ ${endpoints.map(({ key }) => key).join(",\n ")}
498
+ ];
499
+
500
+ export async function setupEndpoints(
501
+ app: Hono,
502
+ envParser: EnvironmentParser<any>,
503
+ logger: Logger,
504
+ enableOpenApi: boolean = true,
505
+ ): Promise<void> {
506
+ const serviceDiscovery = ServiceDiscovery.getInstance(envParser);
507
+
508
+ // Configure OpenAPI options based on enableOpenApi flag
509
+ const openApiOptions: any = enableOpenApi ? {
510
+ docsPath: '/__docs',
511
+ openApiOptions: {
512
+ title: 'API Documentation',
513
+ version: '1.0.0',
514
+ description: 'Generated API documentation'
515
+ }
516
+ } : { docsPath: false };
517
+
518
+ HonoEndpoint.addRoutes(endpoints, serviceDiscovery, app, openApiOptions);
519
+
520
+ // Add Swagger UI if OpenAPI is enabled
521
+ if (enableOpenApi) {
522
+ try {
523
+ const { swaggerUI } = await import('@hono/swagger-ui');
524
+ app.get('/__docs/ui', swaggerUI({ url: '/__docs' }));
525
+ } catch {
526
+ // @hono/swagger-ui not installed, skip Swagger UI
527
+ }
528
+ }
529
+ }
530
+ `;
531
+ await writeFile(endpointsPath, content);
532
+ return endpointsPath;
533
+ }
534
+ async generateAppFile(outputDir, context) {
535
+ await writeTelemetryModule(outputDir, context.telemetry);
536
+ if (context.production?.enabled) return this.generateProductionAppFile(outputDir, context);
537
+ const appPath = join(outputDir, "app.ts");
538
+ const runtime = runtimeFor(context, dirname(appPath));
539
+ const telescopeEnabled = context.telescope?.enabled;
540
+ const telescopeWebSocketEnabled = context.telescope?.websocket;
541
+ const usesExternalTelescope = !!context.telescope?.telescopePath;
542
+ const telescopeFromSurface = !!context.surface?.module && !usesExternalTelescope;
543
+ let telescopeImports = "";
544
+ if (telescopeEnabled) {
545
+ if (telescopeFromSurface) telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
546
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
547
+ else if (usesExternalTelescope) {
548
+ const relativeTelescopePath = relative(dirname(appPath), context.telescope?.telescopePath);
549
+ telescopeImports = `import ${context.telescope?.telescopeImportPattern} from '${relativeTelescopePath}';
550
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
551
+ } else telescopeImports = `import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
552
+ import { createApi, createMiddleware } from '@geekmidas/telescope/hono';`;
553
+ }
554
+ const databaseApi = context.databaseApi;
555
+ const databaseApiImports = databaseApi ? `import { snifferContext } from '@geekmidas/constructs';
556
+ import { createIntrospectionHandler } from '@geekmidas/db/introspect';
557
+ import { ${databaseApi.database.exportName} as __introspectedDb } from '${importSpecifier(dirname(appPath), databaseApi.database.specifier)}';` : "";
558
+ const cors = corsFor(context.surface);
559
+ let hooksImports = "";
560
+ let beforeSetupCall = "";
561
+ let afterSetupCall = "";
562
+ if (context.hooks?.serverHooksPath) {
563
+ hooksImports = `import * as serverHooks from '${relative(dirname(appPath), context.hooks.serverHooksPath)}';`;
564
+ beforeSetupCall = `
565
+ // Call beforeSetup hook if defined
566
+ if (typeof serverHooks.beforeSetup === 'function') {
567
+ await serverHooks.beforeSetup(honoApp, { envParser, logger });
568
+ }
569
+ `;
570
+ afterSetupCall = `
571
+ // Call afterSetup hook if defined
572
+ if (typeof serverHooks.afterSetup === 'function') {
573
+ await serverHooks.afterSetup(honoApp, { envParser, logger });
574
+ }
575
+ `;
576
+ }
577
+ const telescopeWebSocketSetupCode = telescopeWebSocketEnabled ? `
578
+ // Setup WebSocket for real-time telescope updates
579
+ try {
580
+ const { createNodeWebSocket } = await import('@hono/node-ws');
581
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app: honoApp });
582
+ // Add WebSocket route directly to main app (sub-app routes don't support WS upgrade)
583
+ honoApp.get('${context.telescope?.path}/ws', upgradeWebSocket(() => ({
584
+ onOpen: (_event: Event, ws: any) => {
585
+ telescope.addWsClient(ws);
586
+ },
587
+ onClose: (_event: Event, ws: any) => {
588
+ telescope.removeWsClient(ws);
589
+ },
590
+ onMessage: (event: MessageEvent, ws: any) => {
591
+ try {
592
+ const data = JSON.parse(event.data);
593
+ if (data.type === 'ping') {
594
+ ws.send(JSON.stringify({ type: 'pong' }));
595
+ }
596
+ } catch {
597
+ // Ignore invalid messages
598
+ }
599
+ },
600
+ })));
601
+ // Store injectWebSocket for server entry to call after serve()
602
+ (honoApp as any).__injectWebSocket = injectWebSocket;
603
+ logger.info('Telescope WebSocket enabled');
604
+ } catch (e) {
605
+ logger.warn({ err: e }, 'WebSocket support not available - install @hono/node-ws for real-time updates');
606
+ }
607
+ ` : "";
608
+ let telescopeSetup = "";
609
+ if (telescopeEnabled) {
610
+ if (telescopeFromSurface || usesExternalTelescope) telescopeSetup = `
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
+ else telescopeSetup = `
620
+ // Setup Telescope for debugging/monitoring
621
+ const telescopeStorage = new InMemoryStorage({ maxEntries: ${context.telescope?.maxEntries} });
622
+ const telescope = new Telescope({
623
+ enabled: true,
624
+ path: '${context.telescope?.path}',
625
+ ignorePatterns: ${JSON.stringify(context.telescope?.ignore)},
626
+ recordBody: ${context.telescope?.recordBody},
627
+ storage: telescopeStorage,
628
+ });
629
+ ${telescopeWebSocketSetupCode}
630
+ // Add telescope middleware (before endpoints to capture all requests)
631
+ honoApp.use('*', createMiddleware(telescope));
632
+
633
+ // Mount Telescope's JSON API
634
+ const telescopeApi = createApi(telescope);
635
+ honoApp.route('${context.telescope?.path}', telescopeApi);
636
+ `;
637
+ }
638
+ const databaseApiSetup = databaseApi ? `
639
+ // The database's structure and rows as JSON, read-only, for whatever tool
640
+ // the developer points at it. Dev only: it answers anyone who can reach the
641
+ // port.
642
+ const databaseApi = createIntrospectionHandler({
643
+ db: await __introspectedDb.service.register({ envParser, context: snifferContext }),
644
+ basePath: '${databaseApi.path}',
645
+ });
646
+ honoApp.all('${databaseApi.path}/*', (c) => databaseApi(c.req.raw));
647
+ ` : "";
648
+ const content = `/**
649
+ * Generated server application
650
+ *
651
+ * ⚠️ WARNING: This is for LOCAL DEVELOPMENT ONLY
652
+ * The subscriber polling mechanism is not production-ready.
653
+ * For production, use AWS Lambda with SQS/SNS event sources.
654
+ */
655
+ import { Hono } from 'hono';
656
+ import type { Hono as HonoType } from 'hono';
657
+ import { setupEndpoints } from './endpoints.js';
658
+ import { setupSubscribers } from './subscribers.js';
659
+ import { setupQueues } from './queues.js';
660
+ import { setupCrons } from './crons.js';
661
+ ${context.devProcessors ? "import { setupProcessors } from './processors.js';\n" : ""}${runtime.imports}
662
+ ${telescopeImports}
663
+ ${databaseApiImports}
664
+ ${hooksImports}
665
+ ${cors.imports}
666
+ ${context.storageDrivers?.imports ?? ""}
667
+
668
+ ${runtime.bindings}
669
+ ${telescopeEnabled && telescopeFromSurface ? `// The surface's own Telescope, or the one \`telescope\` config describes.
670
+ const telescope =
671
+ __surface.telescope ??
672
+ new Telescope({
673
+ enabled: true,
674
+ path: '${context.telescope?.path}',
675
+ ignorePatterns: ${JSON.stringify(context.telescope?.ignore)},
676
+ recordBody: ${context.telescope?.recordBody},
677
+ storage: new InMemoryStorage({ maxEntries: ${context.telescope?.maxEntries} }),
678
+ });` : ""}
679
+
680
+ ${context.storageDrivers?.setup ? `// Which drivers exist — storage, cache, events — is the entry point's
681
+ // decision: the scheme in each injected URL picks one, so no construct and no
682
+ // application module names a provider.
683
+ ${context.storageDrivers.setup}
684
+ ` : ""}
685
+ ${context.surface ? `// Who this server is to Postgres: application_name on every connection.
686
+ process.env.GKM_APP_NAME ??= ${JSON.stringify(context.surface.id)};
687
+
688
+ ` : ""}export interface ServerApp {
689
+ app: HonoType;
690
+ /** The origins this API's CORS allows: its own sites. */
691
+ trustedOrigins: readonly string[];
692
+ start: (options?: {
693
+ port?: number;
694
+ /** Returns the server, so a shutdown can stop it taking requests. */
695
+ serve: (app: HonoType, port: number) => unknown;
696
+ }) => Promise<void>;
697
+ }
698
+
699
+ /**
700
+ * Create and configure the Hono application
701
+ *
702
+ * @param app - Optional Hono app instance to configure (creates new one if not provided)
703
+ * @param enableOpenApi - Enable OpenAPI documentation (default: true)
704
+ * @returns Server app with configured Hono app and start function
705
+ *
706
+ * @example
707
+ * // With Bun
708
+ * import { createApp } from './.gkm/server/app.js';
709
+ *
710
+ * const { app, start } = await createApp();
711
+ *
712
+ * await start({
713
+ * port: 3000,
714
+ * serve: (app, port) => {
715
+ * Bun.serve({ port, fetch: app.fetch });
716
+ * }
717
+ * });
718
+ *
719
+ * @example
720
+ * // With Node.js (using @hono/node-server)
721
+ * import { serve } from '@hono/node-server';
722
+ * import { createApp } from './.gkm/server/app.js';
723
+ *
724
+ * const { app, start } = await createApp();
725
+ *
726
+ * await start({
727
+ * port: 3000,
728
+ * serve: (app, port) => {
729
+ * serve({ fetch: app.fetch, port });
730
+ * }
731
+ * });
732
+ */
733
+ export async function createApp(app?: HonoType, enableOpenApi: boolean = true): Promise<ServerApp> {
734
+ const honoApp = app || new Hono();
735
+ const trustedOrigins: string[] = [];
736
+ ${telescopeSetup}${cors.setup}${beforeSetupCall}${databaseApiSetup}${context.devProcessors ? `
737
+ // The file servers' processors this app holds, where the local edge sends
738
+ // each pattern on their hosts. Ahead of the endpoints, so none shadows them.
739
+ setupProcessors(honoApp, envParser);
740
+ ` : ""}
741
+ // Setup HTTP endpoints
742
+ await setupEndpoints(honoApp, envParser, logger, enableOpenApi);
743
+ ${afterSetupCall}
744
+
745
+ return {
746
+ app: honoApp,
747
+ trustedOrigins,
748
+ async start(options) {
749
+ if (!options?.serve) {
750
+ throw new Error(
751
+ 'serve function is required. Pass a serve function for your runtime:\\n' +
752
+ ' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\n' +
753
+ ' - Node: (app, port) => serve({ fetch: app.fetch, port })'
754
+ );
755
+ }
756
+
757
+ const port = options.port ?? 3000;
758
+
759
+ // Mount pushed subscribers' routes and start polled ones. What comes
760
+ // back subscribes the routes, once the server can answer them.
761
+ const subscribeForPush = await setupSubscribers(honoApp, envParser, logger).catch((error) => {
762
+ logger.error({ err: error }, 'Failed to start subscribers');
763
+ return async (_port: number) => {};
764
+ });
765
+
766
+ // Start queue workers in background (non-blocking, local development only)
767
+ await setupQueues(envParser, logger).catch((error) => {
768
+ logger.error({ err: error }, 'Failed to start queue workers');
769
+ });
770
+
771
+ // Schedule this app's crons. Caught like the others: a scheduler that
772
+ // cannot start is not a reason for the HTTP server not to.
773
+ await setupCrons(envParser, logger).catch((error) => {
774
+ logger.error({ err: error }, 'Failed to schedule crons');
775
+ });
776
+
777
+ logger.info({ port }, 'Starting server');
778
+
779
+ // Start HTTP server using provided serve function
780
+ await options.serve(honoApp, port);
781
+
782
+ logger.info({ port }, 'Server started');
783
+
784
+ await subscribeForPush(port);
785
+ }
786
+ };
787
+ }
788
+
789
+ // Default export for convenience
790
+ export default createApp;
791
+ `;
792
+ await writeFile(appPath, content);
793
+ return appPath;
794
+ }
795
+ /**
796
+ * One Lambda, one endpoint — and no environment import.
797
+ *
798
+ * The endpoint was built from its surface, so it carries the parser the
799
+ * adaptor needs. This used to read
800
+ * `import { envParser } from '../../config/env'`, a line the build wrote
801
+ * because a generator can print a module specifier and cannot print an
802
+ * object. Nothing has to be printed now, which is also why nothing has to be
803
+ * named in config.
804
+ */
805
+ generateAWSApiGatewayV2Handler(importPath, exportName, drivers) {
806
+ return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/constructs/aws';
807
+ import { ${exportName} } from '${importPath}';
808
+ ${drivers?.imports ?? ""}
809
+ ${drivers?.setup ? `\n// The handler registers the drivers its target needs.\n${drivers.setup}\n` : ""}
810
+ const adapter = new AmazonApiGatewayV2Endpoint(${exportName});
811
+
812
+ export const handler = adapter.handler;
813
+ `;
814
+ }
815
+ /**
816
+ * Generate a production-optimized app.ts file
817
+ * No dev tools (Telescope, Studio, WebSocket), includes health checks and graceful shutdown
818
+ */
819
+ async generateProductionAppFile(outputDir, context) {
820
+ const appPath = join(outputDir, "app.ts");
821
+ const runtime = runtimeFor(context, dirname(appPath));
822
+ const production = context.production;
823
+ const healthCheckPath = production.healthCheck;
824
+ const enableGracefulShutdown = production.gracefulShutdown;
825
+ const enableOpenApi = production.openapi;
826
+ const includeSubscribers = production.subscribers === "include";
827
+ const cors = corsFor(context.surface);
828
+ let hooksImports = "";
829
+ let beforeSetupCall = "";
830
+ let afterSetupCall = "";
831
+ if (context.hooks?.serverHooksPath) {
832
+ hooksImports = `import * as serverHooks from '${relative(dirname(appPath), context.hooks.serverHooksPath)}';`;
833
+ beforeSetupCall = `
834
+ // Call beforeSetup hook if defined
835
+ if (typeof serverHooks.beforeSetup === 'function') {
836
+ await serverHooks.beforeSetup(honoApp, { envParser, logger });
837
+ }
838
+ `;
839
+ afterSetupCall = `
840
+ // Call afterSetup hook if defined
841
+ if (typeof serverHooks.afterSetup === 'function') {
842
+ await serverHooks.afterSetup(honoApp, { envParser, logger });
843
+ }
844
+ `;
845
+ }
846
+ const subscriberSetup = includeSubscribers ? `
847
+ // Mount pushed subscribers' routes and start polled ones. What comes
848
+ // back subscribes the routes, once the server can answer them.
849
+ const subscribeForPush = await setupSubscribers(honoApp, envParser, logger).catch((error) => {
850
+ logger.error({ err: error }, 'Failed to start subscribers');
851
+ return async (_port: number) => {};
852
+ });
853
+
854
+ // Start queue workers in background
855
+ await setupQueues(envParser, logger).catch((error) => {
856
+ logger.error({ err: error }, 'Failed to start queue workers');
857
+ });
858
+
859
+ // Schedule this app's crons. Caught like the others: a scheduler that
860
+ // cannot start is not a reason for the HTTP server not to.
861
+ await setupCrons(envParser, logger).catch((error) => {
862
+ logger.error({ err: error }, 'Failed to schedule crons');
863
+ });
864
+ ` : "";
865
+ const subscriberImport = includeSubscribers ? `import { setupSubscribers } from './subscribers.js';
866
+ import { setupQueues } from './queues.js';
867
+ import { setupCrons } from './crons.js';` : "";
868
+ const gracefulShutdownCode = enableGracefulShutdown ? `
869
+ // Graceful shutdown: stop taking requests, let in-flight ones finish, then
870
+ // close what constructs opened (database pools) — so a rolling deploy does
871
+ // not leave the old task holding connections. Bounded by
872
+ // GKM_SHUTDOWN_TIMEOUT_MS, 8s by default: under Docker's 10s stop timeout,
873
+ // so the process exits on its own terms rather than being killed mid-drain.
874
+ let isShuttingDown = false;
875
+
876
+ const shutdown = async () => {
877
+ if (isShuttingDown) return;
878
+ isShuttingDown = true;
879
+ const deadline = Number(process.env.GKM_SHUTDOWN_TIMEOUT_MS) || 8000;
880
+ logger.info({ deadline }, 'Graceful shutdown initiated');
881
+ setTimeout(() => {
882
+ logger.warn({ deadline }, 'Shutdown deadline reached, exiting');
883
+ process.exit(1);
884
+ }, deadline).unref();
885
+ await new Promise<void>((resolve) => {
886
+ const close = (server as { close?: (done: () => void) => void } | undefined)?.close;
887
+ if (typeof close === 'function') close.call(server, () => resolve());
888
+ else resolve();
889
+ });
890
+ await runShutdownHooks((error) => logger.error({ err: error }, 'Shutdown hook failed'));
891
+ process.exit(0);
892
+ };
893
+
894
+ process.on('SIGTERM', shutdown);
895
+ process.on('SIGINT', shutdown);
896
+ ` : "";
897
+ const content = `/**
898
+ * Generated production server application
899
+ *
900
+ * This is a production-optimized build without dev tools.
901
+ * - No Telescope debugging dashboard
902
+ * - No Studio database browser
903
+ * - No WebSocket updates
904
+ * - Includes health checks and graceful shutdown
905
+ */
906
+ import { Hono } from 'hono';
907
+ import type { Hono as HonoType } from 'hono';
908
+ ${enableGracefulShutdown ? "import { runShutdownHooks } from '@geekmidas/constructs';\n" : ""}import { setupEndpoints } from './endpoints.js';
909
+ ${subscriberImport}
910
+ ${runtime.imports}
911
+ ${runtime.bindings}
912
+ ${hooksImports}
913
+ ${cors.imports}
914
+ ${context.storageDrivers?.imports ?? ""}
915
+
916
+ ${context.storageDrivers?.setup ? `// The entry point registers the drivers its target needs.
917
+ ${context.storageDrivers.setup}
918
+ ` : ""}
919
+ ${context.surface ? `// Who this server is to Postgres: application_name on every connection.
920
+ process.env.GKM_APP_NAME ??= ${JSON.stringify(context.surface.id)};
921
+
922
+ ` : ""}export interface ServerApp {
923
+ app: HonoType;
924
+ /** The origins this API's CORS allows: its own sites. */
925
+ trustedOrigins: readonly string[];
926
+ start: (options?: {
927
+ port?: number;
928
+ serve: (app: HonoType, port: number) => void | Promise<void>;
929
+ }) => Promise<void>;
930
+ }
931
+
932
+ /**
933
+ * Create and configure the production Hono application
934
+ */
935
+ export async function createApp(app?: HonoType): Promise<ServerApp> {
936
+ const honoApp = app || new Hono();
937
+ const trustedOrigins: string[] = [];
938
+
939
+ // Health check endpoint (always first)
940
+ honoApp.get('${healthCheckPath}', (c) => c.json({ status: 'ok', timestamp: Date.now() }));
941
+ honoApp.get('/ready', (c) => c.json({ ready: true }));
942
+
943
+ // An HttpError a handler or a session callback throws — a 401, a 404 —
944
+ // answers with its own status, as it does under gkm dev. The optimized
945
+ // handlers do not catch, so without this every one of them was a 500.
946
+ // Anything else is a 500 that says nothing about why, and is logged.
947
+ honoApp.onError((error, c) => {
948
+ const http = error as {
949
+ isHttpError?: boolean;
950
+ statusCode?: number;
951
+ statusMessage?: string;
952
+ code?: string;
953
+ details?: unknown;
954
+ };
955
+ if (http.isHttpError === true && typeof http.statusCode === 'number') {
956
+ return c.json(
957
+ {
958
+ name: error.name,
959
+ message: error.message,
960
+ statusCode: http.statusCode,
961
+ statusMessage: http.statusMessage,
962
+ code: http.code,
963
+ details: http.details,
964
+ },
965
+ http.statusCode as 500,
966
+ );
967
+ }
968
+ logger.error({ err: error }, 'Unhandled error');
969
+ return c.json({ message: 'Internal Server Error' }, 500);
970
+ });
971
+ ${cors.setup}${beforeSetupCall}
972
+ // Setup HTTP endpoints (OpenAPI: ${enableOpenApi})
973
+ await setupEndpoints(honoApp, envParser, logger, ${enableOpenApi});
974
+ ${afterSetupCall}
975
+ return {
976
+ app: honoApp,
977
+ trustedOrigins,
978
+ async start(options) {
979
+ if (!options?.serve) {
980
+ throw new Error(
981
+ 'serve function is required. Pass a serve function for your runtime:\\n' +
982
+ ' - Bun: (app, port) => Bun.serve({ port, fetch: app.fetch })\\n' +
983
+ ' - Node: (app, port) => serve({ fetch: app.fetch, port })'
984
+ );
985
+ }
986
+
987
+ const port = options.port ?? Number(process.env.PORT) ?? 3000;
988
+ let server: unknown;
989
+ ${gracefulShutdownCode}${subscriberSetup}
990
+ logger.info({ port }, 'Starting production server');
991
+
992
+ // Start HTTP server using provided serve function
993
+ server = await options.serve(honoApp, port);
994
+
995
+ logger.info({ port }, 'Production server started');
996
+ ${includeSubscribers ? "\n await subscribeForPush(port);" : ""}
997
+ }
998
+ };
999
+ }
1000
+
1001
+ // Default export for convenience
1002
+ export default createApp;
1003
+ `;
1004
+ await writeFile(appPath, content);
1005
+ await this.generateProductionServerEntry(outputDir, context);
1006
+ return appPath;
1007
+ }
1008
+ /**
1009
+ * Generate production server.ts entry point
1010
+ */
1011
+ async generateProductionServerEntry(outputDir, context) {
1012
+ const serverPath = join(outputDir, "server.ts");
1013
+ const content = `#!/usr/bin/env node
1014
+ /**
1015
+ * Production server entry point
1016
+ * Generated by 'gkm build --production'
1017
+ */
1018
+ import { serve } from '@hono/node-server';
1019
+ import { Hono } from 'hono';
1020
+
1021
+ ${startTelemetryCode([context.production?.healthCheck ?? "/health", "/ready"])}
1022
+ const { createApp } = await import('./app.js');
1023
+
1024
+ const port = Number(process.env.PORT) || 3000;
1025
+
1026
+ const app = new Hono();
1027
+ ${mountRequestSpansCode("app")}
1028
+ const created = await createApp(app);
1029
+ trustedOrigins = created.trustedOrigins;
1030
+ const { start } = created;
1031
+
1032
+ await start({
1033
+ port,
1034
+ serve: (app, port) => serve({ fetch: app.fetch, port }),
1035
+ });
1036
+ `;
1037
+ await writeFile(serverPath, content);
1038
+ }
1039
+ };
1040
+ //#endregion
1041
+ export { startTelemetryCode as a, parseTelemetryFlag as c, routeTelemetry as i, printTelemetryDefault as l, runtimeFor as n, telemetryFor as o, mountRequestSpansCode as r, writeTelemetryModule as s, EndpointGenerator as t, telemetryArgs as u };
1042
+
1043
+ //# sourceMappingURL=EndpointGenerator-CBKH87_b.mjs.map