@geekmidas/constructs 10.0.0-alpha.11 → 10.0.0-alpha.110

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 (438) hide show
  1. package/README.md +222 -158
  2. package/dist/Construct-BQALFCh2.d.cts +230 -0
  3. package/dist/Construct-BQALFCh2.d.cts.map +1 -0
  4. package/dist/{Construct-BD5neF7w.mjs → Construct-CKUA-CTA.mjs} +35 -35
  5. package/dist/Construct-CKUA-CTA.mjs.map +1 -0
  6. package/dist/{Construct-CyS3RpTL.cjs → Construct-DEOVauyA.cjs} +55 -49
  7. package/dist/Construct-DEOVauyA.cjs.map +1 -0
  8. package/dist/Construct-QXnl3VqT.d.mts +230 -0
  9. package/dist/Construct-QXnl3VqT.d.mts.map +1 -0
  10. package/dist/{Cron-DmQ8vQ4b.d.cts → Cron-CQJqqkhY.d.mts} +17 -11
  11. package/dist/Cron-CQJqqkhY.d.mts.map +1 -0
  12. package/dist/{Cron-dh4rUgib.d.mts → Cron-DI3nKoic.d.cts} +17 -11
  13. package/dist/Cron-DI3nKoic.d.cts.map +1 -0
  14. package/dist/{CronBuilder-Da0C0edR.cjs → CronBuilder-BXTG10u5.cjs} +47 -31
  15. package/dist/CronBuilder-BXTG10u5.cjs.map +1 -0
  16. package/dist/{CronBuilder-CYKT5RiO.mjs → CronBuilder-D3sF9tS_.mjs} +37 -21
  17. package/dist/CronBuilder-D3sF9tS_.mjs.map +1 -0
  18. package/dist/CronBuilder-Xx_zakuc.d.mts +47 -0
  19. package/dist/CronBuilder-Xx_zakuc.d.mts.map +1 -0
  20. package/dist/CronBuilder-g1lZLWyG.d.cts +47 -0
  21. package/dist/CronBuilder-g1lZLWyG.d.cts.map +1 -0
  22. package/dist/{Endpoint-BjWKinFA.d.mts → Endpoint-BWyKCa2x.d.cts} +130 -100
  23. package/dist/Endpoint-BWyKCa2x.d.cts.map +1 -0
  24. package/dist/{Endpoint-dav89W6-.d.cts → Endpoint-CrE9Ppdk.d.mts} +130 -100
  25. package/dist/Endpoint-CrE9Ppdk.d.mts.map +1 -0
  26. package/dist/{Endpoint-DCQPMdUX.mjs → Endpoint-gPXhHKhJ.mjs} +208 -100
  27. package/dist/Endpoint-gPXhHKhJ.mjs.map +1 -0
  28. package/dist/{Endpoint-DcWXE-SZ.cjs → Endpoint-yhR2T2Wt.cjs} +248 -122
  29. package/dist/Endpoint-yhR2T2Wt.cjs.map +1 -0
  30. package/dist/{index-lAO9egTb.d.mts → EndpointFactory-BV-nfnaP.d.mts} +85 -136
  31. package/dist/EndpointFactory-BV-nfnaP.d.mts.map +1 -0
  32. package/dist/{EndpointFactory-CdWB7wPw.cjs → EndpointFactory-BVv6EIDu.cjs} +98 -112
  33. package/dist/EndpointFactory-BVv6EIDu.cjs.map +1 -0
  34. package/dist/{index-Bd5FqCoe.d.cts → EndpointFactory-C1-IBwm4.d.cts} +84 -135
  35. package/dist/EndpointFactory-C1-IBwm4.d.cts.map +1 -0
  36. package/dist/{EndpointFactory-CjV8F_lJ.mjs → EndpointFactory-Cs8IHvwF.mjs} +62 -76
  37. package/dist/EndpointFactory-Cs8IHvwF.mjs.map +1 -0
  38. package/dist/Function-DuqGcbOI.d.mts +76 -0
  39. package/dist/Function-DuqGcbOI.d.mts.map +1 -0
  40. package/dist/Function-Pu-1kKZz.d.cts +76 -0
  41. package/dist/Function-Pu-1kKZz.d.cts.map +1 -0
  42. package/dist/{HonoEndpointAdaptor-DtL9j19R.cjs → HonoEndpointAdaptor-CN1jjUBJ.cjs} +115 -71
  43. package/dist/HonoEndpointAdaptor-CN1jjUBJ.cjs.map +1 -0
  44. package/dist/{HonoEndpointAdaptor-P1ahhZHu.mjs → HonoEndpointAdaptor-euH1oSdY.mjs} +105 -64
  45. package/dist/HonoEndpointAdaptor-euH1oSdY.mjs.map +1 -0
  46. package/dist/Queue-BhuofM3k.cjs +109 -0
  47. package/dist/Queue-BhuofM3k.cjs.map +1 -0
  48. package/dist/{Queue-D7ZuwBhy.d.cts → Queue-DlsHRzUp.d.mts} +48 -48
  49. package/dist/Queue-DlsHRzUp.d.mts.map +1 -0
  50. package/dist/{Queue-gVGfi2Yk.d.mts → Queue-HPyi0e1i.d.cts} +49 -49
  51. package/dist/Queue-HPyi0e1i.d.cts.map +1 -0
  52. package/dist/Queue-cmhqEBOB.mjs +104 -0
  53. package/dist/Queue-cmhqEBOB.mjs.map +1 -0
  54. package/dist/QueueBuilder-Cx9lKC5d.d.mts +75 -0
  55. package/dist/QueueBuilder-Cx9lKC5d.d.mts.map +1 -0
  56. package/dist/QueueBuilder-DXu1qxT1.mjs +118 -0
  57. package/dist/QueueBuilder-DXu1qxT1.mjs.map +1 -0
  58. package/dist/QueueBuilder-DdU2klPu.cjs +135 -0
  59. package/dist/QueueBuilder-DdU2klPu.cjs.map +1 -0
  60. package/dist/QueueBuilder-OSi6LkV9.d.cts +75 -0
  61. package/dist/QueueBuilder-OSi6LkV9.d.cts.map +1 -0
  62. package/dist/{Subscriber-2mEi0ImH.d.cts → Subscriber-Bpp02cGr.d.cts} +29 -20
  63. package/dist/Subscriber-Bpp02cGr.d.cts.map +1 -0
  64. package/dist/{Subscriber-xTJ9ayPN.d.mts → Subscriber-CtN9R48-.d.mts} +29 -20
  65. package/dist/Subscriber-CtN9R48-.d.mts.map +1 -0
  66. package/dist/SubscriberBuilder-4DWe9feX.d.mts +67 -0
  67. package/dist/SubscriberBuilder-4DWe9feX.d.mts.map +1 -0
  68. package/dist/{SubscriberBuilder-BjkbeT9l.mjs → SubscriberBuilder-DRXfxWn_.mjs} +50 -24
  69. package/dist/SubscriberBuilder-DRXfxWn_.mjs.map +1 -0
  70. package/dist/{SubscriberBuilder-4OPehf2R.cjs → SubscriberBuilder-M2EAgQhC.cjs} +61 -36
  71. package/dist/SubscriberBuilder-M2EAgQhC.cjs.map +1 -0
  72. package/dist/SubscriberBuilder-g3fAVWgs.d.cts +67 -0
  73. package/dist/SubscriberBuilder-g3fAVWgs.d.cts.map +1 -0
  74. package/dist/Topic-D2R0r24C.mjs +99 -0
  75. package/dist/Topic-D2R0r24C.mjs.map +1 -0
  76. package/dist/Topic-DwS3QO0m.cjs +104 -0
  77. package/dist/Topic-DwS3QO0m.cjs.map +1 -0
  78. package/dist/adaptors/aws.cjs +200 -246
  79. package/dist/adaptors/aws.cjs.map +1 -1
  80. package/dist/adaptors/aws.d.cts +58 -62
  81. package/dist/adaptors/aws.d.cts.map +1 -1
  82. package/dist/adaptors/aws.d.mts +59 -63
  83. package/dist/adaptors/aws.d.mts.map +1 -1
  84. package/dist/adaptors/aws.mjs +171 -219
  85. package/dist/adaptors/aws.mjs.map +1 -1
  86. package/dist/adaptors/hono.cjs +3 -10
  87. package/dist/adaptors/hono.d.cts +7 -16
  88. package/dist/adaptors/hono.d.cts.map +1 -1
  89. package/dist/adaptors/hono.d.mts +9 -18
  90. package/dist/adaptors/hono.d.mts.map +1 -1
  91. package/dist/adaptors/hono.mjs +2 -10
  92. package/dist/adaptors/testing.cjs +765 -99
  93. package/dist/adaptors/testing.cjs.map +1 -1
  94. package/dist/adaptors/testing.d.cts +351 -54
  95. package/dist/adaptors/testing.d.cts.map +1 -1
  96. package/dist/adaptors/testing.d.mts +351 -54
  97. package/dist/adaptors/testing.d.mts.map +1 -1
  98. package/dist/adaptors/testing.mjs +726 -78
  99. package/dist/adaptors/testing.mjs.map +1 -1
  100. package/dist/auth-BMCJN30Y.d.cts +268 -0
  101. package/dist/auth-BMCJN30Y.d.cts.map +1 -0
  102. package/dist/auth-D_0788uW.d.mts +268 -0
  103. package/dist/auth-D_0788uW.d.mts.map +1 -0
  104. package/dist/auth.cjs +301 -33
  105. package/dist/auth.cjs.map +1 -1
  106. package/dist/auth.d.cts +2 -108
  107. package/dist/auth.d.mts +2 -108
  108. package/dist/auth.mjs +289 -27
  109. package/dist/auth.mjs.map +1 -1
  110. package/dist/{cache-BrRz3fEB.d.mts → cache-5QZzh5Er.d.mts} +3 -6
  111. package/dist/cache-5QZzh5Er.d.mts.map +1 -0
  112. package/dist/{cache-BtZY_tHe.d.cts → cache-DnGDGly3.d.cts} +3 -6
  113. package/dist/cache-DnGDGly3.d.cts.map +1 -0
  114. package/dist/cache.cjs +68 -2
  115. package/dist/cache.cjs.map +1 -0
  116. package/dist/cache.d.cts +1 -2
  117. package/dist/cache.d.mts +1 -2
  118. package/dist/cache.mjs +67 -2
  119. package/dist/cache.mjs.map +1 -0
  120. package/dist/cipher-C1lEFX63.mjs +225 -0
  121. package/dist/cipher-C1lEFX63.mjs.map +1 -0
  122. package/dist/cipher-CVxfwLjk.cjs +332 -0
  123. package/dist/cipher-CVxfwLjk.cjs.map +1 -0
  124. package/dist/{clone-DblgEZZa.mjs → clone-EKNovYHu.mjs} +3 -3
  125. package/dist/clone-EKNovYHu.mjs.map +1 -0
  126. package/dist/{clone-Dy0cR2SZ.cjs → clone-UGJpvQnL.cjs} +7 -8
  127. package/dist/clone-UGJpvQnL.cjs.map +1 -0
  128. package/dist/{construct-interface-D9d4Gm4p.d.cts → construct-interface-B1AfqRl4.d.cts} +42 -11
  129. package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
  130. package/dist/{construct-interface-g5GM5pwR.d.mts → construct-interface-ZvYQbivO.d.mts} +42 -11
  131. package/dist/construct-interface-ZvYQbivO.d.mts.map +1 -0
  132. package/dist/construct-interface.cjs +113 -7
  133. package/dist/construct-interface.cjs.map +1 -0
  134. package/dist/construct-interface.d.cts +2 -2
  135. package/dist/construct-interface.d.mts +2 -2
  136. package/dist/construct-interface.mjs +106 -2
  137. package/dist/construct-interface.mjs.map +1 -0
  138. package/dist/credential-DYymbp_7.cjs +257 -0
  139. package/dist/credential-DYymbp_7.cjs.map +1 -0
  140. package/dist/credential-DfSAOOdY.mjs +222 -0
  141. package/dist/credential-DfSAOOdY.mjs.map +1 -0
  142. package/dist/credential.cjs +8 -96
  143. package/dist/credential.d.cts +2 -61
  144. package/dist/credential.d.mts +2 -61
  145. package/dist/credential.mjs +2 -94
  146. package/dist/crons/index.cjs +129 -7
  147. package/dist/crons/index.cjs.map +1 -1
  148. package/dist/crons/index.d.cts +45 -11
  149. package/dist/crons/index.d.cts.map +1 -1
  150. package/dist/crons/index.d.mts +45 -11
  151. package/dist/crons/index.d.mts.map +1 -1
  152. package/dist/crons/index.mjs +127 -8
  153. package/dist/crons/index.mjs.map +1 -1
  154. package/dist/database/kysely.cjs +4 -181
  155. package/dist/database/kysely.d.cts +2 -152
  156. package/dist/database/kysely.d.mts +2 -152
  157. package/dist/database/kysely.mjs +2 -180
  158. package/dist/email.cjs +25 -12
  159. package/dist/email.cjs.map +1 -1
  160. package/dist/email.d.cts +3 -7
  161. package/dist/email.d.cts.map +1 -1
  162. package/dist/email.d.mts +4 -8
  163. package/dist/email.d.mts.map +1 -1
  164. package/dist/email.mjs +16 -3
  165. package/dist/email.mjs.map +1 -1
  166. package/dist/encryption.cjs +96 -0
  167. package/dist/encryption.cjs.map +1 -0
  168. package/dist/encryption.d.cts +117 -0
  169. package/dist/encryption.d.cts.map +1 -0
  170. package/dist/encryption.d.mts +117 -0
  171. package/dist/encryption.d.mts.map +1 -0
  172. package/dist/encryption.mjs +83 -0
  173. package/dist/encryption.mjs.map +1 -0
  174. package/dist/endpoints/index.cjs +20 -16
  175. package/dist/endpoints/index.d.cts +105 -7
  176. package/dist/endpoints/index.d.cts.map +1 -0
  177. package/dist/endpoints/index.d.mts +105 -7
  178. package/dist/endpoints/index.d.mts.map +1 -0
  179. package/dist/endpoints/index.mjs +6 -10
  180. package/dist/external-api.cjs +106 -0
  181. package/dist/external-api.cjs.map +1 -0
  182. package/dist/external-api.d.cts +2 -0
  183. package/dist/external-api.d.mts +2 -0
  184. package/dist/external-api.mjs +103 -0
  185. package/dist/external-api.mjs.map +1 -0
  186. package/dist/fake-DqKo8INJ.d.mts +201 -0
  187. package/dist/fake-DqKo8INJ.d.mts.map +1 -0
  188. package/dist/fake-Dvion_Fh.d.cts +201 -0
  189. package/dist/fake-Dvion_Fh.d.cts.map +1 -0
  190. package/dist/file-server.cjs +42 -10
  191. package/dist/file-server.cjs.map +1 -1
  192. package/dist/file-server.d.cts +6 -10
  193. package/dist/file-server.d.cts.map +1 -1
  194. package/dist/file-server.d.mts +6 -10
  195. package/dist/file-server.d.mts.map +1 -1
  196. package/dist/file-server.mjs +34 -2
  197. package/dist/file-server.mjs.map +1 -1
  198. package/dist/functions/index.cjs +3 -6
  199. package/dist/functions/index.d.cts +3 -4
  200. package/dist/functions/index.d.mts +3 -4
  201. package/dist/functions/index.mjs +2 -6
  202. package/dist/{functions-14lpEFL4.mjs → functions-CTI-hDem.mjs} +376 -238
  203. package/dist/{functions-14lpEFL4.mjs.map → functions-CTI-hDem.mjs.map} +1 -1
  204. package/dist/{functions-i_la-N5r.cjs → functions-D7O5SGVc.cjs} +414 -264
  205. package/dist/functions-D7O5SGVc.cjs.map +1 -0
  206. package/dist/index-B13kQB_U.d.mts +115 -0
  207. package/dist/index-B13kQB_U.d.mts.map +1 -0
  208. package/dist/index-BuzRvKOQ.d.cts +115 -0
  209. package/dist/index-BuzRvKOQ.d.cts.map +1 -0
  210. package/dist/index-CeEtxDmK.d.cts +79 -0
  211. package/dist/index-CeEtxDmK.d.cts.map +1 -0
  212. package/dist/index-CeEtxDmK.d.mts +79 -0
  213. package/dist/index-CeEtxDmK.d.mts.map +1 -0
  214. package/dist/index.cjs +6 -3
  215. package/dist/index.d.cts +27 -4
  216. package/dist/index.d.cts.map +1 -0
  217. package/dist/index.d.mts +27 -4
  218. package/dist/index.d.mts.map +1 -0
  219. package/dist/index.mjs +3 -3
  220. package/dist/kms-B-Hm3d5r.cjs +85 -0
  221. package/dist/kms-B-Hm3d5r.cjs.map +1 -0
  222. package/dist/kms-BdUlMJEZ.mjs +85 -0
  223. package/dist/kms-BdUlMJEZ.mjs.map +1 -0
  224. package/dist/kysely-B3zfg9ti.cjs +383 -0
  225. package/dist/kysely-B3zfg9ti.cjs.map +1 -0
  226. package/dist/kysely-B_0BAr0T.mjs +370 -0
  227. package/dist/kysely-B_0BAr0T.mjs.map +1 -0
  228. package/dist/kysely-D0bpzgPs.d.cts +175 -0
  229. package/dist/kysely-D0bpzgPs.d.cts.map +1 -0
  230. package/dist/kysely-DKwnl0nf.d.mts +175 -0
  231. package/dist/kysely-DKwnl0nf.d.mts.map +1 -0
  232. package/dist/{telemetry-C3L0iS28.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +3 -6
  233. package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
  234. package/dist/{telemetry-D7bVFLGi.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +3 -6
  235. package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
  236. package/dist/mobile-app.cjs +73 -0
  237. package/dist/mobile-app.cjs.map +1 -0
  238. package/dist/mobile-app.d.cts +61 -0
  239. package/dist/mobile-app.d.cts.map +1 -0
  240. package/dist/mobile-app.d.mts +61 -0
  241. package/dist/mobile-app.d.mts.map +1 -0
  242. package/dist/mobile-app.mjs +72 -0
  243. package/dist/mobile-app.mjs.map +1 -0
  244. package/dist/object-storage.cjs +18 -10
  245. package/dist/object-storage.cjs.map +1 -1
  246. package/dist/object-storage.d.cts +3 -7
  247. package/dist/object-storage.d.cts.map +1 -1
  248. package/dist/object-storage.d.mts +3 -7
  249. package/dist/object-storage.d.mts.map +1 -1
  250. package/dist/object-storage.mjs +11 -3
  251. package/dist/object-storage.mjs.map +1 -1
  252. package/dist/queue/index.cjs +6 -189
  253. package/dist/queue/index.d.cts +3 -60
  254. package/dist/queue/index.d.mts +3 -60
  255. package/dist/queue/index.mjs +3 -186
  256. package/dist/random-password.cjs +86 -0
  257. package/dist/random-password.cjs.map +1 -0
  258. package/dist/random-password.d.cts +30 -0
  259. package/dist/random-password.d.cts.map +1 -0
  260. package/dist/random-password.d.mts +30 -0
  261. package/dist/random-password.d.mts.map +1 -0
  262. package/dist/random-password.mjs +84 -0
  263. package/dist/random-password.mjs.map +1 -0
  264. package/dist/{lazyAccessors-BoJN3SMd.mjs → readRequestBody-BTIl3k-D.mjs} +117 -60
  265. package/dist/readRequestBody-BTIl3k-D.mjs.map +1 -0
  266. package/dist/readRequestBody-Dej_L3c4.cjs +342 -0
  267. package/dist/readRequestBody-Dej_L3c4.cjs.map +1 -0
  268. package/dist/requestLogger-BZcXwdBs.cjs +207 -0
  269. package/dist/requestLogger-BZcXwdBs.cjs.map +1 -0
  270. package/dist/requestLogger-pA4gi3E1.mjs +178 -0
  271. package/dist/requestLogger-pA4gi3E1.mjs.map +1 -0
  272. package/dist/rest-api.cjs +90 -59
  273. package/dist/rest-api.cjs.map +1 -1
  274. package/dist/rest-api.d.cts +70 -42
  275. package/dist/rest-api.d.cts.map +1 -1
  276. package/dist/rest-api.d.mts +70 -42
  277. package/dist/rest-api.d.mts.map +1 -1
  278. package/dist/rest-api.mjs +82 -51
  279. package/dist/rest-api.mjs.map +1 -1
  280. package/dist/{chunk-DWy1uDak.cjs → rolldown-runtime-y5ARvAq5.cjs} +14 -18
  281. package/dist/runSubscriber-BHvJ8POr.mjs +109 -0
  282. package/dist/runSubscriber-BHvJ8POr.mjs.map +1 -0
  283. package/dist/runSubscriber-D8nLXIv1.cjs +126 -0
  284. package/dist/runSubscriber-D8nLXIv1.cjs.map +1 -0
  285. package/dist/shutdown-BMJmAhSt.cjs +38 -0
  286. package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
  287. package/dist/shutdown-C7xa8x9S.mjs +27 -0
  288. package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
  289. package/dist/site.cjs +33 -7
  290. package/dist/site.cjs.map +1 -1
  291. package/dist/site.d.cts +17 -7
  292. package/dist/site.d.cts.map +1 -1
  293. package/dist/site.d.mts +17 -7
  294. package/dist/site.d.mts.map +1 -1
  295. package/dist/site.mjs +29 -3
  296. package/dist/site.mjs.map +1 -1
  297. package/dist/stages-BSCF19o2.d.cts +56 -0
  298. package/dist/stages-BSCF19o2.d.cts.map +1 -0
  299. package/dist/stages-BSCF19o2.d.mts +56 -0
  300. package/dist/stages-BSCF19o2.d.mts.map +1 -0
  301. package/dist/subscribers/index.cjs +118 -6
  302. package/dist/subscribers/index.cjs.map +1 -0
  303. package/dist/subscribers/index.d.cts +51 -6
  304. package/dist/subscribers/index.d.cts.map +1 -0
  305. package/dist/subscribers/index.d.mts +51 -6
  306. package/dist/subscribers/index.d.mts.map +1 -0
  307. package/dist/subscribers/index.mjs +115 -5
  308. package/dist/subscribers/index.mjs.map +1 -0
  309. package/dist/surfaceEnv-CNimK76p.cjs +56 -0
  310. package/dist/surfaceEnv-CNimK76p.cjs.map +1 -0
  311. package/dist/surfaceEnv-wMT5QzgZ.mjs +45 -0
  312. package/dist/surfaceEnv-wMT5QzgZ.mjs.map +1 -0
  313. package/dist/telemetry-B48RLjyk.d.cts +40 -0
  314. package/dist/telemetry-B48RLjyk.d.cts.map +1 -0
  315. package/dist/telemetry-BEoBn6GO.d.mts +40 -0
  316. package/dist/telemetry-BEoBn6GO.d.mts.map +1 -0
  317. package/dist/telemetry.cjs +56 -0
  318. package/dist/telemetry.cjs.map +1 -0
  319. package/dist/telemetry.d.cts +2 -0
  320. package/dist/telemetry.d.mts +2 -0
  321. package/dist/telemetry.mjs +55 -0
  322. package/dist/telemetry.mjs.map +1 -0
  323. package/dist/topic/index.cjs +3 -137
  324. package/dist/topic/index.d.cts +2 -4
  325. package/dist/topic/index.d.mts +2 -4
  326. package/dist/topic/index.mjs +2 -134
  327. package/dist/tracing-Bbj1uoFJ.mjs +127 -0
  328. package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
  329. package/dist/tracing-C0ooU0V2.cjs +150 -0
  330. package/dist/tracing-C0ooU0V2.cjs.map +1 -0
  331. package/dist/{types-BlAkSuGI.d.cts → types-DMuSQeLL.d.cts} +3 -5
  332. package/dist/types-DMuSQeLL.d.cts.map +1 -0
  333. package/dist/{types-aKksMEWL.d.mts → types-DMuSQeLL.d.mts} +3 -5
  334. package/dist/types-DMuSQeLL.d.mts.map +1 -0
  335. package/dist/types.d.cts +1 -1
  336. package/dist/types.d.mts +1 -1
  337. package/dist/types.mjs +1 -0
  338. package/dist/worker.cjs +59 -34
  339. package/dist/worker.cjs.map +1 -1
  340. package/dist/worker.d.cts +70 -45
  341. package/dist/worker.d.cts.map +1 -1
  342. package/dist/worker.d.mts +71 -46
  343. package/dist/worker.d.mts.map +1 -1
  344. package/dist/worker.mjs +54 -29
  345. package/dist/worker.mjs.map +1 -1
  346. package/package.json +106 -42
  347. package/dist/Construct-BD5neF7w.mjs.map +0 -1
  348. package/dist/Construct-C0ijr2qp.d.cts +0 -117
  349. package/dist/Construct-C0ijr2qp.d.cts.map +0 -1
  350. package/dist/Construct-Ct8nalEi.d.mts +0 -117
  351. package/dist/Construct-Ct8nalEi.d.mts.map +0 -1
  352. package/dist/Construct-CyS3RpTL.cjs.map +0 -1
  353. package/dist/Cron-DmQ8vQ4b.d.cts.map +0 -1
  354. package/dist/Cron-dh4rUgib.d.mts.map +0 -1
  355. package/dist/CronBuilder-BquXDbDI.d.cts +0 -44
  356. package/dist/CronBuilder-BquXDbDI.d.cts.map +0 -1
  357. package/dist/CronBuilder-CGgY2080.d.mts +0 -44
  358. package/dist/CronBuilder-CGgY2080.d.mts.map +0 -1
  359. package/dist/CronBuilder-CYKT5RiO.mjs.map +0 -1
  360. package/dist/CronBuilder-Da0C0edR.cjs.map +0 -1
  361. package/dist/Endpoint-BjWKinFA.d.mts.map +0 -1
  362. package/dist/Endpoint-DCQPMdUX.mjs.map +0 -1
  363. package/dist/Endpoint-DcWXE-SZ.cjs.map +0 -1
  364. package/dist/Endpoint-dav89W6-.d.cts.map +0 -1
  365. package/dist/EndpointFactory-CdWB7wPw.cjs.map +0 -1
  366. package/dist/EndpointFactory-CjV8F_lJ.mjs.map +0 -1
  367. package/dist/HonoEndpointAdaptor-DtL9j19R.cjs.map +0 -1
  368. package/dist/HonoEndpointAdaptor-P1ahhZHu.mjs.map +0 -1
  369. package/dist/Queue-D7ZuwBhy.d.cts.map +0 -1
  370. package/dist/Queue-gVGfi2Yk.d.mts.map +0 -1
  371. package/dist/Subscriber-2mEi0ImH.d.cts.map +0 -1
  372. package/dist/Subscriber-xTJ9ayPN.d.mts.map +0 -1
  373. package/dist/SubscriberBuilder-4OPehf2R.cjs.map +0 -1
  374. package/dist/SubscriberBuilder-BjkbeT9l.mjs.map +0 -1
  375. package/dist/SubscriberBuilder-Dptmo-1A.d.mts +0 -62
  376. package/dist/SubscriberBuilder-Dptmo-1A.d.mts.map +0 -1
  377. package/dist/SubscriberBuilder-waNhzjSM.d.cts +0 -62
  378. package/dist/SubscriberBuilder-waNhzjSM.d.cts.map +0 -1
  379. package/dist/Topic-19QeHBIR.d.cts +0 -91
  380. package/dist/Topic-19QeHBIR.d.cts.map +0 -1
  381. package/dist/Topic-DuFeqkBh.d.mts +0 -91
  382. package/dist/Topic-DuFeqkBh.d.mts.map +0 -1
  383. package/dist/auth.d.cts.map +0 -1
  384. package/dist/auth.d.mts.map +0 -1
  385. package/dist/cache-0ANvRQnD.mjs +0 -51
  386. package/dist/cache-0ANvRQnD.mjs.map +0 -1
  387. package/dist/cache-3WSvAulx.cjs +0 -57
  388. package/dist/cache-3WSvAulx.cjs.map +0 -1
  389. package/dist/cache-BrRz3fEB.d.mts.map +0 -1
  390. package/dist/cache-BtZY_tHe.d.cts.map +0 -1
  391. package/dist/clone-DblgEZZa.mjs.map +0 -1
  392. package/dist/clone-Dy0cR2SZ.cjs.map +0 -1
  393. package/dist/construct-interface-BfjcOD_E.cjs +0 -117
  394. package/dist/construct-interface-BfjcOD_E.cjs.map +0 -1
  395. package/dist/construct-interface-D9d4Gm4p.d.cts.map +0 -1
  396. package/dist/construct-interface-Z4CpS8tK.mjs +0 -81
  397. package/dist/construct-interface-Z4CpS8tK.mjs.map +0 -1
  398. package/dist/construct-interface-g5GM5pwR.d.mts.map +0 -1
  399. package/dist/credential.cjs.map +0 -1
  400. package/dist/credential.d.cts.map +0 -1
  401. package/dist/credential.d.mts.map +0 -1
  402. package/dist/credential.mjs.map +0 -1
  403. package/dist/database/kysely.cjs.map +0 -1
  404. package/dist/database/kysely.d.cts.map +0 -1
  405. package/dist/database/kysely.d.mts.map +0 -1
  406. package/dist/database/kysely.mjs.map +0 -1
  407. package/dist/functions-i_la-N5r.cjs.map +0 -1
  408. package/dist/index-Bd5FqCoe.d.cts.map +0 -1
  409. package/dist/index-BknhM6Ux.d.mts +0 -31
  410. package/dist/index-BknhM6Ux.d.mts.map +0 -1
  411. package/dist/index-CBSfrowv.d.cts +0 -31
  412. package/dist/index-CBSfrowv.d.cts.map +0 -1
  413. package/dist/index-D24Xm79M.d.cts +0 -171
  414. package/dist/index-D24Xm79M.d.cts.map +0 -1
  415. package/dist/index-_ajboYxK.d.mts +0 -171
  416. package/dist/index-_ajboYxK.d.mts.map +0 -1
  417. package/dist/index-lAO9egTb.d.mts.map +0 -1
  418. package/dist/lazyAccessors-BoJN3SMd.mjs.map +0 -1
  419. package/dist/lazyAccessors-e3j2oE2m.cjs +0 -274
  420. package/dist/lazyAccessors-e3j2oE2m.cjs.map +0 -1
  421. package/dist/processAudits-CGqttuXm.cjs +0 -92
  422. package/dist/processAudits-CGqttuXm.cjs.map +0 -1
  423. package/dist/processAudits-Dmts9H_b.mjs +0 -80
  424. package/dist/processAudits-Dmts9H_b.mjs.map +0 -1
  425. package/dist/queue/index.cjs.map +0 -1
  426. package/dist/queue/index.d.cts.map +0 -1
  427. package/dist/queue/index.d.mts.map +0 -1
  428. package/dist/queue/index.mjs.map +0 -1
  429. package/dist/surfaceEnv-BFXEms2f.cjs +0 -39
  430. package/dist/surfaceEnv-BFXEms2f.cjs.map +0 -1
  431. package/dist/surfaceEnv-C3Ktahea.mjs +0 -27
  432. package/dist/surfaceEnv-C3Ktahea.mjs.map +0 -1
  433. package/dist/telemetry-C3L0iS28.d.cts.map +0 -1
  434. package/dist/telemetry-D7bVFLGi.d.mts.map +0 -1
  435. package/dist/topic/index.cjs.map +0 -1
  436. package/dist/topic/index.mjs.map +0 -1
  437. package/dist/types-BlAkSuGI.d.cts.map +0 -1
  438. package/dist/types-aKksMEWL.d.mts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"rest-api.mjs","names":["id: ConstructName<TName>","config: RestApiConfig<TAuthorizers>","dependencies: readonly Dependency[]","authenticator?: string","path: TPath","construct: Declarable","constructs: readonly Declarable[]"],"sources":["../src/rest-api.ts"],"sourcesContent":["/**\n * `RestApi` — the application's own HTTP surface, declared.\n *\n * Everything an app serves already existed; what did not exist was a *node* for\n * it. Without one, three things that are properties of the graph had to be\n * written down somewhere else: which origins the API accepts, which origins the\n * auth server trusts, and which URL a frontend is built against. All three were\n * being derived by walking the workspace config for ports — a second mechanism,\n * running beside the graph and answering the same question worse, since it can\n * only ever describe what this repo happens to run.\n *\n * With the surface declared, all three become one edge read backwards: a\n * consumer depends on the API, and *that* is the CORS entry, the trusted origin,\n * and the build-time URL. Nothing enumerates its own callers.\n *\n * ```ts\n * export const api = new RestApi('Api', {\n * authorizers: ['session'],\n * defaultAuthorizer: 'session',\n * });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n} from '@geekmidas/manifest';\nimport type { Telescope } from '@geekmidas/telescope';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { BuiltInSecuritySchemeId } from './endpoints/Authorizer';\nimport { EndpointFactory } from './endpoints/EndpointFactory';\nimport { envParserFor } from './endpoints/surfaceEnv';\n\nexport interface RestApiConfig<\n\t// `readonly []` rather than `readonly string[]`: a surface that declares no\n\t// authorizers of its own should narrow `defaultAuthorizer` to the built-ins\n\t// and `'none'`, not widen it back to any string.\n\tTAuthorizers extends readonly string[] = readonly [],\n> {\n\t/**\n\t * The app that serves this surface, relative to the workspace root —\n\t * `'apps/api'`, or `'.'` in a single-app project.\n\t *\n\t * Required. It was inferred from the id (`apps/<kebab-id>`, or the root\n\t * when no such directory existed), which meant a surface's home was\n\t * whatever happened to be on disk. It is where the app's `package.json`\n\t * and base `tsconfig.json` are, and which build serves this surface. It\n\t * does not change discovery: constructs still load from the workspace's\n\t * `constructs` glob.\n\t */\n\tpath: string;\n\t/**\n\t * CORS tunables. The *origins* are never here — they are read off the\n\t * constructs that declared an edge to this surface, which is the whole point\n\t * of declaring one. These are the parts a graph cannot answer.\n\t */\n\tcors?: {\n\t\tmaxAge?: number;\n\t\tcredentials?: boolean;\n\t\tallowHeaders?: readonly string[];\n\t\texposeHeaders?: readonly string[];\n\t};\n\t/**\n\t * The authorizer names this surface exposes. Names only — what verifies a\n\t * request legitimately differs between local and deployed, so the mechanism\n\t * belongs to the target and never to portable code.\n\t */\n\tauthorizers?: TAuthorizers;\n\t/**\n\t * The authorizer applied to an endpoint that names none.\n\t *\n\t * Required, and `'none'` is a valid answer that has to be typed out. The\n\t * alternative is an API that ships open because a field was left off, which\n\t * is the one default worth refusing to have.\n\t *\n\t * It was called `default`, which said what it was to the type and nothing\n\t * to the reader: next to `authorizers: ['iam']`, a bare `default: 'none'`\n\t * could be defaulting the runtime or the target. The manifest has always\n\t * called it `defaultAuthorizer` and the factory `defaultAuthorizerName`;\n\t * this is the same fact under the same name.\n\t *\n\t * Typed from `authorizers`, so it can only name one this surface exposes —\n\t * plus a built-in scheme, and `'none'`. It was a bare `string`, which let\n\t * `defaultAuthorizer: 'jwtt'` compile and every endpoint on the surface\n\t * default to an authorizer that does not exist.\n\t */\n\tdefaultAuthorizer: TAuthorizers[number] | BuiltInSecuritySchemeId | 'none';\n\t/**\n\t * The logger every endpoint on this surface runs with.\n\t *\n\t * The actual logger, not a path to one. It used to be named in config as\n\t * `logger: './config/logger'`, because the build wrote an import into each\n\t * generated handler and a generator can print a specifier but not an object.\n\t * Endpoints built from the surface carry it, so there is nothing to print\n\t * and nothing to keep in step with a moved file.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser every endpoint on this surface runs with.\n\t *\n\t * Same reason as `logger`, and the same field it replaces —\n\t * `envParser: './config/env#envParser'`, a module path with an export name\n\t * appended, parsed by us, checked by nothing.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * The Telescope instance this surface's entry mounts.\n\t *\n\t * The actual instance, for the reason `logger` is: it used to be named as\n\t * `telescope: './config/telescope#telescope'`, a module path the build\n\t * printed an import for. The entry already imports the surface.\n\t */\n\ttelescope?: Telescope;\n}\n\n/**\n * What is *not* here, and why.\n *\n * `dependsOn`, `database`, `auditor` and `publisher` all inject a capability\n * into a handler. Putting one on the surface hands it to every route the\n * surface serves — a health check gets the database because a report needed it\n * — which is the thing least privilege forbids and the reason `.calls()` is not\n * spelled `dependsOn`. They belong to the endpoint, or to a factory branched\n * from `api.endpoints` for a group of endpoints that genuinely share them.\n *\n * `auth` is not here either: `.auth(construct)` already declares it, and a\n * second way to say the same thing is the duplication this whole model removes.\n *\n * What is left is what the *process* is rather than what a route may reach.\n */\n\nexport class RestApi<\n\tTName extends string = string,\n\tconst TAuthorizers extends readonly string[] = readonly [],\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/**\n\t * Declared once and read by both `declare()` and anything that consumes this\n\t * surface, so what the target publishes and what a consumer reads cannot\n\t * drift.\n\t */\n\treadonly keys: {\n\t\turl: string;\n\t\ttrustedOrigins: string;\n\t\tcookieDomain: string;\n\t};\n\n\t/**\n\t * The logger every endpoint on this surface runs with.\n\t *\n\t * Always defined — the surface's own if it was given one, the console\n\t * logger otherwise — so nothing downstream has to decide what to do about a\n\t * missing one. The generated entry reads it from here.\n\t */\n\treadonly logger: Logger;\n\n\t/**\n\t * The environment parser every endpoint on this surface runs with.\n\t *\n\t * Always defined, and normally the default: `process.env` merged with the\n\t * credentials `gkm dev`/`gkm exec` injected. That is what every\n\t * application's own `config/env.ts` was — boilerplate identical in every\n\t * project, and mandatory, which is a poor combination.\n\t */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/** The Telescope instance, when this surface was given one. */\n\treadonly telescope?: Telescope;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: RestApiConfig<TAuthorizers>,\n\t\t/** Internal: how `.calls()` carries edges into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\t/** Internal: how `.auth()` carries the authenticator into its copy. */\n\t\tprivate readonly authenticator?: string,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\n\t\tthis.keys = {\n\t\t\turl: provideKey(canonical, 'url'),\n\t\t\ttrustedOrigins: provideKey(canonical, 'trustedOrigins'),\n\t\t\tcookieDomain: provideKey(canonical, 'cookieDomain'),\n\t\t};\n\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.telescope = config.telescope;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\n\t\tthis.endpoints = new EndpointFactory({\n\t\t\tdefaultLogger: this.logger,\n\t\t\t...(config.authorizers\n\t\t\t\t? {\n\t\t\t\t\t\tavailableAuthorizers: config.authorizers.map((name) => ({ name })),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t// `'none'` reaches the factory as no default at all, which is what\n\t\t\t// public means to an endpoint that names no authorizer.\n\t\t\t...(config.defaultAuthorizer && config.defaultAuthorizer !== 'none'\n\t\t\t\t? { defaultAuthorizerName: config.defaultAuthorizer }\n\t\t\t\t: {}),\n\t\t\tsurface: { id: this.id, envParser: this.envParser },\n\t\t});\n\t}\n\n\t/**\n\t * This surface's endpoint factory.\n\t *\n\t * `api.get('/users')` is the short form and covers most routes. Reach for\n\t * this one when a *group* of endpoints shares something a single route would\n\t * otherwise repeat — a database, an auditor, a publisher:\n\t *\n\t * ```ts\n\t * const audited = api.endpoints.database(db).auditor(AuditStore);\n\t * export const createUser = audited.post('/users').handle(...);\n\t * ```\n\t *\n\t * A factory branched from here keeps the surface, so its endpoints still\n\t * know which API serves them. That is deliberately narrower than putting the\n\t * same thing in the surface's own config: a group opts in, where a surface\n\t * would grant it to every route it serves.\n\t */\n\treadonly endpoints: EndpointFactory<[], '', Logger>;\n\n\t/** `api.get('/users')` — sugar for `api.endpoints.get('/users')`. */\n\tget<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.get(path);\n\t}\n\n\tpost<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.post(path);\n\t}\n\n\tput<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.put(path);\n\t}\n\n\tpatch<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.patch(path);\n\t}\n\n\tdelete<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.delete(path);\n\t}\n\n\toptions<TPath extends string>(path: TPath) {\n\t\treturn this.endpoints.options(path);\n\t}\n\n\t/**\n\t * What authenticates this surface.\n\t *\n\t * An edge like `.calls()` — the auth server learns this origin, and the two\n\t * share a cookie domain — but a named one, because *who authenticates me* is\n\t * a different fact from *who I happen to call*, and only one of them decides\n\t * what a request is allowed to be. A surface with two of the first is a\n\t * mistake; two of the second is Tuesday.\n\t *\n\t * It records the id, not a client. Every endpoint consumes the same thing —\n\t * `verify(request) → Session | null` — and that is what every provider\n\t * shares, whether the server is mounted in this process, deployed beside it,\n\t * or an OIDC issuer somebody else runs.\n\t */\n\tauth(construct: Declarable): RestApi<TName, TAuthorizers> {\n\t\treturn new RestApi<TName, TAuthorizers>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(construct)],\n\t\t\tconstruct.id,\n\t\t);\n\t}\n\n\t/**\n\t * Other surfaces this one calls.\n\t *\n\t * **Not `.dependsOn()`, and the difference matters.** An endpoint's\n\t * `.dependsOn()` injects a client into that handler and grants it exactly\n\t * what it named. This grants nothing and injects nothing: it records that\n\t * this API calls another surface, which is what puts this API's origin on\n\t * that surface's trusted-origin list.\n\t *\n\t * Spelling it `dependsOn` would invite the thing least privilege forbids —\n\t * every route on the surface receiving whatever the surface named.\n\t *\n\t * Immutable, like every other builder here.\n\t */\n\tcalls(constructs: readonly Declarable[]): RestApi<TName, TAuthorizers> {\n\t\treturn new RestApi<TName, TAuthorizers>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, ...constructs.map(edgeTo)],\n\t\t\tthis.authenticator,\n\t\t);\n\t}\n\n\t/**\n\t * One surface node, with its endpoints left to the build.\n\t *\n\t * The three provided keys are one fact about this surface and two about its\n\t * callers. Declaring the caller-derived pair here rather than having the\n\t * target invent them is what makes the contract checkable: a target that\n\t * resolves no origins is caught against this list instead of being noticed\n\t * when a browser is refused in production.\n\t */\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'rest-api',\n\t\t\t\tid: this.id,\n\t\t\t\tpath: this.config.path,\n\t\t\t\t...(this.config.telescope ? { telescope: true } : {}),\n\t\t\t\t...(this.config.cors ? { cors: this.config.cors } : {}),\n\t\t\t\t...(this.authenticator ? { auth: this.authenticator } : {}),\n\t\t\t\t// Filled by the build, which already generates one handler per\n\t\t\t\t// endpoint and knows the path it wrote it to. A surface that\n\t\t\t\t// enumerates its own routes statically — an auth server's single\n\t\t\t\t// wildcard — puts them here instead.\n\t\t\t\tendpoints: [],\n\t\t\t\t...(this.dependencies.length ? { calls: this.dependencies } : {}),\n\t\t\t\t...(this.config.authorizers?.length\n\t\t\t\t\t? { authorizers: this.config.authorizers }\n\t\t\t\t\t: {}),\n\t\t\t\tdefaultAuthorizer: this.config.defaultAuthorizer,\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\tthis.keys.trustedOrigins,\n\t\t\t\t\tthis.keys.cookieDomain,\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,IAAa,UAAb,MAAa,QAIb;CACC,AAAS;;;;;;CAOT,AAAS;;;;;;;;CAaT,AAAS;;;;;;;;;CAUT,AAAS;;CAGT,AAAS;CAET,YACCA,IACiBC,QAEAC,eAAsC,CAAE,GAExCC,eAChB;EALgB;EAEA;EAEA;EAEjB,MAAM,YAAY,YAAY,GAAa;AAE3C,OAAK,KAAK;AAEV,OAAK,OAAO;GACX,KAAK,WAAW,WAAW,MAAM;GACjC,gBAAgB,WAAW,WAAW,iBAAiB;GACvD,cAAc,WAAW,WAAW,eAAe;EACnD;AAED,OAAK,SAAS,OAAO,UAAU;AAC/B,OAAK,YAAY,OAAO;AACxB,OAAK,YAAY,aAChB,OAAO,YACJ;GAAE,IAAI;GAAW,WAAW,OAAO;EAAW,WAEjD;AAED,OAAK,YAAY,IAAI,gBAAgB;GACpC,eAAe,KAAK;GACpB,GAAI,OAAO,cACR,EACA,sBAAsB,OAAO,YAAY,IAAI,CAAC,UAAU,EAAE,KAAM,GAAE,CAClE,IACA,CAAE;GAGL,GAAI,OAAO,qBAAqB,OAAO,sBAAsB,SAC1D,EAAE,uBAAuB,OAAO,kBAAmB,IACnD,CAAE;GACL,SAAS;IAAE,IAAI,KAAK;IAAI,WAAW,KAAK;GAAW;EACnD;CACD;;;;;;;;;;;;;;;;;;CAmBD,AAAS;;CAGT,IAA0BC,MAAa;AACtC,SAAO,KAAK,UAAU,IAAI,KAAK;CAC/B;CAED,KAA2BA,MAAa;AACvC,SAAO,KAAK,UAAU,KAAK,KAAK;CAChC;CAED,IAA0BA,MAAa;AACtC,SAAO,KAAK,UAAU,IAAI,KAAK;CAC/B;CAED,MAA4BA,MAAa;AACxC,SAAO,KAAK,UAAU,MAAM,KAAK;CACjC;CAED,OAA6BA,MAAa;AACzC,SAAO,KAAK,UAAU,OAAO,KAAK;CAClC;CAED,QAA8BA,MAAa;AAC1C,SAAO,KAAK,UAAU,QAAQ,KAAK;CACnC;;;;;;;;;;;;;;;CAgBD,KAAKC,WAAqD;AACzD,SAAO,IAAI,QACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,OAAO,UAAU,AAAC,GACzC,UAAU;CAEX;;;;;;;;;;;;;;;CAgBD,MAAMC,YAAiE;AACtE,SAAO,IAAI,QACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,GAAG,WAAW,IAAI,OAAO,AAAC,GACjD,KAAK;CAEN;;;;;;;;;;CAWD,UAAyB;AACxB,SAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,MAAM,KAAK,OAAO;GAClB,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAM,IAAG,CAAE;GACpD,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAM,IAAG,CAAE;GACtD,GAAI,KAAK,gBAAgB,EAAE,MAAM,KAAK,cAAe,IAAG,CAAE;GAK1D,WAAW,CAAE;GACb,GAAI,KAAK,aAAa,SAAS,EAAE,OAAO,KAAK,aAAc,IAAG,CAAE;GAChE,GAAI,KAAK,OAAO,aAAa,SAC1B,EAAE,aAAa,KAAK,OAAO,YAAa,IACxC,CAAE;GACL,mBAAmB,KAAK,OAAO;GAC/B,UAAU;IACT,KAAK,KAAK;IACV,KAAK,KAAK;IACV,KAAK,KAAK;GACV;EACD,CACD;CACD;AACD"}
1
+ {"version":3,"file":"rest-api.mjs","names":[],"sources":["../src/rest-api.ts"],"sourcesContent":["/**\n * `RestApi` — the application's own HTTP surface, declared.\n *\n * Everything an app serves already existed; what did not exist was a *node* for\n * it. Without one, three things that are properties of the graph had to be\n * written down somewhere else: which origins the API accepts, which origins the\n * auth server trusts, and which URL a frontend is built against. All three were\n * being derived by walking the workspace config for ports — a second mechanism,\n * running beside the graph and answering the same question worse, since it can\n * only ever describe what this repo happens to run.\n *\n * With the surface declared, all three become one edge read backwards: a\n * consumer depends on the API, and *that* is the CORS entry, the trusted origin,\n * and the build-time URL. Nothing enumerates its own callers.\n *\n * ```ts\n * export const api = new RestApi('Api', {\n * authorizers: ['session'],\n * defaultAuthorizer: 'session',\n * });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n} from '@geekmidas/manifest';\nimport type { Telescope } from '@geekmidas/telescope';\nimport {\n\ttype Authenticator,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\n\nexport type { Authenticator } from './construct-interface';\n\nimport {\n\ttype BuiltInSecuritySchemeId,\n\tgetSecurityScheme,\n} from './endpoints/Authorizer';\nimport { EndpointFactory } from './endpoints/EndpointFactory';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport type { Telemetry } from './telemetry';\n\n/** The factory a surface builds its endpoints from. */\ntype Endpoints = EndpointFactory<[], '', Logger>;\n\nexport interface RestApiConfig<\n\t// `readonly []` rather than `readonly string[]`: a surface that declares no\n\t// authorizers of its own should narrow `defaultAuthorizer` to the built-ins\n\t// and `'none'`, not widen it back to any string.\n\tTAuthorizers extends readonly string[] = readonly [],\n> {\n\t/**\n\t * The app that serves this surface, relative to the workspace root —\n\t * `'apps/api'`, or `'.'` in a single-app project.\n\t *\n\t * Required. It was inferred from the id (`apps/<kebab-id>`, or the root\n\t * when no such directory existed), which meant a surface's home was\n\t * whatever happened to be on disk. It is where the app's `package.json`\n\t * and base `tsconfig.json` are, and which build serves this surface. It\n\t * does not change discovery: constructs still load from the workspace's\n\t * `constructs` glob.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * CORS tunables. The *origins* are never here — they are read off the\n\t * constructs that declared an edge to this surface, which is the whole point\n\t * of declaring one. These are the parts a graph cannot answer.\n\t */\n\tcors?: {\n\t\tmaxAge?: number;\n\t\tcredentials?: boolean;\n\t\tallowHeaders?: readonly string[];\n\t\texposeHeaders?: readonly string[];\n\t};\n\t/**\n\t * The authorizer names this surface exposes. Names only — what verifies a\n\t * request legitimately differs between local and deployed, so the mechanism\n\t * belongs to the target and never to portable code.\n\t */\n\tauthorizers?: TAuthorizers;\n\t/**\n\t * The authorizer applied to an endpoint that names none.\n\t *\n\t * Required, and `'none'` is a valid answer that has to be typed out. The\n\t * alternative is an API that ships open because a field was left off, which\n\t * is the one default worth refusing to have.\n\t *\n\t * It was called `default`, which said what it was to the type and nothing\n\t * to the reader: next to `authorizers: ['iam']`, a bare `default: 'none'`\n\t * could be defaulting the runtime or the target. The manifest has always\n\t * called it `defaultAuthorizer` and the factory `defaultAuthorizerName`;\n\t * this is the same fact under the same name.\n\t *\n\t * Typed from `authorizers`, so it can only name one this surface exposes —\n\t * plus a built-in scheme, and `'none'`. It was a bare `string`, which let\n\t * `defaultAuthorizer: 'jwtt'` compile and every endpoint on the surface\n\t * default to an authorizer that does not exist.\n\t */\n\tdefaultAuthorizer: TAuthorizers[number] | BuiltInSecuritySchemeId | 'none';\n\t/**\n\t * The logger every endpoint on this surface runs with.\n\t *\n\t * The actual logger, not a path to one. It used to be named in config as\n\t * `logger: './config/logger'`, because the build wrote an import into each\n\t * generated handler and a generator can print a specifier but not an object.\n\t * Endpoints built from the surface carry it, so there is nothing to print\n\t * and nothing to keep in step with a moved file.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser every endpoint on this surface runs with.\n\t *\n\t * Same reason as `logger`, and the same field it replaces —\n\t * `envParser: './config/env#envParser'`, a module path with an export name\n\t * appended, parsed by us, checked by nothing.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * The Telescope instance this surface's entry mounts.\n\t *\n\t * The actual instance, for the reason `logger` is: it used to be named as\n\t * `telescope: './config/telescope#telescope'`, a module path the build\n\t * printed an import for. The entry already imports the surface.\n\t */\n\ttelescope?: Telescope;\n\t/**\n\t * What this surface's process emits — the `Telemetry` construct, passed\n\t * like the logger: a fact about the process, not a grant to a route.\n\t *\n\t * An edge to the node, so the deploy hands this process the `OTEL_*` keys\n\t * its stage resolves, and the build fails without the OpenTelemetry\n\t * packages. Where the telemetry goes is never here: it is the deploy's,\n\t * per stage.\n\t */\n\ttelemetry?: Telemetry;\n}\n\n/**\n * What is *not* here, and why.\n *\n * `dependsOn`, `database`, `auditor` and `.event(topic, …)` all inject a capability\n * into a handler. Putting one on the surface hands it to every route the\n * surface serves — a health check gets the database because a report needed it\n * — which is the thing least privilege forbids and the reason `.calls()` is not\n * spelled `dependsOn`. They belong to the endpoint, or to a branch —\n * `api.database(db)` — for a group of endpoints that genuinely share them. A\n * branch is a new factory; the surface config stays free of grants.\n *\n * `auth` is not here either: `.auth(construct)` already declares it, and a\n * second way to say the same thing is the duplication this whole model removes.\n *\n * What is left is what the *process* is rather than what a route may reach.\n */\n\nexport class RestApi<\n\tTName extends string = string,\n\tconst TAuthorizers extends readonly string[] = readonly [],\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/**\n\t * Declared once and read by both `declare()` and anything that consumes this\n\t * surface, so what the target publishes and what a consumer reads cannot\n\t * drift.\n\t */\n\treadonly keys: {\n\t\turl: string;\n\t\ttrustedOrigins: string;\n\t\tcookieDomain: string;\n\t};\n\n\t/**\n\t * The logger every endpoint on this surface runs with.\n\t *\n\t * Always defined — the surface's own if it was given one, the console\n\t * logger otherwise — so nothing downstream has to decide what to do about a\n\t * missing one. The generated entry reads it from here.\n\t */\n\treadonly logger: Logger;\n\n\t/**\n\t * The environment parser every endpoint on this surface runs with.\n\t *\n\t * Always defined, and normally the default: `process.env` merged with the\n\t * credentials `gkm dev`/`gkm exec` injected. That is what every\n\t * application's own `config/env.ts` was — boilerplate identical in every\n\t * project, and mandatory, which is a poor combination.\n\t */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/** The Telescope instance, when this surface was given one. */\n\treadonly telescope?: Telescope;\n\n\t/** What this surface's process emits, when it was given a `Telemetry`. */\n\treadonly telemetry?: Telemetry;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: RestApiConfig<TAuthorizers>,\n\t\t/** Internal: how `.calls()` carries edges into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\t/** Internal: how `.auth()` carries the authenticator into its copy. */\n\t\tprivate readonly authenticator?: Authenticator,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\n\t\tthis.keys = {\n\t\t\turl: provideKey(canonical, 'url'),\n\t\t\ttrustedOrigins: provideKey(canonical, 'trustedOrigins'),\n\t\t\tcookieDomain: provideKey(canonical, 'cookieDomain'),\n\t\t};\n\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.telescope = config.telescope;\n\t\tthis.telemetry = config.telemetry;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\n\t\tthis.#endpoints = new EndpointFactory({\n\t\t\tdefaultLogger: this.logger,\n\t\t\t...(config.authorizers\n\t\t\t\t? {\n\t\t\t\t\t\t// With the scheme a built-in name stands for, as the factory's own\n\t\t\t\t\t\t// `.authorizers()` resolves it. Bare names reached the OpenAPI\n\t\t\t\t\t\t// document with no scheme, so a guarded endpoint read as public.\n\t\t\t\t\t\tavailableAuthorizers: config.authorizers.map((name) => {\n\t\t\t\t\t\t\tconst securityScheme = getSecurityScheme(name);\n\t\t\t\t\t\t\treturn securityScheme ? { name, securityScheme } : { name };\n\t\t\t\t\t\t}),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t// `'none'` reaches the factory as no default at all, which is what\n\t\t\t// public means to an endpoint that names no authorizer.\n\t\t\t...(config.defaultAuthorizer && config.defaultAuthorizer !== 'none'\n\t\t\t\t? { defaultAuthorizerName: config.defaultAuthorizer }\n\t\t\t\t: {}),\n\t\t\tsurface: {\n\t\t\t\tid: this.id,\n\t\t\t\tenvParser: this.envParser,\n\t\t\t\t...(authenticator ? { auth: authenticator } : {}),\n\t\t\t},\n\t\t});\n\n\t\tconst endpoints = this.#endpoints;\n\t\tthis.get = endpoints.get.bind(endpoints);\n\t\tthis.post = endpoints.post.bind(endpoints);\n\t\tthis.put = endpoints.put.bind(endpoints);\n\t\tthis.patch = endpoints.patch.bind(endpoints);\n\t\tthis.delete = endpoints.delete.bind(endpoints);\n\t\tthis.options = endpoints.options.bind(endpoints);\n\t\tthis.database = endpoints.database.bind(endpoints);\n\t\tthis.session = endpoints.session.bind(endpoints);\n\t\tthis.auditor = endpoints.auditor.bind(endpoints);\n\t\tthis.actor = endpoints.actor.bind(endpoints);\n\t\tthis.authorizer = endpoints.authorizer.bind(endpoints);\n\t\tthis.authorize = endpoints.authorize.bind(endpoints);\n\t\tthis.rls = endpoints.rls.bind(endpoints);\n\t\tthis.route = endpoints.route.bind(endpoints);\n\t}\n\n\t/**\n\t * This surface's endpoint factory, which every method below starts from.\n\t *\n\t * Private: a surface *is* where endpoints are built, so there is no second\n\t * object to reach through first. `api.database(db)` said the same\n\t * thing as `api.database(db)` with one more word to learn.\n\t */\n\treadonly #endpoints: Endpoints;\n\n\t/** `api.get('/users')` — one route on this surface. */\n\treadonly get: Endpoints['get'];\n\treadonly post: Endpoints['post'];\n\treadonly put: Endpoints['put'];\n\treadonly patch: Endpoints['patch'];\n\treadonly delete: Endpoints['delete'];\n\treadonly options: Endpoints['options'];\n\n\t/**\n\t * A branch for a *group* of endpoints that shares what a single route would\n\t * otherwise repeat — a database, an auditor, a publisher, a session:\n\t *\n\t * ```ts\n\t * export const router = api.database(database);\n\t * export const createUser = router.post('/users').handle(({ db }) => …);\n\t * ```\n\t *\n\t * Each returns a new factory and leaves the surface as it was. That is the\n\t * whole difference from putting the same thing in the surface's config: a\n\t * group opts in, where the surface would grant it to every route it serves —\n\t * a health check handed the database because a profile endpoint needed it.\n\t *\n\t * `dependsOn` is deliberately not here. It is per endpoint, and on the\n\t * surface it would read as the API depending on something, which is what\n\t * `.calls()` and `.auth()` say instead.\n\t */\n\treadonly database: Endpoints['database'];\n\treadonly session: Endpoints['session'];\n\treadonly auditor: Endpoints['auditor'];\n\treadonly actor: Endpoints['actor'];\n\treadonly authorizer: Endpoints['authorizer'];\n\treadonly authorize: Endpoints['authorize'];\n\treadonly rls: Endpoints['rls'];\n\treadonly route: Endpoints['route'];\n\n\t/**\n\t * What authenticates this surface.\n\t *\n\t * An edge like `.calls()` — the auth server learns this origin, and the two\n\t * share a cookie domain — but a named one, because *who authenticates me* is\n\t * a different fact from *who I happen to call*, and only one of them decides\n\t * what a request is allowed to be. A surface with two of the first is a\n\t * mistake; two of the second is Tuesday.\n\t *\n\t * It declares the id, and keeps the construct: a session callback reads from\n\t * it as `auth` — `session(async ({ auth }) => auth.getSession())` — which\n\t * calls the construct's `verify(headers)`. That is the one thing every\n\t * provider shares, whether the server is mounted in this process, deployed\n\t * beside it, or an OIDC issuer somebody else runs.\n\t */\n\tauth(construct: Authenticator): RestApi<TName, TAuthorizers> {\n\t\treturn new RestApi<TName, TAuthorizers>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(construct)],\n\t\t\tconstruct,\n\t\t);\n\t}\n\n\t/**\n\t * Other surfaces this one calls.\n\t *\n\t * **Not `.dependsOn()`, and the difference matters.** An endpoint's\n\t * `.dependsOn()` injects a client into that handler and grants it exactly\n\t * what it named. This grants nothing and injects nothing: it records that\n\t * this API calls another surface, which is what puts this API's origin on\n\t * that surface's trusted-origin list.\n\t *\n\t * Spelling it `dependsOn` would invite the thing least privilege forbids —\n\t * every route on the surface receiving whatever the surface named.\n\t *\n\t * Immutable, like every other builder here.\n\t */\n\tcalls(constructs: readonly Declarable[]): RestApi<TName, TAuthorizers> {\n\t\treturn new RestApi<TName, TAuthorizers>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, ...constructs.map(edgeTo)],\n\t\t\tthis.authenticator,\n\t\t);\n\t}\n\n\t/**\n\t * One surface node, with its endpoints left to the build.\n\t *\n\t * The three provided keys are one fact about this surface and two about its\n\t * callers. Declaring the caller-derived pair here rather than having the\n\t * target invent them is what makes the contract checkable: a target that\n\t * resolves no origins is caught against this list instead of being noticed\n\t * when a browser is refused in production.\n\t */\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'rest-api',\n\t\t\t\tid: this.id,\n\t\t\t\tpath: this.config.path,\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.config.telescope ? { telescope: true } : {}),\n\t\t\t\t...(this.config.cors ? { cors: this.config.cors } : {}),\n\t\t\t\t...(this.authenticator ? { auth: this.authenticator.id } : {}),\n\t\t\t\t// Filled by the build, which already generates one handler per\n\t\t\t\t// endpoint and knows the path it wrote it to. A surface that\n\t\t\t\t// enumerates its own routes statically — an auth server's single\n\t\t\t\t// wildcard — puts them here instead.\n\t\t\t\tendpoints: [],\n\t\t\t\t...(this.dependencies.length ? { calls: this.dependencies } : {}),\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.authorizers?.length\n\t\t\t\t\t? { authorizers: this.config.authorizers }\n\t\t\t\t\t: {}),\n\t\t\t\tdefaultAuthorizer: this.config.defaultAuthorizer,\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\tthis.keys.trustedOrigins,\n\t\t\t\t\tthis.keys.cookieDomain,\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":"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"}
@@ -1,13 +1,11 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
8
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
11
9
  var __copyProps = (to, from, except, desc) => {
12
10
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
11
  key = keys[i];
@@ -18,22 +16,20 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
22
20
  value: mod,
23
21
  enumerable: true
24
22
  }) : target, mod));
25
-
26
23
  //#endregion
27
-
28
- Object.defineProperty(exports, '__commonJS', {
29
- enumerable: true,
30
- get: function () {
31
- return __commonJS;
32
- }
24
+ Object.defineProperty(exports, "__commonJSMin", {
25
+ enumerable: true,
26
+ get: function() {
27
+ return __commonJSMin;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "__toESM", {
31
+ enumerable: true,
32
+ get: function() {
33
+ return __toESM;
34
+ }
33
35
  });
34
- Object.defineProperty(exports, '__toESM', {
35
- enumerable: true,
36
- get: function () {
37
- return __toESM;
38
- }
39
- });
@@ -0,0 +1,109 @@
1
+ import { ServiceDiscovery } from "@geekmidas/services";
2
+ //#region src/subscribers/runSubscriber.ts
3
+ /** The subscriber's output did not match its `.output()` schema. */
4
+ var SubscriberOutputInvalid = class extends Error {
5
+ issues;
6
+ constructor(issues) {
7
+ super("Subscriber output validation failed: the handler's result does not match its .output() schema.");
8
+ this.issues = issues;
9
+ this.name = "SubscriberOutputInvalid";
10
+ }
11
+ };
12
+ /** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */
13
+ function subscribedEvents(subscriber, rawEvent, logger) {
14
+ const events = [];
15
+ const records = rawEvent.Records ?? [];
16
+ const first = records[0];
17
+ const parse = first?.eventSource === "aws:sqs" ? (record) => parseSQSRecord(record) : first?.EventSource === "aws:sns" ? (record) => parseSNSRecord(record) : void 0;
18
+ if (!parse) return events;
19
+ for (const record of records) try {
20
+ const event = parse(record);
21
+ if (isSubscribed(subscriber, event)) events.push(event);
22
+ } catch (error) {
23
+ logger.error({
24
+ err: error,
25
+ record
26
+ }, "Failed to parse record");
27
+ }
28
+ return events;
29
+ }
30
+ /** The subscriber's services and database, registered as functions do. */
31
+ async function subscriberContext(subscriber, envParser) {
32
+ const discovery = ServiceDiscovery.getInstance(envParser);
33
+ const services = subscriber.services.length > 0 ? await discovery.register(subscriber.services) : {};
34
+ const service = subscriber.databaseService;
35
+ return {
36
+ services,
37
+ db: service ? (await discovery.register([service]))[service.serviceName] : void 0
38
+ };
39
+ }
40
+ /** Runs the handler on `events`, and checks its output against its schema. */
41
+ async function runSubscriber(subscriber, context) {
42
+ if (context.events.length === 0) {
43
+ context.logger.info("No subscribed events to process");
44
+ return { batchItemFailures: [] };
45
+ }
46
+ const { events, services, db, logger } = context;
47
+ const result = await subscriber.handler({
48
+ events,
49
+ services,
50
+ logger,
51
+ db
52
+ });
53
+ if (subscriber.outputSchema && result) {
54
+ const validation = await subscriber.outputSchema["~standard"].validate(result);
55
+ if (validation.issues) {
56
+ context.logger.error({ issues: validation.issues }, "Subscriber output validation failed");
57
+ throw new SubscriberOutputInvalid(validation.issues);
58
+ }
59
+ return validation.value;
60
+ }
61
+ return result;
62
+ }
63
+ function isSubscribed(subscriber, event) {
64
+ if (typeof event !== "object" || !event?.type) return true;
65
+ if (!subscriber.subscribedEvents) return true;
66
+ return subscriber.subscribedEvents.includes(event.type);
67
+ }
68
+ function parseSNSRecord(record) {
69
+ const message = safeJsonParse(record.Sns.Message);
70
+ const messageType = record.Sns.MessageAttributes?.type?.Value;
71
+ if (message === null) return messageType ? {
72
+ type: messageType,
73
+ payload: record.Sns.Message
74
+ } : record.Sns.Message;
75
+ if (message.type) return message;
76
+ return messageType ? {
77
+ type: messageType,
78
+ payload: message
79
+ } : message;
80
+ }
81
+ function parseSQSRecord(record) {
82
+ const body = safeJsonParse(record.body);
83
+ if (body === null) return record.body;
84
+ if (body.Type === "Notification" && body.Message) {
85
+ const snsMessage = safeJsonParse(body.Message);
86
+ const messageType = body.MessageAttributes?.type?.Value;
87
+ if (snsMessage === null) return messageType ? {
88
+ type: messageType,
89
+ payload: body.Message
90
+ } : body.Message;
91
+ if (snsMessage.type) return snsMessage;
92
+ return messageType ? {
93
+ type: messageType,
94
+ payload: snsMessage
95
+ } : snsMessage;
96
+ }
97
+ return body;
98
+ }
99
+ function safeJsonParse(value) {
100
+ try {
101
+ return JSON.parse(value);
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+ //#endregion
107
+ export { subscribedEvents as n, subscriberContext as r, runSubscriber as t };
108
+
109
+ //# sourceMappingURL=runSubscriber-BHvJ8POr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runSubscriber-BHvJ8POr.mjs","names":[],"sources":["../src/subscribers/runSubscriber.ts"],"sourcesContent":["/**\n * What a subscriber does with a batch of records, however they arrived: parse\n * them into events, keep the ones it subscribed to, and run its handler with\n * its services and database.\n *\n * Shared by the Lambda adaptor, which wraps it in middy, and the SNS push\n * adaptor, which a server runs and which must not need middy to load.\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport type { SNSEvent, SNSEventRecord, SQSEvent, SQSRecord } from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\ntype AnySubscriber = Subscriber<any, any, any, any, any, any, any>;\n\n/** The subscriber's output did not match its `.output()` schema. */\nexport class SubscriberOutputInvalid extends Error {\n\tconstructor(readonly issues: ReadonlyArray<unknown>) {\n\t\tsuper(\n\t\t\t\"Subscriber output validation failed: the handler's result does not match its .output() schema.\",\n\t\t);\n\t\tthis.name = 'SubscriberOutputInvalid';\n\t}\n}\n\n/** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */\nexport function subscribedEvents(\n\tsubscriber: AnySubscriber,\n\trawEvent: { Records?: readonly unknown[] },\n\tlogger: Logger,\n): any[] {\n\tconst events: any[] = [];\n\tconst records = rawEvent.Records ?? [];\n\tconst first = records[0] as any;\n\tconst parse =\n\t\tfirst?.eventSource === 'aws:sqs'\n\t\t\t? (record: any) => parseSQSRecord(record)\n\t\t\t: first?.EventSource === 'aws:sns'\n\t\t\t\t? (record: any) => parseSNSRecord(record)\n\t\t\t\t: undefined;\n\tif (!parse) return events;\n\n\tfor (const record of records) {\n\t\ttry {\n\t\t\tconst event = parse(record);\n\t\t\tif (isSubscribed(subscriber, event)) events.push(event);\n\t\t} catch (error) {\n\t\t\tlogger.error({ err: error, record }, 'Failed to parse record');\n\t\t}\n\t}\n\treturn events;\n}\n\n/** The subscriber's services and database, registered as functions do. */\nexport async function subscriberContext(\n\tsubscriber: AnySubscriber,\n\tenvParser: EnvironmentParser<{}>,\n): Promise<{ services: Record<string, unknown>; db: unknown }> {\n\tconst discovery = ServiceDiscovery.getInstance(envParser);\n\tconst services =\n\t\tsubscriber.services.length > 0\n\t\t\t? await discovery.register(subscriber.services)\n\t\t\t: {};\n\tconst service = subscriber.databaseService;\n\tconst db = service\n\t\t? (await discovery.register([service]))[service.serviceName]\n\t\t: undefined;\n\treturn { services, db };\n}\n\n/** Runs the handler on `events`, and checks its output against its schema. */\nexport async function runSubscriber(\n\tsubscriber: AnySubscriber,\n\tcontext: {\n\t\tevents: any[];\n\t\tservices: Record<string, unknown>;\n\t\tdb: unknown;\n\t\tlogger: Logger;\n\t},\n): Promise<unknown> {\n\tif (context.events.length === 0) {\n\t\tcontext.logger.info('No subscribed events to process');\n\t\treturn { batchItemFailures: [] };\n\t}\n\n\tconst { events, services, db, logger } = context;\n\tconst result = await subscriber.handler({\n\t\tevents,\n\t\tservices,\n\t\tlogger,\n\t\tdb,\n\t} as any);\n\n\tif (subscriber.outputSchema && result) {\n\t\tconst validation =\n\t\t\tawait subscriber.outputSchema['~standard'].validate(result);\n\t\tif (validation.issues) {\n\t\t\tcontext.logger.error(\n\t\t\t\t{ issues: validation.issues },\n\t\t\t\t'Subscriber output validation failed',\n\t\t\t);\n\t\t\tthrow new SubscriberOutputInvalid(validation.issues);\n\t\t}\n\t\treturn validation.value;\n\t}\n\n\treturn result;\n}\n\nfunction isSubscribed(subscriber: AnySubscriber, event: any): boolean {\n\t// No event type (raw string/non-object) — always include\n\tif (typeof event !== 'object' || !event?.type) return true;\n\t// No filter configured — accept all\n\tif (!subscriber.subscribedEvents) return true;\n\treturn subscriber.subscribedEvents.includes(event.type);\n}\n\nfunction parseSNSRecord(record: SNSEventRecord): any {\n\tconst message = safeJsonParse(record.Sns.Message);\n\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\tif (message === null) {\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t: record.Sns.Message;\n\t}\n\n\tif (message.type) {\n\t\treturn message; // Full event format: { type, payload }\n\t}\n\n\t// Payload-only format: type is in MessageAttributes\n\treturn messageType ? { type: messageType, payload: message } : message;\n}\n\nfunction parseSQSRecord(record: SQSRecord): any {\n\tconst body = safeJsonParse(record.body);\n\n\t// Not JSON — return raw body as-is\n\tif (body === null) {\n\t\treturn record.body;\n\t}\n\n\t// Check if this is an SNS message wrapped in SQS\n\tif (body.Type === 'Notification' && body.Message) {\n\t\tconst snsMessage = safeJsonParse(body.Message);\n\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\tif (snsMessage === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t: body.Message;\n\t\t}\n\n\t\tif (snsMessage.type) {\n\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: snsMessage }\n\t\t\t: snsMessage;\n\t}\n\n\t// Direct SQS message\n\treturn body;\n}\n\nfunction safeJsonParse(value: string): any | null {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn null;\n\t}\n}\n"],"mappings":"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"}
@@ -0,0 +1,126 @@
1
+ let _geekmidas_services = require("@geekmidas/services");
2
+ //#region src/subscribers/runSubscriber.ts
3
+ /** The subscriber's output did not match its `.output()` schema. */
4
+ var SubscriberOutputInvalid = class extends Error {
5
+ issues;
6
+ constructor(issues) {
7
+ super("Subscriber output validation failed: the handler's result does not match its .output() schema.");
8
+ this.issues = issues;
9
+ this.name = "SubscriberOutputInvalid";
10
+ }
11
+ };
12
+ /** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */
13
+ function subscribedEvents(subscriber, rawEvent, logger) {
14
+ const events = [];
15
+ const records = rawEvent.Records ?? [];
16
+ const first = records[0];
17
+ const parse = first?.eventSource === "aws:sqs" ? (record) => parseSQSRecord(record) : first?.EventSource === "aws:sns" ? (record) => parseSNSRecord(record) : void 0;
18
+ if (!parse) return events;
19
+ for (const record of records) try {
20
+ const event = parse(record);
21
+ if (isSubscribed(subscriber, event)) events.push(event);
22
+ } catch (error) {
23
+ logger.error({
24
+ err: error,
25
+ record
26
+ }, "Failed to parse record");
27
+ }
28
+ return events;
29
+ }
30
+ /** The subscriber's services and database, registered as functions do. */
31
+ async function subscriberContext(subscriber, envParser) {
32
+ const discovery = _geekmidas_services.ServiceDiscovery.getInstance(envParser);
33
+ const services = subscriber.services.length > 0 ? await discovery.register(subscriber.services) : {};
34
+ const service = subscriber.databaseService;
35
+ return {
36
+ services,
37
+ db: service ? (await discovery.register([service]))[service.serviceName] : void 0
38
+ };
39
+ }
40
+ /** Runs the handler on `events`, and checks its output against its schema. */
41
+ async function runSubscriber(subscriber, context) {
42
+ if (context.events.length === 0) {
43
+ context.logger.info("No subscribed events to process");
44
+ return { batchItemFailures: [] };
45
+ }
46
+ const { events, services, db, logger } = context;
47
+ const result = await subscriber.handler({
48
+ events,
49
+ services,
50
+ logger,
51
+ db
52
+ });
53
+ if (subscriber.outputSchema && result) {
54
+ const validation = await subscriber.outputSchema["~standard"].validate(result);
55
+ if (validation.issues) {
56
+ context.logger.error({ issues: validation.issues }, "Subscriber output validation failed");
57
+ throw new SubscriberOutputInvalid(validation.issues);
58
+ }
59
+ return validation.value;
60
+ }
61
+ return result;
62
+ }
63
+ function isSubscribed(subscriber, event) {
64
+ if (typeof event !== "object" || !event?.type) return true;
65
+ if (!subscriber.subscribedEvents) return true;
66
+ return subscriber.subscribedEvents.includes(event.type);
67
+ }
68
+ function parseSNSRecord(record) {
69
+ const message = safeJsonParse(record.Sns.Message);
70
+ const messageType = record.Sns.MessageAttributes?.type?.Value;
71
+ if (message === null) return messageType ? {
72
+ type: messageType,
73
+ payload: record.Sns.Message
74
+ } : record.Sns.Message;
75
+ if (message.type) return message;
76
+ return messageType ? {
77
+ type: messageType,
78
+ payload: message
79
+ } : message;
80
+ }
81
+ function parseSQSRecord(record) {
82
+ const body = safeJsonParse(record.body);
83
+ if (body === null) return record.body;
84
+ if (body.Type === "Notification" && body.Message) {
85
+ const snsMessage = safeJsonParse(body.Message);
86
+ const messageType = body.MessageAttributes?.type?.Value;
87
+ if (snsMessage === null) return messageType ? {
88
+ type: messageType,
89
+ payload: body.Message
90
+ } : body.Message;
91
+ if (snsMessage.type) return snsMessage;
92
+ return messageType ? {
93
+ type: messageType,
94
+ payload: snsMessage
95
+ } : snsMessage;
96
+ }
97
+ return body;
98
+ }
99
+ function safeJsonParse(value) {
100
+ try {
101
+ return JSON.parse(value);
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+ //#endregion
107
+ Object.defineProperty(exports, "runSubscriber", {
108
+ enumerable: true,
109
+ get: function() {
110
+ return runSubscriber;
111
+ }
112
+ });
113
+ Object.defineProperty(exports, "subscribedEvents", {
114
+ enumerable: true,
115
+ get: function() {
116
+ return subscribedEvents;
117
+ }
118
+ });
119
+ Object.defineProperty(exports, "subscriberContext", {
120
+ enumerable: true,
121
+ get: function() {
122
+ return subscriberContext;
123
+ }
124
+ });
125
+
126
+ //# sourceMappingURL=runSubscriber-D8nLXIv1.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runSubscriber-D8nLXIv1.cjs","names":["ServiceDiscovery"],"sources":["../src/subscribers/runSubscriber.ts"],"sourcesContent":["/**\n * What a subscriber does with a batch of records, however they arrived: parse\n * them into events, keep the ones it subscribed to, and run its handler with\n * its services and database.\n *\n * Shared by the Lambda adaptor, which wraps it in middy, and the SNS push\n * adaptor, which a server runs and which must not need middy to load.\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport type { SNSEvent, SNSEventRecord, SQSEvent, SQSRecord } from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\ntype AnySubscriber = Subscriber<any, any, any, any, any, any, any>;\n\n/** The subscriber's output did not match its `.output()` schema. */\nexport class SubscriberOutputInvalid extends Error {\n\tconstructor(readonly issues: ReadonlyArray<unknown>) {\n\t\tsuper(\n\t\t\t\"Subscriber output validation failed: the handler's result does not match its .output() schema.\",\n\t\t);\n\t\tthis.name = 'SubscriberOutputInvalid';\n\t}\n}\n\n/** The events in an SQS or SNS batch (a Lambda event's `Records`) that `subscriber` subscribed to. */\nexport function subscribedEvents(\n\tsubscriber: AnySubscriber,\n\trawEvent: { Records?: readonly unknown[] },\n\tlogger: Logger,\n): any[] {\n\tconst events: any[] = [];\n\tconst records = rawEvent.Records ?? [];\n\tconst first = records[0] as any;\n\tconst parse =\n\t\tfirst?.eventSource === 'aws:sqs'\n\t\t\t? (record: any) => parseSQSRecord(record)\n\t\t\t: first?.EventSource === 'aws:sns'\n\t\t\t\t? (record: any) => parseSNSRecord(record)\n\t\t\t\t: undefined;\n\tif (!parse) return events;\n\n\tfor (const record of records) {\n\t\ttry {\n\t\t\tconst event = parse(record);\n\t\t\tif (isSubscribed(subscriber, event)) events.push(event);\n\t\t} catch (error) {\n\t\t\tlogger.error({ err: error, record }, 'Failed to parse record');\n\t\t}\n\t}\n\treturn events;\n}\n\n/** The subscriber's services and database, registered as functions do. */\nexport async function subscriberContext(\n\tsubscriber: AnySubscriber,\n\tenvParser: EnvironmentParser<{}>,\n): Promise<{ services: Record<string, unknown>; db: unknown }> {\n\tconst discovery = ServiceDiscovery.getInstance(envParser);\n\tconst services =\n\t\tsubscriber.services.length > 0\n\t\t\t? await discovery.register(subscriber.services)\n\t\t\t: {};\n\tconst service = subscriber.databaseService;\n\tconst db = service\n\t\t? (await discovery.register([service]))[service.serviceName]\n\t\t: undefined;\n\treturn { services, db };\n}\n\n/** Runs the handler on `events`, and checks its output against its schema. */\nexport async function runSubscriber(\n\tsubscriber: AnySubscriber,\n\tcontext: {\n\t\tevents: any[];\n\t\tservices: Record<string, unknown>;\n\t\tdb: unknown;\n\t\tlogger: Logger;\n\t},\n): Promise<unknown> {\n\tif (context.events.length === 0) {\n\t\tcontext.logger.info('No subscribed events to process');\n\t\treturn { batchItemFailures: [] };\n\t}\n\n\tconst { events, services, db, logger } = context;\n\tconst result = await subscriber.handler({\n\t\tevents,\n\t\tservices,\n\t\tlogger,\n\t\tdb,\n\t} as any);\n\n\tif (subscriber.outputSchema && result) {\n\t\tconst validation =\n\t\t\tawait subscriber.outputSchema['~standard'].validate(result);\n\t\tif (validation.issues) {\n\t\t\tcontext.logger.error(\n\t\t\t\t{ issues: validation.issues },\n\t\t\t\t'Subscriber output validation failed',\n\t\t\t);\n\t\t\tthrow new SubscriberOutputInvalid(validation.issues);\n\t\t}\n\t\treturn validation.value;\n\t}\n\n\treturn result;\n}\n\nfunction isSubscribed(subscriber: AnySubscriber, event: any): boolean {\n\t// No event type (raw string/non-object) — always include\n\tif (typeof event !== 'object' || !event?.type) return true;\n\t// No filter configured — accept all\n\tif (!subscriber.subscribedEvents) return true;\n\treturn subscriber.subscribedEvents.includes(event.type);\n}\n\nfunction parseSNSRecord(record: SNSEventRecord): any {\n\tconst message = safeJsonParse(record.Sns.Message);\n\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\tif (message === null) {\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t: record.Sns.Message;\n\t}\n\n\tif (message.type) {\n\t\treturn message; // Full event format: { type, payload }\n\t}\n\n\t// Payload-only format: type is in MessageAttributes\n\treturn messageType ? { type: messageType, payload: message } : message;\n}\n\nfunction parseSQSRecord(record: SQSRecord): any {\n\tconst body = safeJsonParse(record.body);\n\n\t// Not JSON — return raw body as-is\n\tif (body === null) {\n\t\treturn record.body;\n\t}\n\n\t// Check if this is an SNS message wrapped in SQS\n\tif (body.Type === 'Notification' && body.Message) {\n\t\tconst snsMessage = safeJsonParse(body.Message);\n\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\tif (snsMessage === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t: body.Message;\n\t\t}\n\n\t\tif (snsMessage.type) {\n\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn messageType\n\t\t\t? { type: messageType, payload: snsMessage }\n\t\t\t: snsMessage;\n\t}\n\n\t// Direct SQS message\n\treturn body;\n}\n\nfunction safeJsonParse(value: string): any | null {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn null;\n\t}\n}\n"],"mappings":"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"}
@@ -0,0 +1,38 @@
1
+ //#region src/shutdown.ts
2
+ const key = Symbol.for("@geekmidas/constructs/shutdown");
3
+ const registry = globalThis;
4
+ registry[key] ??= /* @__PURE__ */ new Set();
5
+ const hooks = registry[key];
6
+ /** Run `hook` when the server shuts down. Returns a function that removes it. */
7
+ function onShutdown(hook) {
8
+ hooks.add(hook);
9
+ return () => hooks.delete(hook);
10
+ }
11
+ /**
12
+ * Run every registered hook, together, and wait for them. A hook that fails is
13
+ * reported to `onError` and does not stop the others.
14
+ */
15
+ async function runShutdownHooks(onError = () => {}) {
16
+ await Promise.all([...hooks].map(async (hook) => {
17
+ try {
18
+ await hook();
19
+ } catch (error) {
20
+ onError(error);
21
+ }
22
+ }));
23
+ }
24
+ //#endregion
25
+ Object.defineProperty(exports, "onShutdown", {
26
+ enumerable: true,
27
+ get: function() {
28
+ return onShutdown;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "runShutdownHooks", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return runShutdownHooks;
35
+ }
36
+ });
37
+
38
+ //# sourceMappingURL=shutdown-BMJmAhSt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown-BMJmAhSt.cjs","names":[],"sources":["../src/shutdown.ts"],"sourcesContent":["/**\n * What a server releases when it stops: the connections constructs opened.\n *\n * A construct that holds something open — a database's pool — registers how to\n * close it here, and the generated server runs every hook once it has stopped\n * taking requests. Without that, a rolling deploy has the old task and the new\n * one both holding connections until the old process dies.\n *\n * Kept free of any driver import so the server entry can always import it,\n * whether or not the app has a database.\n */\n\ntype ShutdownHook = () => Promise<void> | void;\n\n// On globalThis, as Credentials are: a package loaded twice (ESM and CJS)\n// would otherwise keep two registries, and the server would run the empty one.\nconst key = Symbol.for('@geekmidas/constructs/shutdown');\nconst registry = globalThis as Record<symbol, Set<ShutdownHook> | undefined>;\nregistry[key] ??= new Set<ShutdownHook>();\nconst hooks = registry[key];\n\n/** Run `hook` when the server shuts down. Returns a function that removes it. */\nexport function onShutdown(hook: ShutdownHook): () => void {\n\thooks.add(hook);\n\treturn () => hooks.delete(hook);\n}\n\n/**\n * Run every registered hook, together, and wait for them. A hook that fails is\n * reported to `onError` and does not stop the others.\n */\nexport async function runShutdownHooks(\n\tonError: (error: unknown) => void = () => {},\n): Promise<void> {\n\tawait Promise.all(\n\t\t[...hooks].map(async (hook) => {\n\t\t\ttry {\n\t\t\t\tawait hook();\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"mappings":";AAgBA,MAAM,MAAM,OAAO,IAAI,gCAAgC;AACvD,MAAM,WAAW;AACjB,SAAS,yBAAS,IAAI,IAAkB;AACxC,MAAM,QAAQ,SAAS;;AAGvB,SAAgB,WAAW,MAAgC;CAC1D,MAAM,IAAI,IAAI;CACd,aAAa,MAAM,OAAO,IAAI;AAC/B;;;;;AAMA,eAAsB,iBACrB,gBAA0C,CAAC,GAC3B;CAChB,MAAM,QAAQ,IACb,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,OAAO,SAAS;EAC9B,IAAI;GACH,MAAM,KAAK;EACZ,SAAS,OAAO;GACf,QAAQ,KAAK;EACd;CACD,CAAC,CACF;AACD"}
@@ -0,0 +1,27 @@
1
+ //#region src/shutdown.ts
2
+ const key = Symbol.for("@geekmidas/constructs/shutdown");
3
+ const registry = globalThis;
4
+ registry[key] ??= /* @__PURE__ */ new Set();
5
+ const hooks = registry[key];
6
+ /** Run `hook` when the server shuts down. Returns a function that removes it. */
7
+ function onShutdown(hook) {
8
+ hooks.add(hook);
9
+ return () => hooks.delete(hook);
10
+ }
11
+ /**
12
+ * Run every registered hook, together, and wait for them. A hook that fails is
13
+ * reported to `onError` and does not stop the others.
14
+ */
15
+ async function runShutdownHooks(onError = () => {}) {
16
+ await Promise.all([...hooks].map(async (hook) => {
17
+ try {
18
+ await hook();
19
+ } catch (error) {
20
+ onError(error);
21
+ }
22
+ }));
23
+ }
24
+ //#endregion
25
+ export { runShutdownHooks as n, onShutdown as t };
26
+
27
+ //# sourceMappingURL=shutdown-C7xa8x9S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown-C7xa8x9S.mjs","names":[],"sources":["../src/shutdown.ts"],"sourcesContent":["/**\n * What a server releases when it stops: the connections constructs opened.\n *\n * A construct that holds something open — a database's pool — registers how to\n * close it here, and the generated server runs every hook once it has stopped\n * taking requests. Without that, a rolling deploy has the old task and the new\n * one both holding connections until the old process dies.\n *\n * Kept free of any driver import so the server entry can always import it,\n * whether or not the app has a database.\n */\n\ntype ShutdownHook = () => Promise<void> | void;\n\n// On globalThis, as Credentials are: a package loaded twice (ESM and CJS)\n// would otherwise keep two registries, and the server would run the empty one.\nconst key = Symbol.for('@geekmidas/constructs/shutdown');\nconst registry = globalThis as Record<symbol, Set<ShutdownHook> | undefined>;\nregistry[key] ??= new Set<ShutdownHook>();\nconst hooks = registry[key];\n\n/** Run `hook` when the server shuts down. Returns a function that removes it. */\nexport function onShutdown(hook: ShutdownHook): () => void {\n\thooks.add(hook);\n\treturn () => hooks.delete(hook);\n}\n\n/**\n * Run every registered hook, together, and wait for them. A hook that fails is\n * reported to `onError` and does not stop the others.\n */\nexport async function runShutdownHooks(\n\tonError: (error: unknown) => void = () => {},\n): Promise<void> {\n\tawait Promise.all(\n\t\t[...hooks].map(async (hook) => {\n\t\t\ttry {\n\t\t\t\tawait hook();\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"mappings":";AAgBA,MAAM,MAAM,OAAO,IAAI,gCAAgC;AACvD,MAAM,WAAW;AACjB,SAAS,yBAAS,IAAI,IAAkB;AACxC,MAAM,QAAQ,SAAS;;AAGvB,SAAgB,WAAW,MAAgC;CAC1D,MAAM,IAAI,IAAI;CACd,aAAa,MAAM,OAAO,IAAI;AAC/B;;;;;AAMA,eAAsB,iBACrB,gBAA0C,CAAC,GAC3B;CAChB,MAAM,QAAQ,IACb,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,OAAO,SAAS;EAC9B,IAAI;GACH,MAAM,KAAK;EACZ,SAAS,OAAO;GACf,QAAQ,KAAK;EACd;CACD,CAAC,CACF;AACD"}
package/dist/site.cjs CHANGED
@@ -1,16 +1,40 @@
1
- const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_construct_interface = require('./construct-interface-BfjcOD_E.cjs');
3
- const __geekmidas_manifest = require_chunk.__toESM(require("@geekmidas/manifest"));
4
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_construct_interface = require("./construct-interface.cjs");
3
+ let _geekmidas_manifest = require("@geekmidas/manifest");
5
4
  //#region src/site.ts
5
+ /**
6
+ * `StaticSite` — a frontend, declared like anything else.
7
+ *
8
+ * The point is not that a site needs provisioning; it is that a site is the
9
+ * *consumer* whose edges make four hand-maintained lists derivable. Declaring it
10
+ * is what turns "which origins does the API allow" from something a person keeps
11
+ * in step into something the graph already knows.
12
+ *
13
+ * ```ts
14
+ * export const console = new StaticSite('Console', { path: 'apps/console' })
15
+ * .dependsOn([api, auth]);
16
+ * ```
17
+ *
18
+ * It has no `.service`. A site is not a process that registers clients — it is
19
+ * built, and the values it needs are inlined or fetched by its own framework —
20
+ * so the edge is {@link Declarable} rather than {@link Consumable}, and the
21
+ * asymmetry is the honest one: a site consumes addresses, not connections.
22
+ *
23
+ * Only the static variant ships. SSR deploy shapes are unstable and each one is
24
+ * its own maintenance, so they follow rather than arrive together. A mobile app
25
+ * is not a site — it is reached by a scheme, not a URL — and is its own
26
+ * construct: see `MobileApp`.
27
+ */
6
28
  var StaticSite = class StaticSite {
29
+ config;
30
+ dependencies;
7
31
  id;
8
32
  keys;
9
33
  constructor(id, config, dependencies = []) {
10
34
  this.config = config;
11
35
  this.dependencies = dependencies;
12
- this.id = (0, __geekmidas_manifest.canonicalId)(id);
13
- this.keys = { url: (0, __geekmidas_manifest.provideKey)(this.id, "url") };
36
+ this.id = (0, _geekmidas_manifest.canonicalId)(id);
37
+ this.keys = { url: (0, _geekmidas_manifest.provideKey)(this.id, "url") };
14
38
  }
15
39
  /**
16
40
  * What this site calls.
@@ -31,6 +55,7 @@ var StaticSite = class StaticSite {
31
55
  kind: "site",
32
56
  id: this.id,
33
57
  variant: this.config.variant ?? "static",
58
+ ...this.config.subdomain ? { subdomain: this.config.subdomain } : {},
34
59
  app: {
35
60
  path: this.config.path,
36
61
  ...this.config.port ? { port: this.config.port } : {},
@@ -38,11 +63,12 @@ var StaticSite = class StaticSite {
38
63
  },
39
64
  ...this.config.root ? { root: true } : {},
40
65
  dependencies: this.dependencies,
66
+ ...this.config.telemetry ? { telemetry: this.config.telemetry.id } : {},
41
67
  provides: [this.keys.url]
42
68
  }];
43
69
  }
44
70
  };
45
-
46
71
  //#endregion
47
72
  exports.StaticSite = StaticSite;
73
+
48
74
  //# sourceMappingURL=site.cjs.map
package/dist/site.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"site.cjs","names":["id: ConstructName<TName>","config: StaticSiteConfig","dependencies: readonly Dependency[]","constructs: readonly Declarable[]","edgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together; Expo and\n * mobile are out of scope entirely, because an app store is not infrastructure\n * and there is no URL to hand anyone.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\tprovides: [this.keys.url],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;AAkFA,IAAa,aAAb,MAAa,WAEb;CACC,AAAS;CACT,AAAS;CAET,YACCA,IACiBC,QAOAC,eAAsC,CAAE,GACxD;EARgB;EAOA;AAEjB,OAAK,KAAK,sCAAY,GAAa;AACnC,OAAK,OAAO,EAAE,KAAK,qCAAW,KAAK,IAAI,MAAM,CAAE;CAC/C;;;;;;;;;;;;CAaD,UAAUC,YAAsD;AAC/D,SAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAIC,mCAAO,AACzB;CACD;CAED,UAAyB;AACxB,SAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAM,IAAG,CAAE;IACtD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAQ,IAAG,CAAE;GAC5D;GACD,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAM,IAAG,CAAE;GAC1C,cAAc,KAAK;GACnB,UAAU,CAAC,KAAK,KAAK,GAAI;EACzB,CACD;CACD;AACD"}
1
+ {"version":3,"file":"site.cjs","names":["canonicalId","provideKey","edgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [this.keys.url],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,IAAa,aAAb,MAAa,WAEb;CAMmB;CAOA;CAZlB;CACA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,MAAA,GAAKA,oBAAAA,YAAAA,CAAY,EAAY;EAClC,KAAK,OAAO,EAAE,MAAA,GAAKC,oBAAAA,WAAAA,CAAW,KAAK,IAAI,KAAK,EAAE;CAC/C;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAIC,4BAAAA,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,UAAU,CAAC,KAAK,KAAK,GAAG;EACzB,CACD;CACD;AACD"}