@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,25 +1,63 @@
1
- import "../Construct-BD5neF7w.mjs";
2
- import "../construct-interface-Z4CpS8tK.mjs";
3
- import { FunctionBuilder } from "../functions-14lpEFL4.mjs";
4
- import "../clone-DblgEZZa.mjs";
5
- import { Endpoint, ResponseBuilder } from "../Endpoint-DCQPMdUX.mjs";
6
- import { createCookieHeaderAccessor, createObjectHeaders, publishConstructEvents, publishEvents } from "../lazyAccessors-BoJN3SMd.mjs";
7
- import { executeWithAuditTransaction } from "../processAudits-Dmts9H_b.mjs";
8
- import { HonoEndpoint } from "../HonoEndpointAdaptor-P1ahhZHu.mjs";
1
+ import { isConsumable } from "../construct-interface.mjs";
2
+ import { BetterAuth } from "../auth.mjs";
3
+ import { a as publishEvents, i as publishConstructEvents, t as FunctionBuilder } from "../functions-CTI-hDem.mjs";
4
+ import { r as ResponseBuilder, t as Endpoint } from "../Endpoint-gPXhHKhJ.mjs";
5
+ import { t as Queue } from "../Queue-cmhqEBOB.mjs";
6
+ import { Email } from "../email.mjs";
7
+ import { t as KyselyDatabase } from "../kysely-B_0BAr0T.mjs";
8
+ import { f as createObjectHeaders, s as createCookieHeaderAccessor } from "../readRequestBody-BTIl3k-D.mjs";
9
+ import { t as Topic } from "../Topic-D2R0r24C.mjs";
10
+ import { t as HonoEndpoint } from "../HonoEndpointAdaptor-euH1oSdY.mjs";
11
+ import { i as executeWithAuditTransaction, n as enforceRateLimit, t as requestLogger } from "../requestLogger-pA4gi3E1.mjs";
12
+ import { provideKey } from "@geekmidas/manifest";
13
+ import { randomUUID } from "node:crypto";
14
+ import { ServiceDiscovery, currentRequestContext, runWithRequestContext, serviceContext } from "@geekmidas/services";
9
15
  import { ForbiddenError } from "@geekmidas/errors";
10
16
  import { EnvironmentParser } from "@geekmidas/envkit";
11
- import { ServiceDiscovery, runWithRequestContext } from "@geekmidas/services";
12
- import { DefaultAuditor } from "@geekmidas/audit";
13
17
  import { Hono } from "hono";
18
+ import { DefaultAuditor } from "@geekmidas/audit";
19
+ import { TEST_CONTEXT_HEADER, currentTestContext, installContextFetch, runAsServer, runInTestContext, testContextOf } from "@geekmidas/testkit/context";
14
20
  import { http } from "msw";
15
-
16
- //#region src/endpoints/MswEndpointAdaptor.ts
21
+ import { Browser } from "@geekmidas/testkit/browser";
22
+ import { faker } from "@geekmidas/testkit/faker";
23
+ import { createMailbox } from "@geekmidas/testkit/mailbox";
24
+ import { TransactionRegistry } from "@geekmidas/testkit/transactions";
25
+ import { setupServer } from "msw/node";
26
+ import { afterAll, beforeAll, test } from "vitest";
27
+ import { existsSync, readFileSync } from "node:fs";
28
+ import tls from "node:tls";
29
+ import { fileURLToPath } from "node:url";
30
+ //#region src/testing/peer.ts
17
31
  /**
18
- * Header used to identify which test context a request belongs to.
19
- * Each concurrent test registers its own context (services, db transaction, etc.)
20
- * and the MSW handler looks it up by this header value.
32
+ * The TCP peer a test's in-process requests arrive from.
33
+ *
34
+ * A feature test hands a request straight to a surface's Hono app — no
35
+ * socket, no server — so the app's bindings have no peer to read. Deployed,
36
+ * every request has one, and what a surface trusts follows from it: the auth
37
+ * server honours `x-gkm-client-ip` only from an internal caller, a loopback
38
+ * or private peer with no `Origin` and no forwarding header. With no peer at
39
+ * all the header was dropped, and every test's session check became the same
40
+ * client to Better Auth's rate limiter.
41
+ *
42
+ * So an in-process dispatch says where it came from, the way
43
+ * `@hono/node-server` does: its bindings carry `incoming.socket.remoteAddress`.
44
+ * The address is loopback because that is the truth — the request came from
45
+ * this process. A browser's own address still travels in its
46
+ * `x-forwarded-for`, which makes it outside traffic exactly as it would be
47
+ * behind the stack's proxy.
48
+ *
49
+ * Only a test's dispatch passes these. A runtime with no socket of its own
50
+ * (Lambda, Bun) still has no peer, and a request with no peer is still not an
51
+ * internal caller's.
21
52
  */
22
- const TEST_CONTEXT_HEADER = "x-test-context-id";
53
+ /** The address an in-process request presents as its peer. */
54
+ const IN_PROCESS_PEER_ADDRESS = "127.0.0.1";
55
+ /** Bindings for `app.fetch(request, bindings)` from inside this process. */
56
+ function inProcessBindings() {
57
+ return { incoming: { socket: { remoteAddress: IN_PROCESS_PEER_ADDRESS } } };
58
+ }
59
+ //#endregion
60
+ //#region src/endpoints/MswEndpointAdaptor.ts
23
61
  const MSW_HTTP_METHODS = [
24
62
  "get",
25
63
  "post",
@@ -67,7 +105,6 @@ function createMswHandlers(endpoints, options) {
67
105
  break;
68
106
  }
69
107
  }
70
- if (ctxOptions.publisher) serviceDefs.push(ctxOptions.publisher);
71
108
  if (ctxOptions.auditorStorage !== void 0) {
72
109
  for (const endpoint of endpoints) if (endpoint.auditorStorageService) {
73
110
  serviceDefs.push({
@@ -98,7 +135,7 @@ function createMswHandlers(endpoints, options) {
98
135
  });
99
136
  const app = new Hono();
100
137
  HonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery, app);
101
- const response = await app.request(request);
138
+ const response = await app.request(request, void 0, inProcessBindings());
102
139
  return new Response(response.body, {
103
140
  status: response.status,
104
141
  statusText: response.statusText,
@@ -111,7 +148,6 @@ function createMswHandlers(endpoints, options) {
111
148
  registerContext
112
149
  };
113
150
  }
114
-
115
151
  //#endregion
116
152
  //#region src/endpoints/TestEndpointAdaptor.ts
117
153
  /**
@@ -131,6 +167,8 @@ function serializeCookie(name, value, options) {
131
167
  return cookieString;
132
168
  }
133
169
  var TestEndpointAdaptor = class TestEndpointAdaptor {
170
+ endpoint;
171
+ serviceDiscovery;
134
172
  static getDefaultServiceDiscover(_endpoint) {
135
173
  return ServiceDiscovery.getInstance(new EnvironmentParser({}));
136
174
  }
@@ -146,17 +184,17 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
146
184
  const cookie = createCookieHeaderAccessor(ctx.headers.cookie);
147
185
  const startTime = Date.now();
148
186
  const requestId = ctx.requestId ?? ctx.headers["x-request-id"] ?? crypto.randomUUID();
149
- const logger = this.endpoint.logger.child({
187
+ let logger = requestLogger(this.endpoint, {
150
188
  requestId,
151
- route: this.endpoint.route,
152
- host: ctx.headers.host,
153
- method: this.endpoint.method
189
+ host: ctx.headers.host
154
190
  });
155
191
  const rawDb = ctx.database;
192
+ const operation = `${this.endpoint.method} ${this.endpoint.route}`;
156
193
  return runWithRequestContext({
157
194
  logger,
158
195
  requestId,
159
- startTime
196
+ startTime,
197
+ operation
160
198
  }, async () => {
161
199
  const session = await this.endpoint.getSession({
162
200
  logger,
@@ -165,7 +203,8 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
165
203
  cookie,
166
204
  ...rawDb !== void 0 && { db: rawDb }
167
205
  });
168
- const isAuthorized = await this.endpoint.authorize({
206
+ logger = currentRequestContext()?.logger ?? logger;
207
+ if (!await this.endpoint.authorize({
169
208
  header,
170
209
  cookie,
171
210
  services: ctx.services,
@@ -175,11 +214,18 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
175
214
  body,
176
215
  query,
177
216
  params
178
- });
179
- if (!isAuthorized) {
217
+ })) {
180
218
  logger.warn("Forbidden access attempt");
181
219
  throw new ForbiddenError("Forbidden access to the endpoint", "You do not have permission to access this resource.");
182
220
  }
221
+ const rateLimitHeaders = this.endpoint.rateLimit ? await enforceRateLimit(this.endpoint.rateLimit, {
222
+ header,
223
+ services: ctx.services,
224
+ logger,
225
+ session,
226
+ path: this.endpoint.route,
227
+ method: this.endpoint.method
228
+ }) : {};
183
229
  const auditorStorage = ctx.auditorStorage;
184
230
  let auditContext;
185
231
  if (auditorStorage) {
@@ -198,24 +244,22 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
198
244
  } catch (error) {
199
245
  logger.error(error, "Failed to extract actor for audits");
200
246
  }
201
- const auditor = new DefaultAuditor({
202
- actor,
203
- storage: auditorStorage,
204
- metadata: {
205
- endpoint: this.endpoint.route,
206
- method: this.endpoint.method
207
- }
208
- });
209
247
  auditContext = {
210
- auditor,
248
+ auditor: new DefaultAuditor({
249
+ actor,
250
+ storage: auditorStorage,
251
+ metadata: {
252
+ endpoint: this.endpoint.route,
253
+ method: this.endpoint.method
254
+ }
255
+ }),
211
256
  storage: auditorStorage
212
257
  };
213
258
  }
214
259
  const audits = this.endpoint.audits;
215
260
  if (!auditContext && audits?.length) logger.warn("No auditor storage service available");
216
- const result = await executeWithAuditTransaction(auditContext, async (auditor) => {
217
- const trx = auditor?.getTransaction?.();
218
- const db = trx ?? rawDb;
261
+ const { output, metadata, redirect } = await executeWithAuditTransaction(auditContext, async (auditor) => {
262
+ const db = auditor?.getTransaction?.() ?? rawDb;
219
263
  const responseBuilder = new ResponseBuilder();
220
264
  const response = await this.endpoint.handler({
221
265
  body,
@@ -230,54 +274,56 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
230
274
  db
231
275
  }, responseBuilder);
232
276
  let data = response;
233
- let metadata$1 = responseBuilder.getMetadata();
277
+ let metadata = responseBuilder.getMetadata();
234
278
  if (Endpoint.hasMetadata(response)) {
235
279
  data = response.data;
236
- metadata$1 = response.metadata;
280
+ metadata = response.metadata;
237
281
  }
238
- const output$1 = await this.endpoint.parseOutput(data);
282
+ const redirect = Endpoint.isRedirectStatus(metadata.status ?? this.endpoint.status);
239
283
  return {
240
- output: output$1,
241
- metadata: metadata$1,
242
- responseBuilder
284
+ output: redirect ? void 0 : await this.endpoint.parseOutput(data),
285
+ metadata,
286
+ responseBuilder,
287
+ redirect
243
288
  };
244
- }, async (result$1, auditor) => {
245
- if (!audits?.length) return;
289
+ }, async (result, auditor) => {
290
+ if (!audits?.length || result.redirect) return;
246
291
  for (const audit of audits) {
247
- if (audit.when && !audit.when(result$1.output)) continue;
248
- const payload = audit.payload(result$1.output);
249
- const entityId = audit.entityId?.(result$1.output);
292
+ if (audit.when && !audit.when(result.output)) continue;
293
+ const payload = audit.payload(result.output);
294
+ const entityId = audit.entityId?.(result.output);
250
295
  auditor.audit(audit.type, payload, {
251
296
  table: audit.table,
252
297
  entityId
253
298
  });
254
299
  }
255
300
  }, { db: rawDb });
256
- const { output, metadata } = result;
257
- ctx.publisher && await this.serviceDiscovery.register([ctx.publisher]);
258
- await publishConstructEvents(this.endpoint, output, this.serviceDiscovery);
259
- const headers = { ...metadata.headers || {} };
301
+ if (!redirect) await publishConstructEvents(this.endpoint, output, this.serviceDiscovery, this.endpoint.logger, ctx.services);
302
+ const headers = {
303
+ ...rateLimitHeaders,
304
+ ...metadata.headers || {}
305
+ };
260
306
  if (metadata.cookies && metadata.cookies.size > 0) {
261
307
  const setCookieValues = [];
262
- for (const [name, cookie$1] of metadata.cookies.entries()) setCookieValues.push(serializeCookie(name, cookie$1.value, cookie$1.options));
308
+ for (const [name, cookie] of metadata.cookies.entries()) setCookieValues.push(serializeCookie(name, cookie.value, cookie.options));
263
309
  headers["set-cookie"] = setCookieValues;
264
310
  }
265
311
  return {
266
312
  body: output,
267
- status: metadata.status || 200,
313
+ status: metadata.status ?? this.endpoint.status,
268
314
  headers
269
315
  };
270
316
  });
271
317
  }
272
318
  async request(ctx) {
273
- const response = await this.fullRequest(ctx);
274
- return response.body;
319
+ return (await this.fullRequest(ctx)).body;
275
320
  }
276
321
  };
277
-
278
322
  //#endregion
279
323
  //#region src/functions/TestFunctionAdaptor.ts
280
324
  var TestFunctionAdaptor = class TestFunctionAdaptor {
325
+ fn;
326
+ serviceDiscovery;
281
327
  static getDefaultServiceDiscovery(_fn) {
282
328
  return ServiceDiscovery.getInstance(new EnvironmentParser({}));
283
329
  }
@@ -293,15 +339,11 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
293
339
  else services = await this.serviceDiscovery.register(this.fn.services);
294
340
  let db;
295
341
  if ("db" in ctx && ctx.db !== void 0) db = ctx.db;
296
- else if (this.fn.databaseService) {
297
- const dbServices = await this.serviceDiscovery.register([this.fn.databaseService]);
298
- db = dbServices[this.fn.databaseService.serviceName];
299
- }
342
+ else if (this.fn.databaseService) db = (await this.serviceDiscovery.register([this.fn.databaseService]))[this.fn.databaseService.serviceName];
300
343
  let auditor;
301
344
  if ("auditor" in ctx && ctx.auditor !== void 0) auditor = ctx.auditor;
302
345
  else if (this.fn.auditorStorageService) {
303
- const auditServices = await this.serviceDiscovery.register([this.fn.auditorStorageService]);
304
- const storage = auditServices[this.fn.auditorStorageService.serviceName];
346
+ const storage = (await this.serviceDiscovery.register([this.fn.auditorStorageService]))[this.fn.auditorStorageService.serviceName];
305
347
  auditor = new DefaultAuditor({
306
348
  actor: {
307
349
  id: "system",
@@ -315,11 +357,10 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
315
357
  });
316
358
  }
317
359
  const requestId = `test-${Date.now()}`;
318
- const startTime = Date.now();
319
360
  return runWithRequestContext({
320
361
  logger,
321
362
  requestId,
322
- startTime
363
+ startTime: Date.now()
323
364
  }, async () => {
324
365
  const response = await this.fn.fn({
325
366
  input: parsedInput,
@@ -336,24 +377,26 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
336
377
  await auditor.flush();
337
378
  }
338
379
  }
339
- await publishEvents(logger, this.serviceDiscovery, this.fn.events, output, this.fn.publisherService);
380
+ await publishEvents(logger, this.serviceDiscovery, this.fn.events, output, services);
340
381
  return output;
341
382
  });
342
383
  }
343
384
  };
344
-
345
385
  //#endregion
346
386
  //#region src/queue/TestQueueAdaptor.ts
347
387
  /**
348
388
  * In-memory test driver for a {@link Queue} worker. Hand it a batch of messages
349
389
  * and it registers the queue's services, runs the handler in a request context,
350
- * and returns the handler result — no SQS/pg-boss required.
390
+ * and returns the handler result — no SQS/pg-boss required. A queue with a
391
+ * database gets `db` registered from it, or the one the request passes.
351
392
  *
352
393
  * @example
353
394
  * const adapter = new TestQueueAdaptor(ordersQueue);
354
395
  * await adapter.invoke({ messages: [{ orderId: '123' }] });
355
396
  */
356
397
  var TestQueueAdaptor = class TestQueueAdaptor {
398
+ queue;
399
+ serviceDiscovery;
357
400
  static getDefaultServiceDiscovery() {
358
401
  return ServiceDiscovery.getInstance(new EnvironmentParser({}));
359
402
  }
@@ -364,23 +407,33 @@ var TestQueueAdaptor = class TestQueueAdaptor {
364
407
  async invoke(request) {
365
408
  const logger = this.queue.logger.child({ test: true });
366
409
  const services = request.services ?? await this.serviceDiscovery.register(this.queue.services);
410
+ const db = request.db !== void 0 ? request.db : await this.getDatabase();
367
411
  const requestId = `test-${Date.now()}`;
368
412
  const startTime = Date.now();
413
+ const operation = `queue ${this.queue.name}`;
369
414
  return runWithRequestContext({
370
415
  logger,
371
416
  requestId,
372
- startTime
417
+ startTime,
418
+ operation
373
419
  }, () => this.queue.handler({
374
420
  messages: request.messages,
375
421
  services,
376
- logger
422
+ logger,
423
+ db
377
424
  }));
378
425
  }
426
+ async getDatabase() {
427
+ const service = this.queue.databaseService;
428
+ if (!service) return void 0;
429
+ return (await this.serviceDiscovery.register([service]))[service.serviceName];
430
+ }
379
431
  };
380
-
381
432
  //#endregion
382
433
  //#region src/subscribers/TestSubscriberAdaptor.ts
383
434
  var TestSubscriberAdaptor = class TestSubscriberAdaptor {
435
+ subscriber;
436
+ serviceDiscovery;
384
437
  static getDefaultServiceDiscovery() {
385
438
  return ServiceDiscovery.getInstance(new EnvironmentParser({}));
386
439
  }
@@ -393,19 +446,23 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
393
446
  let services;
394
447
  if (request.services) services = request.services;
395
448
  else services = await this.serviceDiscovery.register(this.subscriber.services);
449
+ const db = request.db !== void 0 ? request.db : await this.getDatabase();
396
450
  const filteredEvents = this.filterEvents(request.events);
397
451
  if (filteredEvents.length === 0) return { batchItemFailures: [] };
398
452
  const requestId = `test-${Date.now()}`;
399
453
  const startTime = Date.now();
454
+ const operation = `subscriber ${this.subscriber.topicName ?? "test"}`;
400
455
  return runWithRequestContext({
401
456
  logger,
402
457
  requestId,
403
- startTime
458
+ startTime,
459
+ operation
404
460
  }, async () => {
405
461
  const result = await this.subscriber.handler({
406
462
  events: filteredEvents,
407
463
  services,
408
- logger
464
+ logger,
465
+ db
409
466
  });
410
467
  let output = result;
411
468
  if (this.subscriber.outputSchema && result) {
@@ -413,16 +470,607 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
413
470
  if (validationResult.issues) throw new Error("Subscriber output validation failed");
414
471
  output = validationResult.value;
415
472
  }
416
- await publishEvents(logger, this.serviceDiscovery, this.subscriber.events, output, this.subscriber.publisherService);
417
473
  return output;
418
474
  });
419
475
  }
476
+ async getDatabase() {
477
+ const service = this.subscriber.databaseService;
478
+ if (!service) return void 0;
479
+ return (await this.serviceDiscovery.register([service]))[service.serviceName];
480
+ }
420
481
  filterEvents(events) {
421
482
  if (!this.subscriber.subscribedEvents) return events;
422
483
  return events.filter((event) => this.subscriber.subscribedEvents.includes(event.type));
423
484
  }
424
485
  };
425
-
426
486
  //#endregion
427
- export { TEST_CONTEXT_HEADER, TestEndpointAdaptor, TestFunctionAdaptor, TestQueueAdaptor, TestSubscriberAdaptor, createMswHandlers };
487
+ //#region src/testing/manifest.ts
488
+ /**
489
+ * The test manifest: what `gkm test` knows about an app, written down for the
490
+ * suite it starts.
491
+ *
492
+ * `gkm test` discovers the constructs, reconciles the test stage and resolves
493
+ * its environment — then, until this existed, threw all of it away and left a
494
+ * test to declare it again by hand. The manifest keeps it: which construct and
495
+ * endpoint is exported where, and the environment the test stage resolved,
496
+ * under the keys the constructs themselves derive. A feature test is built from
497
+ * it, so nothing a test says can drift from what the app declares.
498
+ */
499
+ /** The environment variable `gkm test` names the manifest in. */
500
+ const TEST_MANIFEST_ENV = "GKM_TEST_MANIFEST";
501
+ /**
502
+ * Read a test manifest: from a path, a `file:` URL, or — given nothing — the
503
+ * one `gkm test` named in `GKM_TEST_MANIFEST`.
504
+ */
505
+ function loadTestManifest(from) {
506
+ const location = from ?? process.env["GKM_TEST_MANIFEST"];
507
+ if (!location) throw new NoTestManifest();
508
+ trustLocalEdge();
509
+ const path = location instanceof URL || location.startsWith("file:") ? fileURLToPath(location) : location;
510
+ return JSON.parse(readFileSync(path, "utf-8"));
511
+ }
512
+ let trusted = false;
513
+ /**
514
+ * Trust the local edge's certificate authority in this thread.
515
+ *
516
+ * `NODE_EXTRA_CA_CERTS` does it for a process started with it — which a
517
+ * suite started by `gkm test` is, and one started by plain `vitest` or an
518
+ * editor is not: its setup only learns the path once Vitest is running, and a
519
+ * worker *thread* shares that process and keeps a TLS store of its own. Every
520
+ * feature test loads the manifest, so this is the one place each worker passes
521
+ * through.
522
+ */
523
+ function trustLocalEdge() {
524
+ const certificate = process.env.NODE_EXTRA_CA_CERTS;
525
+ if (trusted || !certificate || !existsSync(certificate)) return;
526
+ trusted = true;
527
+ tls.setDefaultCACertificates([...tls.getCACertificates("default"), readFileSync(certificate, "utf-8")]);
528
+ }
529
+ /** A feature test ran without a manifest to build itself from. */
530
+ var NoTestManifest = class extends Error {
531
+ constructor() {
532
+ super(`No test manifest: run the suite with \`gkm test\`, or add \`globalSetup: ['@geekmidas/cli/vitest']\` to the root vitest config — either writes one and names it in ${TEST_MANIFEST_ENV}.`);
533
+ this.name = "NoTestManifest";
534
+ }
535
+ };
536
+ //#endregion
537
+ //#region src/testing/featureTest.ts
538
+ /**
539
+ * `featureTest`: an app, driven the way it runs deployed.
540
+ *
541
+ * A browser signs in and calls the API; the API calls the auth server; each
542
+ * over its URL, each database in its own transaction. Nothing runs as a server:
543
+ * every URL an app's constructs answer on is served in-process through MSW,
544
+ * from the real handler, for the test that made the request. Everything else
545
+ * with a real local equivalent — Postgres, Mailpit, MinIO — is used directly.
546
+ *
547
+ * It is built from the test manifest `gkm test` writes — the constructs and
548
+ * endpoints the app exports, and the environment the test stage resolved — so
549
+ * a test declares none of it. `gkm test` also generates the configured `it`
550
+ * and a `Browser` with a typed client per surface:
551
+ *
552
+ * ```ts
553
+ * import { it } from '#test';
554
+ *
555
+ * it('shows the signed-in user their profile', async ({ browser, mailbox }) => {
556
+ * await browser.auth.signIn.magicLink({ email: 'ada@shop.test' });
557
+ * await browser.visit((await mailbox('ada@shop.test').last()).link!);
558
+ * expect(await browser.api.get('/profile')).toMatchObject({ email: 'ada@shop.test' });
559
+ * });
560
+ * ```
561
+ */
562
+ /** Every test in flight in this process, by id. */
563
+ const contexts = /* @__PURE__ */ new Map();
564
+ /** Databases already resolving to test transactions — patched once each. */
565
+ const bound = /* @__PURE__ */ new WeakSet();
566
+ function featureTest(options = {}) {
567
+ const manifest = options.manifest ?? loadTestManifest();
568
+ const BrowserClass = options.browser ?? Browser;
569
+ let app;
570
+ let factoryDatabases = [];
571
+ let owned = [];
572
+ let network;
573
+ let restoreFetch = () => {};
574
+ beforeAll(async () => {
575
+ app = await load(manifest, options.modules ?? {});
576
+ owned = ownDatabases(app, manifest);
577
+ factoryDatabases = databasesFor(options.factories ?? {}, owned);
578
+ for (const database of app.databases) bindToTests(database);
579
+ network = setupServer(...surfaceHandlers(app.endpoints, manifest.env), ...app.auths.map((auth) => authHandler(auth, manifest.env, app.envParser)), ...Object.entries(options.fakes ?? {}).flatMap(([id, fake]) => fakeHandler(id, fake, manifest.env)));
580
+ network.listen({ onUnhandledRequest(request, print) {
581
+ if (isLocal(new URL(request.url))) return;
582
+ print.error();
583
+ } });
584
+ const restoreStamp = installContextFetch();
585
+ const stamped = globalThis.fetch;
586
+ globalThis.fetch = deliveringFetch(stamped, (id) => {
587
+ const state = contexts.get(id);
588
+ return state ? deliver(app, state, id) : Promise.resolve();
589
+ });
590
+ restoreFetch = () => {
591
+ globalThis.fetch = stamped;
592
+ restoreStamp();
593
+ };
594
+ });
595
+ afterAll(() => {
596
+ restoreFetch();
597
+ network?.close();
598
+ });
599
+ const run = (name, fn) => async () => {
600
+ const id = randomUUID();
601
+ faker.seed(seedOf(name));
602
+ const state = {
603
+ transactions: new TransactionRegistry(),
604
+ discovery: new ServiceDiscovery(app.envParser),
605
+ surfaces: /* @__PURE__ */ new Map(),
606
+ auth: /* @__PURE__ */ new Map(),
607
+ addresses: /* @__PURE__ */ new Set(),
608
+ published: /* @__PURE__ */ new Map(),
609
+ pending: [],
610
+ delivering: false
611
+ };
612
+ const readMail = app.readMail;
613
+ if (readMail) state.mailbox = (address) => {
614
+ state.addresses.add(address);
615
+ return readMail(address);
616
+ };
617
+ contexts.set(id, state);
618
+ await state.discovery.register(recorders(app.channels, state));
619
+ try {
620
+ await runInTestContext(id, async () => {
621
+ const browser = new BrowserClass();
622
+ const restore = browser.install();
623
+ try {
624
+ const transaction = (database) => state.transactions.get(database.id, urlOf(database, app.envParser), database.clientConfig);
625
+ const db = { get: (name) => {
626
+ const database = owned.find((candidate) => candidate.service.serviceName === name);
627
+ if (!database) throw new UnknownDatabase(name, owned.map((candidate) => candidate.service.serviceName));
628
+ return transaction(database);
629
+ } };
630
+ const built = /* @__PURE__ */ new Map();
631
+ await fn({
632
+ browser,
633
+ db,
634
+ factories: { get: (name) => {
635
+ const database = factoryDatabases.find(([candidate]) => candidate === name)?.[1];
636
+ if (!database) throw new UnknownFactory(name, factoryDatabases.map(([candidate]) => candidate));
637
+ let factory = built.get(name);
638
+ if (!factory) {
639
+ factory = transaction(database).then(options.factories[name]);
640
+ built.set(name, factory);
641
+ }
642
+ return factory;
643
+ } },
644
+ faker,
645
+ mailbox: (address) => {
646
+ if (!state.mailbox) throw new NoInbox();
647
+ return state.mailbox(address);
648
+ },
649
+ published: (channel) => [...state.published.get(channel.id) ?? []],
650
+ services: { get: (name) => resolveService(app, state, name) },
651
+ subscriber: (subscriber) => thenDeliver(new TestSubscriberAdaptor(subscriber, state.discovery), () => deliver(app, state, id)),
652
+ queue: (queue) => thenDeliver(new TestQueueAdaptor(queue, state.discovery), () => deliver(app, state, id))
653
+ });
654
+ } finally {
655
+ restore();
656
+ }
657
+ });
658
+ } finally {
659
+ contexts.delete(id);
660
+ await Promise.all([state.transactions.rollbackAll(), ...[...state.addresses].map((address) => app.readMail?.(address).clear())]);
661
+ }
662
+ };
663
+ const it = ((name, fn, timeout) => test(name, run(name, fn), timeout));
664
+ it.only = (name, fn, timeout) => test.only(name, run(name, fn), timeout);
665
+ it.skip = (name, fn, timeout) => test.skip(name, run(name, fn), timeout);
666
+ return it;
667
+ }
668
+ /**
669
+ * A test's faker seed, from its name: the same test draws the same data on
670
+ * every run, and two tests draw different data.
671
+ */
672
+ function seedOf(name) {
673
+ let hash = 0;
674
+ for (const char of name) hash = Math.imul(hash, 31) + char.charCodeAt(0) | 0;
675
+ return hash >>> 0;
676
+ }
677
+ /**
678
+ * Import what the manifest points at.
679
+ *
680
+ * The same modules the app runs, so a construct here *is* the app's construct —
681
+ * the one its endpoints were built from — never a copy declared again.
682
+ */
683
+ async function load(manifest, modules) {
684
+ const envParser = new EnvironmentParser({ ...manifest.env });
685
+ const imported = async ({ file, export: name }) => (modules[file] ?? await import(file))[name];
686
+ const constructs = await Promise.all(Object.values(manifest.constructs).map(({ source }) => imported(source)));
687
+ const endpoints = (await Promise.all(manifest.endpoints.map(({ source }) => imported(source)))).filter((value) => Endpoint.isEndpoint(value));
688
+ const subscribers = (await Promise.all((manifest.subscribers ?? []).map(async ({ source }) => ({
689
+ name: source.export,
690
+ subscriber: await imported(source)
691
+ })))).filter((entry) => entry.subscriber?.__IS_SUBSCRIBER__ === true);
692
+ const unique = (values) => [...new Set(values)];
693
+ const databases = unique(constructs.filter((value) => value instanceof KyselyDatabase));
694
+ const auths = unique(constructs.filter((value) => value instanceof BetterAuth));
695
+ const emails = unique(constructs.filter((value) => value instanceof Email));
696
+ const consumables = unique(constructs.filter(isConsumable));
697
+ const channels = unique(constructs.filter((value) => value instanceof Topic || value instanceof Queue));
698
+ const inbox = emails.map((email) => manifest.env[provideKey(email.id, "inboxUrl")]).find(Boolean);
699
+ return {
700
+ envParser,
701
+ endpoints,
702
+ databases,
703
+ auths,
704
+ emails,
705
+ channels,
706
+ consumables,
707
+ subscribers,
708
+ ...inbox ? { readMail: createMailbox({ inbox }) } : {}
709
+ };
710
+ }
711
+ /**
712
+ * A publisher that records rather than sends, under the name a topic or queue
713
+ * is injected by — `services.users` — which is also the one `.event(users, …)`
714
+ * publishes through.
715
+ */
716
+ function recorders(channels, state) {
717
+ return channels.map((channel) => {
718
+ const publisher = { async publish(messages) {
719
+ const sent = messages.map(({ type, payload }) => ({
720
+ type,
721
+ payload
722
+ }));
723
+ state.published.set(channel.id, [...state.published.get(channel.id) ?? [], ...sent]);
724
+ state.pending.push({
725
+ channel,
726
+ messages: sent
727
+ });
728
+ } };
729
+ return {
730
+ serviceName: channel.service.serviceName,
731
+ register: () => publisher
732
+ };
733
+ });
734
+ }
735
+ /**
736
+ * The databases a test is handed: the app's own. A schema tenant an auth server
737
+ * owns is reached through that server, as the app reaches it, and a reader is
738
+ * the same database through a read-only role — neither is another database to
739
+ * test against.
740
+ */
741
+ function ownDatabases(app, manifest) {
742
+ const owners = new Set(app.auths.map((auth) => auth.databaseId));
743
+ return app.databases.filter((database) => !owners.has(database.id) && manifest.constructs[database.id]?.kind !== "database-reader");
744
+ }
745
+ /** Each factory's database, found by the service name it is keyed by. */
746
+ function databasesFor(factories, databases) {
747
+ return Object.keys(factories).map((name) => {
748
+ const database = databases.find((candidate) => candidate.service.serviceName === name);
749
+ if (!database) throw new UnknownFactory(name, databases.map((candidate) => candidate.service.serviceName));
750
+ return [name, database];
751
+ });
752
+ }
753
+ /**
754
+ * Make a database resolve, inside a test, to that test's transaction.
755
+ *
756
+ * Everything reaches a database through its service — an endpoint through
757
+ * service discovery, the auth server through its tenant directly — so this is
758
+ * the one place a test's connection can be handed over. Outside a test it is
759
+ * the database it always was.
760
+ */
761
+ /** Rounds of delivery before a chain of consumers is called a loop. */
762
+ const MAX_DELIVERY_ROUNDS = 25;
763
+ /**
764
+ * Deliver what this test published, in-process, as the broker would — and
765
+ * keep delivering what the consumers publish in turn, until nothing is left.
766
+ *
767
+ * - A queue's messages go to its one consumer, as a batch.
768
+ * - A topic's events go to every subscriber that named their type, and only
769
+ * those: fan-out, as the filter policy (SNS) or the per-subscriber queue
770
+ * (pg-boss) does it.
771
+ * - Each payload is checked against the consumer's schema first. Turning an
772
+ * SNS envelope or an SQS record into `{ type, payload }` is each adaptor's
773
+ * job and tested there; what is tested here is what the handler is handed.
774
+ * - Consumers run as the server side of this test, so their databases are
775
+ * this test's transactions and their writes roll back with it.
776
+ * - A consumer that throws fails the test. Deployed, the message would be
777
+ * retried; here a retry would only hide the bug.
778
+ */
779
+ async function deliver(app, state, id) {
780
+ if (state.delivering) return;
781
+ state.delivering = true;
782
+ try {
783
+ for (let round = 0; state.pending.length > 0; round++) {
784
+ if (round === MAX_DELIVERY_ROUNDS) throw new DeliveryDidNotSettle(MAX_DELIVERY_ROUNDS, [...new Set(state.pending.map(({ channel }) => channel.id))]);
785
+ for (const { channel, messages } of state.pending.splice(0)) if (channel instanceof Queue) await toQueue(channel, messages, state, id);
786
+ else await toSubscribers(channel, messages, app, state, id);
787
+ }
788
+ } finally {
789
+ state.delivering = false;
790
+ }
791
+ }
792
+ async function toQueue(queue, messages, state, id) {
793
+ const payloads = [];
794
+ for (const message of messages) payloads.push(await accepted(queue.messageSchema, message, `queue '${queue.name}'`));
795
+ await runAsServer(id, () => new TestQueueAdaptor(queue, state.discovery).invoke({ messages: payloads })).catch((error) => {
796
+ throw new DeliveryFailed(`queue '${queue.name}'`, messages, error);
797
+ });
798
+ }
799
+ async function toSubscribers(topic, messages, app, state, id) {
800
+ for (const { name, subscriber } of app.subscribers) {
801
+ if (subscriber.topicName !== topic.name) continue;
802
+ const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
803
+ if (named.length === 0) continue;
804
+ const consumer = `subscriber '${name}'`;
805
+ const events = [];
806
+ for (const message of named) {
807
+ const schema = topic.eventSchemas[message.type];
808
+ events.push({
809
+ type: message.type,
810
+ payload: await accepted(schema, message, consumer)
811
+ });
812
+ }
813
+ await runAsServer(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events })).catch((error) => {
814
+ throw new DeliveryFailed(consumer, named, error);
815
+ });
816
+ }
817
+ }
818
+ /** The payload, if the consumer's schema takes it — what the handler is handed. */
819
+ async function accepted(schema, message, consumer) {
820
+ const standard = schema?.["~standard"];
821
+ if (!standard) return message.payload;
822
+ const result = await standard.validate(message.payload);
823
+ if (result.issues) throw new MessageRejected(consumer, message, result.issues);
824
+ return result.value;
825
+ }
826
+ /** `fetch`, delivering what the test published once each of its requests answers. */
827
+ function deliveringFetch(inner, settle) {
828
+ return async (input, init) => {
829
+ const context = currentTestContext();
830
+ const response = await inner(input, init);
831
+ if (context?.side === "client") await settle(context.id);
832
+ return response;
833
+ };
834
+ }
835
+ /** An adaptor whose `invoke` delivers what it published before returning. */
836
+ function thenDeliver(adaptor, settle) {
837
+ const invoke = adaptor.invoke.bind(adaptor);
838
+ adaptor.invoke = (async (...args) => {
839
+ const result = await invoke(...args);
840
+ await settle();
841
+ return result;
842
+ });
843
+ return adaptor;
844
+ }
845
+ function bindToTests(database) {
846
+ if (bound.has(database)) return;
847
+ bound.add(database);
848
+ const service = database.service;
849
+ const register = service.register;
850
+ service.register = (options) => {
851
+ const context = currentTestContext();
852
+ const state = context && contexts.get(context.id);
853
+ if (!state) return register(options);
854
+ return state.transactions.get(database.id, urlOf(database, options.envParser), database.clientConfig);
855
+ };
856
+ }
857
+ function urlOf(database, envParser) {
858
+ return envParser.create((get) => ({ url: get(provideKey(database.id, "url")).string() })).parse().url;
859
+ }
860
+ /** Each surface's endpoints, served at its URL for the test that asked. */
861
+ function surfaceHandlers(endpoints, env) {
862
+ const bySurface = /* @__PURE__ */ new Map();
863
+ for (const endpoint of endpoints) {
864
+ const surface = endpoint.surface?.id;
865
+ if (!surface) continue;
866
+ bySurface.set(surface, [...bySurface.get(surface) ?? [], endpoint]);
867
+ }
868
+ return [...bySurface].flatMap(([surface, served]) => {
869
+ const base = env[provideKey(surface, "url")];
870
+ if (!base) return [];
871
+ return http.all(`${trim(base)}/*`, ({ request }) => serve(request, async (state) => {
872
+ let app = state.surfaces.get(surface);
873
+ if (!app) {
874
+ app = Promise.resolve().then(() => {
875
+ const hono = new Hono();
876
+ HonoEndpoint.addRoutes(served, state.discovery, hono);
877
+ return hono;
878
+ });
879
+ state.surfaces.set(surface, app);
880
+ }
881
+ return (await app).fetch(request, inProcessBindings());
882
+ }));
883
+ });
884
+ }
885
+ /**
886
+ * An external API's app fake, answering at the URL the test stage resolved for
887
+ * it — so a handler that calls Polar calls the fake, and the test sets up
888
+ * nothing.
889
+ *
890
+ * Not per test, unlike a surface: a fake stands in for somebody else's server,
891
+ * which no test's transaction reaches. An image fake has no handler here — its
892
+ * container answers on localhost, which is let through.
893
+ */
894
+ function fakeHandler(id, fake, env) {
895
+ const base = env[provideKey(id, "url")];
896
+ if (fake.kind !== "app" || !base) return [];
897
+ return [http.all(`${trim(base)}/*`, ({ request }) => fake.handler.fetch(request))];
898
+ }
899
+ /**
900
+ * A construct's client for this test, by service name — through the test's own
901
+ * discovery, so a topic or queue is its recorder and a database its
902
+ * transaction, exactly as the test's endpoints get them.
903
+ */
904
+ async function resolveService(app, state, name) {
905
+ const construct = app.consumables.find((candidate) => candidate.service.serviceName === name);
906
+ if (!construct) throw new UnknownService(name, app.consumables.map((candidate) => candidate.service.serviceName));
907
+ return (await state.discovery.register([construct.service]))[name];
908
+ }
909
+ /** An auth server, served at its URL, on the transaction of the test that asked. */
910
+ function authHandler(auth, env, envParser) {
911
+ const base = trim(env[provideKey(auth.id, "url")] ?? "");
912
+ return http.all(`${base}/*`, ({ request }) => serve(request, async (state) => {
913
+ let app = state.auth.get(auth);
914
+ if (!app) {
915
+ app = auth.server({
916
+ envParser,
917
+ context: serviceContext
918
+ }).then(({ app }) => app);
919
+ state.auth.set(auth, app);
920
+ }
921
+ return (await app).fetch(request, inProcessBindings());
922
+ }));
923
+ }
924
+ /** Handle a request as the server side of the test it was made for. */
925
+ async function serve(request, handle) {
926
+ const id = testContextOf(request);
927
+ const state = id ? contexts.get(id) : void 0;
928
+ if (!id || !state) throw new UnknownTestContext(request.url, id);
929
+ return runAsServer(id, () => handle(state));
930
+ }
931
+ function trim(url) {
932
+ return url.replace(/\/$/, "");
933
+ }
934
+ function isLocal(url) {
935
+ return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname.endsWith(".localhost");
936
+ }
937
+ /**
938
+ * Sign a test's browser in the way a person does: ask the auth server for a
939
+ * magic link, open the email it sent, follow the link.
940
+ *
941
+ * What the generated `browser.signIn(email)` calls. The address's mail is
942
+ * cleared first — so the link is this request's, not one an earlier test left
943
+ * — and cleared again after the test, like any address a test reads. Returns
944
+ * the session the auth server then reports, as better-auth hands it back.
945
+ */
946
+ async function signInWithMagicLink(browser, auth, email = freshAddress()) {
947
+ const context = currentTestContext();
948
+ const state = context && contexts.get(context.id);
949
+ if (!state) throw new UnknownTestContext("signIn", context?.id);
950
+ if (!state.mailbox) throw new NoInbox();
951
+ const inbox = state.mailbox(email);
952
+ await inbox.clear();
953
+ const requested = await auth.signIn.magicLink({ email });
954
+ if (requested.error) throw new SignInFailed(email, `the auth server refused the magic link: ${requested.error.message ?? "no reason given"}`);
955
+ const mail = await inbox.last();
956
+ if (!mail.link) throw new SignInFailed(email, "its email held no link");
957
+ await browser.visit(mail.link);
958
+ const { data } = await auth.getSession();
959
+ if (!data) throw new SignInFailed(email, "the auth server reported no session after the link was opened");
960
+ return data;
961
+ }
962
+ /**
963
+ * An address nobody else signs in as — what `browser.signIn()` uses when the
964
+ * test does not care who it is.
965
+ *
966
+ * Unique rather than only seeded: tests in other files run at the same time,
967
+ * against the same Mailpit and the same unique columns, and a seeded address
968
+ * repeats wherever two tests share a name. The readable half is the seeded
969
+ * faker's, so a failure still names somebody.
970
+ */
971
+ function freshAddress() {
972
+ return `${faker.internet.username().toLowerCase().replace(/[^a-z0-9]/g, "")}.${randomUUID().slice(0, 8)}@example.test`;
973
+ }
974
+ /** `browser.signIn` finished without a session. */
975
+ var SignInFailed = class extends Error {
976
+ email;
977
+ reason;
978
+ constructor(email, reason) {
979
+ super(`Signing ${email} in failed: ${reason}.`);
980
+ this.email = email;
981
+ this.reason = reason;
982
+ this.name = "SignInFailed";
983
+ }
984
+ };
985
+ /** A request reached an in-process server without a test to belong to. */
986
+ var UnknownTestContext = class extends Error {
987
+ url;
988
+ id;
989
+ constructor(url, id) {
990
+ super(id ? `${url} was requested for test ${id}, which is not running. A request that outlives its test — an un-awaited call — lands here.` : `${url} was requested outside any test. Make the request inside a featureTest, so it reaches that test's transactions.`);
991
+ this.url = url;
992
+ this.id = id;
993
+ this.name = "UnknownTestContext";
994
+ }
995
+ };
996
+ /** `mailbox` was used in an app that declares no Email construct. */
997
+ var NoInbox = class extends Error {
998
+ constructor() {
999
+ super("mailbox() reads the inbox of the app's Email construct, and none was found in featureTest's modules — or `gkm test` did not inject its <ID>_INBOX_URL.");
1000
+ this.name = "NoInbox";
1001
+ }
1002
+ };
1003
+ /** `db.get(name)` named no database the test is handed. */
1004
+ var UnknownDatabase = class extends Error {
1005
+ database;
1006
+ known;
1007
+ constructor(database, known) {
1008
+ super(`db.get('${database}') names no database of this app's. ` + (known.length > 0 ? `Its databases: ${known.join(", ")}. ` : "It declares no database of its own. ") + "A tenant an auth server owns is reached through that server, and a reader through the database it reads.");
1009
+ this.database = database;
1010
+ this.known = known;
1011
+ this.name = "UnknownDatabase";
1012
+ }
1013
+ };
1014
+ /** A factory keyed by a service name no database the app declares has. */
1015
+ var UnknownFactory = class extends Error {
1016
+ factory;
1017
+ known;
1018
+ constructor(factory, known) {
1019
+ super(`There is a test factory for '${factory}', and no database this app declares is called that. ` + (known.length > 0 ? `Its databases: ${known.join(", ")}. ` : "It declares no database. ") + `Name the file after the database construct: test/factories/<construct>.ts.`);
1020
+ this.factory = factory;
1021
+ this.known = known;
1022
+ this.name = "UnknownFactory";
1023
+ }
1024
+ };
1025
+ /** A published message the consumer's own schema refuses. */
1026
+ var MessageRejected = class extends Error {
1027
+ consumer;
1028
+ published;
1029
+ issues;
1030
+ constructor(consumer, published, issues) {
1031
+ super(`${consumer} refuses '${published.type}': ${issues.map((issue) => issue.message).join("; ")}. What is published must be what the consumer's schema takes — fix the producer, or the schema.`);
1032
+ this.consumer = consumer;
1033
+ this.published = published;
1034
+ this.issues = issues;
1035
+ this.name = "MessageRejected";
1036
+ }
1037
+ };
1038
+ /** A consumer that threw while handling what the test published. */
1039
+ var DeliveryFailed = class extends Error {
1040
+ consumer;
1041
+ messages;
1042
+ cause;
1043
+ constructor(consumer, messages, cause) {
1044
+ super(`${consumer} failed handling ${messages.map(({ type }) => `'${type}'`).join(", ")}: ${cause?.message ?? String(cause)}. Deployed, the message would be retried; here the failure is the result.`, { cause });
1045
+ this.consumer = consumer;
1046
+ this.messages = messages;
1047
+ this.cause = cause;
1048
+ this.name = "DeliveryFailed";
1049
+ }
1050
+ };
1051
+ /** Consumers that kept publishing to each other without settling. */
1052
+ var DeliveryDidNotSettle = class extends Error {
1053
+ rounds;
1054
+ channels;
1055
+ constructor(rounds, channels) {
1056
+ super(`Delivery did not settle after ${rounds} rounds — consumers are still publishing to ${channels.join(", ")}. A consumer that publishes to what triggers it loops forever deployed too.`);
1057
+ this.rounds = rounds;
1058
+ this.channels = channels;
1059
+ this.name = "DeliveryDidNotSettle";
1060
+ }
1061
+ };
1062
+ /** `services.get(name)` for a name no construct of the app is served by. */
1063
+ var UnknownService = class extends Error {
1064
+ serviceName;
1065
+ available;
1066
+ constructor(serviceName, available) {
1067
+ super(`The app declares no construct served as '${serviceName}'. Its services are: ${available.join(", ") || "none"}.`);
1068
+ this.serviceName = serviceName;
1069
+ this.available = available;
1070
+ this.name = "UnknownService";
1071
+ }
1072
+ };
1073
+ //#endregion
1074
+ export { DeliveryDidNotSettle, DeliveryFailed, IN_PROCESS_PEER_ADDRESS, MessageRejected, NoInbox, NoTestManifest, SignInFailed, TEST_CONTEXT_HEADER, TEST_MANIFEST_ENV, TestEndpointAdaptor, TestFunctionAdaptor, TestQueueAdaptor, TestSubscriberAdaptor, UnknownDatabase, UnknownFactory, UnknownService, UnknownTestContext, createMswHandlers, featureTest, inProcessBindings, loadTestManifest, signInWithMagicLink };
1075
+
428
1076
  //# sourceMappingURL=testing.mjs.map