@geekmidas/constructs 10.0.0-alpha.13 → 10.0.0-alpha.131

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 (444) hide show
  1. package/README.md +222 -158
  2. package/dist/Construct-127M7yrl.d.cts +231 -0
  3. package/dist/Construct-127M7yrl.d.cts.map +1 -0
  4. package/dist/{Construct-BeYVu_QF.mjs → Construct-CGuc_Ijk.mjs} +8 -9
  5. package/dist/Construct-CGuc_Ijk.mjs.map +1 -0
  6. package/dist/{Construct-DqdlARxq.cjs → Construct-DorKS0Ua.cjs} +8 -9
  7. package/dist/Construct-DorKS0Ua.cjs.map +1 -0
  8. package/dist/Construct-DySlwh8o.d.mts +231 -0
  9. package/dist/Construct-DySlwh8o.d.mts.map +1 -0
  10. package/dist/{Cron-DKqnnTdH.d.cts → Cron-CFkpEys6.d.cts} +14 -7
  11. package/dist/Cron-CFkpEys6.d.cts.map +1 -0
  12. package/dist/{Cron-SyqS5oWJ.d.mts → Cron-CQoDSu-n.d.mts} +14 -7
  13. package/dist/Cron-CQoDSu-n.d.mts.map +1 -0
  14. package/dist/CronBuilder-1W-G_i15.d.mts +47 -0
  15. package/dist/CronBuilder-1W-G_i15.d.mts.map +1 -0
  16. package/dist/{CronBuilder-D_0HNBTr.mjs → CronBuilder-BJ5LoadF.mjs} +28 -11
  17. package/dist/CronBuilder-BJ5LoadF.mjs.map +1 -0
  18. package/dist/{CronBuilder-BdnI6lxF.cjs → CronBuilder-B_NSP-Y5.cjs} +27 -10
  19. package/dist/CronBuilder-B_NSP-Y5.cjs.map +1 -0
  20. package/dist/CronBuilder-OaCRRFVk.d.cts +47 -0
  21. package/dist/CronBuilder-OaCRRFVk.d.cts.map +1 -0
  22. package/dist/{Endpoint-C6yyHpRS.d.cts → Endpoint-BEh-jW-f.d.cts} +122 -41
  23. package/dist/Endpoint-BEh-jW-f.d.cts.map +1 -0
  24. package/dist/Endpoint-BcUorcBa.cjs +576 -0
  25. package/dist/Endpoint-BcUorcBa.cjs.map +1 -0
  26. package/dist/Endpoint-BgvG36NO.mjs +547 -0
  27. package/dist/Endpoint-BgvG36NO.mjs.map +1 -0
  28. package/dist/{Endpoint-DuT4TEEq.d.mts → Endpoint-DTXDggNl.d.mts} +124 -43
  29. package/dist/Endpoint-DTXDggNl.d.mts.map +1 -0
  30. package/dist/{index-BPSZ_Lp_.d.cts → EndpointFactory-B2dCS9dy.d.cts} +187 -104
  31. package/dist/EndpointFactory-B2dCS9dy.d.cts.map +1 -0
  32. package/dist/{EndpointFactory-ptPR1cXw.mjs → EndpointFactory-C1NlpCAS.mjs} +270 -54
  33. package/dist/EndpointFactory-C1NlpCAS.mjs.map +1 -0
  34. package/dist/{index-BoZ-iisU.d.mts → EndpointFactory-D2HXcUrJ.d.mts} +188 -105
  35. package/dist/EndpointFactory-D2HXcUrJ.d.mts.map +1 -0
  36. package/dist/{EndpointFactory-M8OQKZRY.cjs → EndpointFactory-gqmIRVWg.cjs} +310 -52
  37. package/dist/EndpointFactory-gqmIRVWg.cjs.map +1 -0
  38. package/dist/Function-BIEsY0Hm.d.cts +76 -0
  39. package/dist/Function-BIEsY0Hm.d.cts.map +1 -0
  40. package/dist/Function-DfMzTGS4.d.mts +76 -0
  41. package/dist/Function-DfMzTGS4.d.mts.map +1 -0
  42. package/dist/{HonoEndpointAdaptor-7QagYKdP.cjs → HonoEndpointAdaptor-BJlj20fQ.cjs} +79 -31
  43. package/dist/HonoEndpointAdaptor-BJlj20fQ.cjs.map +1 -0
  44. package/dist/{HonoEndpointAdaptor-CYHA0WAt.mjs → HonoEndpointAdaptor-BlbkUDNo.mjs} +76 -28
  45. package/dist/HonoEndpointAdaptor-BlbkUDNo.mjs.map +1 -0
  46. package/dist/ObjectSubscriberBuilder-HmBwFn2o.d.mts +129 -0
  47. package/dist/ObjectSubscriberBuilder-HmBwFn2o.d.mts.map +1 -0
  48. package/dist/ObjectSubscriberBuilder-l-64yUiF.d.cts +129 -0
  49. package/dist/ObjectSubscriberBuilder-l-64yUiF.d.cts.map +1 -0
  50. package/dist/ProcessorBuilder-B2_stA8f.d.mts +216 -0
  51. package/dist/ProcessorBuilder-B2_stA8f.d.mts.map +1 -0
  52. package/dist/ProcessorBuilder-C62bIOwj.d.cts +216 -0
  53. package/dist/ProcessorBuilder-C62bIOwj.d.cts.map +1 -0
  54. package/dist/{Queue-D9X6OoON.d.mts → Queue-BnK3UH8r.d.mts} +42 -41
  55. package/dist/Queue-BnK3UH8r.d.mts.map +1 -0
  56. package/dist/{Queue-DYPB2KWL.d.cts → Queue-C4rijiM7.d.cts} +43 -42
  57. package/dist/Queue-C4rijiM7.d.cts.map +1 -0
  58. package/dist/Queue-D4Iaidrs.cjs +109 -0
  59. package/dist/Queue-D4Iaidrs.cjs.map +1 -0
  60. package/dist/Queue-u8w8_HpE.mjs +104 -0
  61. package/dist/Queue-u8w8_HpE.mjs.map +1 -0
  62. package/dist/QueueBuilder-2wP5lEC8.mjs +118 -0
  63. package/dist/QueueBuilder-2wP5lEC8.mjs.map +1 -0
  64. package/dist/QueueBuilder-B3vL1ED2.d.mts +75 -0
  65. package/dist/QueueBuilder-B3vL1ED2.d.mts.map +1 -0
  66. package/dist/QueueBuilder-BcPBQSSX.d.cts +75 -0
  67. package/dist/QueueBuilder-BcPBQSSX.d.cts.map +1 -0
  68. package/dist/QueueBuilder-BxsZ9o5z.cjs +135 -0
  69. package/dist/QueueBuilder-BxsZ9o5z.cjs.map +1 -0
  70. package/dist/Subscriber-BdCtfFXL.d.cts +73 -0
  71. package/dist/Subscriber-BdCtfFXL.d.cts.map +1 -0
  72. package/dist/Subscriber-DDo4HFNn.d.mts +73 -0
  73. package/dist/Subscriber-DDo4HFNn.d.mts.map +1 -0
  74. package/dist/SubscriberBuilder-3msj1U2w.mjs +230 -0
  75. package/dist/SubscriberBuilder-3msj1U2w.mjs.map +1 -0
  76. package/dist/SubscriberBuilder-CQst6Iz3.cjs +253 -0
  77. package/dist/SubscriberBuilder-CQst6Iz3.cjs.map +1 -0
  78. package/dist/Topic-DN2gYJ-p.mjs +99 -0
  79. package/dist/Topic-DN2gYJ-p.mjs.map +1 -0
  80. package/dist/Topic-Dp9Q7Lj2.cjs +104 -0
  81. package/dist/Topic-Dp9Q7Lj2.cjs.map +1 -0
  82. package/dist/adaptors/aws.cjs +134 -160
  83. package/dist/adaptors/aws.cjs.map +1 -1
  84. package/dist/adaptors/aws.d.cts +57 -48
  85. package/dist/adaptors/aws.d.cts.map +1 -1
  86. package/dist/adaptors/aws.d.mts +58 -49
  87. package/dist/adaptors/aws.d.mts.map +1 -1
  88. package/dist/adaptors/aws.mjs +130 -157
  89. package/dist/adaptors/aws.mjs.map +1 -1
  90. package/dist/adaptors/hono.cjs +1 -1
  91. package/dist/adaptors/hono.d.cts +5 -6
  92. package/dist/adaptors/hono.d.cts.map +1 -1
  93. package/dist/adaptors/hono.d.mts +6 -7
  94. package/dist/adaptors/hono.d.mts.map +1 -1
  95. package/dist/adaptors/hono.mjs +1 -1
  96. package/dist/adaptors/testing.cjs +824 -38
  97. package/dist/adaptors/testing.cjs.map +1 -1
  98. package/dist/adaptors/testing.d.cts +368 -39
  99. package/dist/adaptors/testing.d.cts.map +1 -1
  100. package/dist/adaptors/testing.d.mts +367 -38
  101. package/dist/adaptors/testing.d.mts.map +1 -1
  102. package/dist/adaptors/testing.mjs +802 -34
  103. package/dist/adaptors/testing.mjs.map +1 -1
  104. package/dist/auth-BMCJN30Y.d.cts +268 -0
  105. package/dist/auth-BMCJN30Y.d.cts.map +1 -0
  106. package/dist/auth-D_0788uW.d.mts +268 -0
  107. package/dist/auth-D_0788uW.d.mts.map +1 -0
  108. package/dist/auth.cjs +289 -46
  109. package/dist/auth.cjs.map +1 -1
  110. package/dist/auth.d.cts +2 -104
  111. package/dist/auth.d.mts +2 -104
  112. package/dist/auth.mjs +285 -48
  113. package/dist/auth.mjs.map +1 -1
  114. package/dist/cache-5QZzh5Er.d.mts +44 -0
  115. package/dist/cache-5QZzh5Er.d.mts.map +1 -0
  116. package/dist/cache-DnGDGly3.d.cts +44 -0
  117. package/dist/cache-DnGDGly3.d.cts.map +1 -0
  118. package/dist/cache.d.cts +2 -43
  119. package/dist/cache.d.mts +2 -43
  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/cipher-DSDxPRIp.d.cts +106 -0
  125. package/dist/cipher-DSDxPRIp.d.cts.map +1 -0
  126. package/dist/cipher-DSDxPRIp.d.mts +106 -0
  127. package/dist/cipher-DSDxPRIp.d.mts.map +1 -0
  128. package/dist/{construct-interface-DPlxfpoS.d.mts → construct-interface-B1AfqRl4.d.cts} +42 -8
  129. package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
  130. package/dist/{construct-interface-DgXTJcOD.d.cts → construct-interface-ZvYQbivO.d.mts} +42 -8
  131. package/dist/construct-interface-ZvYQbivO.d.mts.map +1 -0
  132. package/dist/construct-interface.cjs +30 -4
  133. package/dist/construct-interface.cjs.map +1 -1
  134. package/dist/construct-interface.d.cts +2 -2
  135. package/dist/construct-interface.d.mts +2 -2
  136. package/dist/construct-interface.mjs +30 -5
  137. package/dist/construct-interface.mjs.map +1 -1
  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 +7 -129
  143. package/dist/credential.d.cts +2 -58
  144. package/dist/credential.d.mts +2 -58
  145. package/dist/credential.mjs +2 -128
  146. package/dist/crons/index.cjs +126 -1
  147. package/dist/crons/index.cjs.map +1 -1
  148. package/dist/crons/index.d.cts +43 -3
  149. package/dist/crons/index.d.cts.map +1 -1
  150. package/dist/crons/index.d.mts +43 -3
  151. package/dist/crons/index.d.mts.map +1 -1
  152. package/dist/crons/index.mjs +125 -2
  153. package/dist/crons/index.mjs.map +1 -1
  154. package/dist/database/kysely.cjs +3 -194
  155. package/dist/database/kysely.d.cts +2 -149
  156. package/dist/database/kysely.d.mts +2 -149
  157. package/dist/database/kysely.mjs +2 -192
  158. package/dist/email.d.cts +1 -1
  159. package/dist/email.d.cts.map +1 -1
  160. package/dist/email.d.mts +2 -2
  161. package/dist/email.d.mts.map +1 -1
  162. package/dist/encryption/kms.cjs +95 -0
  163. package/dist/encryption/kms.cjs.map +1 -0
  164. package/dist/encryption/kms.d.cts +7 -0
  165. package/dist/encryption/kms.d.cts.map +1 -0
  166. package/dist/encryption/kms.d.mts +7 -0
  167. package/dist/encryption/kms.d.mts.map +1 -0
  168. package/dist/encryption/kms.mjs +93 -0
  169. package/dist/encryption/kms.mjs.map +1 -0
  170. package/dist/encryption.cjs +116 -0
  171. package/dist/encryption.cjs.map +1 -0
  172. package/dist/encryption.d.cts +37 -0
  173. package/dist/encryption.d.cts.map +1 -0
  174. package/dist/encryption.d.mts +37 -0
  175. package/dist/encryption.d.mts.map +1 -0
  176. package/dist/encryption.mjs +101 -0
  177. package/dist/encryption.mjs.map +1 -0
  178. package/dist/endpoints/index.cjs +25 -10
  179. package/dist/endpoints/index.d.cts +105 -3
  180. package/dist/endpoints/index.d.cts.map +1 -0
  181. package/dist/endpoints/index.d.mts +105 -3
  182. package/dist/endpoints/index.d.mts.map +1 -0
  183. package/dist/endpoints/index.mjs +5 -4
  184. package/dist/expire-C586zznE.d.cts +38 -0
  185. package/dist/expire-C586zznE.d.cts.map +1 -0
  186. package/dist/expire-C586zznE.d.mts +38 -0
  187. package/dist/expire-C586zznE.d.mts.map +1 -0
  188. package/dist/expire-CieftS01.cjs +67 -0
  189. package/dist/expire-CieftS01.cjs.map +1 -0
  190. package/dist/expire-CpzUAfr9.mjs +50 -0
  191. package/dist/expire-CpzUAfr9.mjs.map +1 -0
  192. package/dist/external-api.cjs +106 -0
  193. package/dist/external-api.cjs.map +1 -0
  194. package/dist/external-api.d.cts +2 -0
  195. package/dist/external-api.d.mts +2 -0
  196. package/dist/external-api.mjs +103 -0
  197. package/dist/external-api.mjs.map +1 -0
  198. package/dist/fake-BUgcX2Dk.d.cts +201 -0
  199. package/dist/fake-BUgcX2Dk.d.cts.map +1 -0
  200. package/dist/fake-D472nkKb.d.mts +201 -0
  201. package/dist/fake-D472nkKb.d.mts.map +1 -0
  202. package/dist/file-server.cjs +123 -30
  203. package/dist/file-server.cjs.map +1 -1
  204. package/dist/file-server.d.cts +115 -1
  205. package/dist/file-server.d.cts.map +1 -1
  206. package/dist/file-server.d.mts +115 -1
  207. package/dist/file-server.d.mts.map +1 -1
  208. package/dist/file-server.mjs +122 -32
  209. package/dist/file-server.mjs.map +1 -1
  210. package/dist/functions/index.cjs +1 -1
  211. package/dist/functions/index.d.cts +2 -1
  212. package/dist/functions/index.d.mts +2 -1
  213. package/dist/functions/index.mjs +1 -1
  214. package/dist/{functions-C53GW2eQ.mjs → functions-BvIDQKAA.mjs} +117 -22
  215. package/dist/functions-BvIDQKAA.mjs.map +1 -0
  216. package/dist/{functions-B6qCvfmy.cjs → functions-DLF6-IK8.cjs} +122 -18
  217. package/dist/functions-DLF6-IK8.cjs.map +1 -0
  218. package/dist/index-BtzMzhMA.d.cts +115 -0
  219. package/dist/index-BtzMzhMA.d.cts.map +1 -0
  220. package/dist/{index-CeEtxDmK.d.cts → index-DdRjYhiJ.d.cts} +42 -2
  221. package/dist/{index-CeEtxDmK.d.cts.map → index-DdRjYhiJ.d.cts.map} +1 -1
  222. package/dist/{index-CeEtxDmK.d.mts → index-DdRjYhiJ.d.mts} +42 -2
  223. package/dist/{index-CeEtxDmK.d.mts.map → index-DdRjYhiJ.d.mts.map} +1 -1
  224. package/dist/index-DuriFjYD.d.mts +115 -0
  225. package/dist/index-DuriFjYD.d.mts.map +1 -0
  226. package/dist/index.cjs +4 -1
  227. package/dist/index.d.cts +26 -3
  228. package/dist/index.d.cts.map +1 -0
  229. package/dist/index.d.mts +26 -3
  230. package/dist/index.d.mts.map +1 -0
  231. package/dist/index.mjs +3 -2
  232. package/dist/kysely-BHYV-WC-.d.cts +216 -0
  233. package/dist/kysely-BHYV-WC-.d.cts.map +1 -0
  234. package/dist/kysely-CAW3QSqp.d.mts +216 -0
  235. package/dist/kysely-CAW3QSqp.d.mts.map +1 -0
  236. package/dist/kysely-Cs4uPO8k.mjs +371 -0
  237. package/dist/kysely-Cs4uPO8k.mjs.map +1 -0
  238. package/dist/kysely-CukArHJ0.cjs +384 -0
  239. package/dist/kysely-CukArHJ0.cjs.map +1 -0
  240. package/dist/{telemetry-DGcFlVpB.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +2 -2
  241. package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
  242. package/dist/{telemetry-DGcFlVpB.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +2 -2
  243. package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
  244. package/dist/mobile-app.cjs +74 -0
  245. package/dist/mobile-app.cjs.map +1 -0
  246. package/dist/mobile-app.d.cts +73 -0
  247. package/dist/mobile-app.d.cts.map +1 -0
  248. package/dist/mobile-app.d.mts +73 -0
  249. package/dist/mobile-app.d.mts.map +1 -0
  250. package/dist/mobile-app.mjs +73 -0
  251. package/dist/mobile-app.mjs.map +1 -0
  252. package/dist/object-storage.cjs +8 -1
  253. package/dist/object-storage.cjs.map +1 -1
  254. package/dist/object-storage.d.cts +10 -1
  255. package/dist/object-storage.d.cts.map +1 -1
  256. package/dist/object-storage.d.mts +10 -1
  257. package/dist/object-storage.d.mts.map +1 -1
  258. package/dist/object-storage.mjs +7 -2
  259. package/dist/object-storage.mjs.map +1 -1
  260. package/dist/pattern-C1CEcglD.mjs +241 -0
  261. package/dist/pattern-C1CEcglD.mjs.map +1 -0
  262. package/dist/pattern-QFaUIr77.cjs +288 -0
  263. package/dist/pattern-QFaUIr77.cjs.map +1 -0
  264. package/dist/processors/index.cjs +214 -0
  265. package/dist/processors/index.cjs.map +1 -0
  266. package/dist/processors/index.d.cts +78 -0
  267. package/dist/processors/index.d.cts.map +1 -0
  268. package/dist/processors/index.d.mts +78 -0
  269. package/dist/processors/index.d.mts.map +1 -0
  270. package/dist/processors/index.mjs +193 -0
  271. package/dist/processors/index.mjs.map +1 -0
  272. package/dist/queue/index.cjs +5 -192
  273. package/dist/queue/index.d.cts +3 -53
  274. package/dist/queue/index.d.mts +3 -53
  275. package/dist/queue/index.mjs +3 -190
  276. package/dist/random-password.cjs +86 -0
  277. package/dist/random-password.cjs.map +1 -0
  278. package/dist/random-password.d.cts +30 -0
  279. package/dist/random-password.d.cts.map +1 -0
  280. package/dist/random-password.d.mts +30 -0
  281. package/dist/random-password.d.mts.map +1 -0
  282. package/dist/random-password.mjs +84 -0
  283. package/dist/random-password.mjs.map +1 -0
  284. package/dist/{lazyAccessors-BHtcqgz2.mjs → readRequestBody-BTIl3k-D.mjs} +99 -39
  285. package/dist/readRequestBody-BTIl3k-D.mjs.map +1 -0
  286. package/dist/{lazyAccessors-Dx9NLwJZ.cjs → readRequestBody-Dej_L3c4.cjs} +118 -46
  287. package/dist/readRequestBody-Dej_L3c4.cjs.map +1 -0
  288. package/dist/requestLogger-BZcXwdBs.cjs +207 -0
  289. package/dist/requestLogger-BZcXwdBs.cjs.map +1 -0
  290. package/dist/requestLogger-pA4gi3E1.mjs +178 -0
  291. package/dist/requestLogger-pA4gi3E1.mjs.map +1 -0
  292. package/dist/rest-api.cjs +76 -43
  293. package/dist/rest-api.cjs.map +1 -1
  294. package/dist/rest-api.d.cts +64 -31
  295. package/dist/rest-api.d.cts.map +1 -1
  296. package/dist/rest-api.d.mts +64 -31
  297. package/dist/rest-api.d.mts.map +1 -1
  298. package/dist/rest-api.mjs +76 -43
  299. package/dist/rest-api.mjs.map +1 -1
  300. package/dist/runSubscriber-B1Yg4dID.cjs +128 -0
  301. package/dist/runSubscriber-B1Yg4dID.cjs.map +1 -0
  302. package/dist/runSubscriber-JCgkeYbE.mjs +111 -0
  303. package/dist/runSubscriber-JCgkeYbE.mjs.map +1 -0
  304. package/dist/shutdown-BMJmAhSt.cjs +38 -0
  305. package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
  306. package/dist/shutdown-C7xa8x9S.mjs +27 -0
  307. package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
  308. package/dist/site.cjs +9 -3
  309. package/dist/site.cjs.map +1 -1
  310. package/dist/site.d.cts +44 -1
  311. package/dist/site.d.cts.map +1 -1
  312. package/dist/site.d.mts +44 -1
  313. package/dist/site.d.mts.map +1 -1
  314. package/dist/site.mjs +9 -3
  315. package/dist/site.mjs.map +1 -1
  316. package/dist/stages-DaTaoQei.d.cts +73 -0
  317. package/dist/stages-DaTaoQei.d.cts.map +1 -0
  318. package/dist/stages-DaTaoQei.d.mts +73 -0
  319. package/dist/stages-DaTaoQei.d.mts.map +1 -0
  320. package/dist/subscribers/index.cjs +134 -1
  321. package/dist/subscribers/index.cjs.map +1 -0
  322. package/dist/subscribers/index.d.cts +74 -3
  323. package/dist/subscribers/index.d.cts.map +1 -0
  324. package/dist/subscribers/index.d.mts +74 -3
  325. package/dist/subscribers/index.d.mts.map +1 -0
  326. package/dist/subscribers/index.mjs +132 -2
  327. package/dist/subscribers/index.mjs.map +1 -0
  328. package/dist/telemetry-B48RLjyk.d.cts +40 -0
  329. package/dist/telemetry-B48RLjyk.d.cts.map +1 -0
  330. package/dist/telemetry-BEoBn6GO.d.mts +40 -0
  331. package/dist/telemetry-BEoBn6GO.d.mts.map +1 -0
  332. package/dist/telemetry.cjs +56 -0
  333. package/dist/telemetry.cjs.map +1 -0
  334. package/dist/telemetry.d.cts +2 -0
  335. package/dist/telemetry.d.mts +2 -0
  336. package/dist/telemetry.mjs +55 -0
  337. package/dist/telemetry.mjs.map +1 -0
  338. package/dist/topic/index.cjs +2 -134
  339. package/dist/topic/index.d.cts +2 -3
  340. package/dist/topic/index.d.mts +2 -3
  341. package/dist/topic/index.mjs +2 -132
  342. package/dist/tracing-Bbj1uoFJ.mjs +127 -0
  343. package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
  344. package/dist/tracing-C0ooU0V2.cjs +150 -0
  345. package/dist/tracing-C0ooU0V2.cjs.map +1 -0
  346. package/dist/websocket-api.cjs +769 -0
  347. package/dist/websocket-api.cjs.map +1 -0
  348. package/dist/websocket-api.d.cts +449 -0
  349. package/dist/websocket-api.d.cts.map +1 -0
  350. package/dist/websocket-api.d.mts +449 -0
  351. package/dist/websocket-api.d.mts.map +1 -0
  352. package/dist/websocket-api.mjs +755 -0
  353. package/dist/websocket-api.mjs.map +1 -0
  354. package/dist/worker.cjs +70 -23
  355. package/dist/worker.cjs.map +1 -1
  356. package/dist/worker.d.cts +86 -36
  357. package/dist/worker.d.cts.map +1 -1
  358. package/dist/worker.d.mts +87 -37
  359. package/dist/worker.d.mts.map +1 -1
  360. package/dist/worker.mjs +70 -23
  361. package/dist/worker.mjs.map +1 -1
  362. package/package.json +145 -44
  363. package/dist/Construct-BeYVu_QF.mjs.map +0 -1
  364. package/dist/Construct-DfbwIntp.d.cts +0 -115
  365. package/dist/Construct-DfbwIntp.d.cts.map +0 -1
  366. package/dist/Construct-DqdlARxq.cjs.map +0 -1
  367. package/dist/Construct-l5aOn_jv.d.mts +0 -115
  368. package/dist/Construct-l5aOn_jv.d.mts.map +0 -1
  369. package/dist/Cron-DKqnnTdH.d.cts.map +0 -1
  370. package/dist/Cron-SyqS5oWJ.d.mts.map +0 -1
  371. package/dist/CronBuilder-BdnI6lxF.cjs.map +0 -1
  372. package/dist/CronBuilder-CRGnDfTq.d.mts +0 -41
  373. package/dist/CronBuilder-CRGnDfTq.d.mts.map +0 -1
  374. package/dist/CronBuilder-D_0HNBTr.mjs.map +0 -1
  375. package/dist/CronBuilder-Df1q9PNy.d.cts +0 -41
  376. package/dist/CronBuilder-Df1q9PNy.d.cts.map +0 -1
  377. package/dist/Endpoint-BCiCYvx2.mjs +0 -1665
  378. package/dist/Endpoint-BCiCYvx2.mjs.map +0 -1
  379. package/dist/Endpoint-C6yyHpRS.d.cts.map +0 -1
  380. package/dist/Endpoint-DuT4TEEq.d.mts.map +0 -1
  381. package/dist/Endpoint-s0AyrQGC.cjs +0 -1683
  382. package/dist/Endpoint-s0AyrQGC.cjs.map +0 -1
  383. package/dist/EndpointFactory-M8OQKZRY.cjs.map +0 -1
  384. package/dist/EndpointFactory-ptPR1cXw.mjs.map +0 -1
  385. package/dist/HonoEndpointAdaptor-7QagYKdP.cjs.map +0 -1
  386. package/dist/HonoEndpointAdaptor-CYHA0WAt.mjs.map +0 -1
  387. package/dist/Queue-D9X6OoON.d.mts.map +0 -1
  388. package/dist/Queue-DYPB2KWL.d.cts.map +0 -1
  389. package/dist/Subscriber-C4heaAyO.d.mts +0 -51
  390. package/dist/Subscriber-C4heaAyO.d.mts.map +0 -1
  391. package/dist/Subscriber-CotDUELC.d.cts +0 -51
  392. package/dist/Subscriber-CotDUELC.d.cts.map +0 -1
  393. package/dist/SubscriberBuilder-BEv0eoHy.d.cts +0 -59
  394. package/dist/SubscriberBuilder-BEv0eoHy.d.cts.map +0 -1
  395. package/dist/SubscriberBuilder-C0ZEtGDI.cjs +0 -125
  396. package/dist/SubscriberBuilder-C0ZEtGDI.cjs.map +0 -1
  397. package/dist/SubscriberBuilder-h7B_cHMr.mjs +0 -114
  398. package/dist/SubscriberBuilder-h7B_cHMr.mjs.map +0 -1
  399. package/dist/SubscriberBuilder-tyH5yTk5.d.mts +0 -59
  400. package/dist/SubscriberBuilder-tyH5yTk5.d.mts.map +0 -1
  401. package/dist/Topic-DEVGo0Dm.d.cts +0 -89
  402. package/dist/Topic-DEVGo0Dm.d.cts.map +0 -1
  403. package/dist/Topic-zk_6Gthr.d.mts +0 -89
  404. package/dist/Topic-zk_6Gthr.d.mts.map +0 -1
  405. package/dist/auth.d.cts.map +0 -1
  406. package/dist/auth.d.mts.map +0 -1
  407. package/dist/cache.d.cts.map +0 -1
  408. package/dist/cache.d.mts.map +0 -1
  409. package/dist/construct-interface-DPlxfpoS.d.mts.map +0 -1
  410. package/dist/construct-interface-DgXTJcOD.d.cts.map +0 -1
  411. package/dist/credential.cjs.map +0 -1
  412. package/dist/credential.d.cts.map +0 -1
  413. package/dist/credential.d.mts.map +0 -1
  414. package/dist/credential.mjs.map +0 -1
  415. package/dist/database/kysely.cjs.map +0 -1
  416. package/dist/database/kysely.d.cts.map +0 -1
  417. package/dist/database/kysely.d.mts.map +0 -1
  418. package/dist/database/kysely.mjs.map +0 -1
  419. package/dist/functions-B6qCvfmy.cjs.map +0 -1
  420. package/dist/functions-C53GW2eQ.mjs.map +0 -1
  421. package/dist/index-B2urf3YI.d.cts +0 -26
  422. package/dist/index-B2urf3YI.d.cts.map +0 -1
  423. package/dist/index-BPSZ_Lp_.d.cts.map +0 -1
  424. package/dist/index-BoZ-iisU.d.mts.map +0 -1
  425. package/dist/index-CdaU--_B.d.cts +0 -165
  426. package/dist/index-CdaU--_B.d.cts.map +0 -1
  427. package/dist/index-DMCDvnsM.d.mts +0 -26
  428. package/dist/index-DMCDvnsM.d.mts.map +0 -1
  429. package/dist/index-PQRWOQj4.d.mts +0 -165
  430. package/dist/index-PQRWOQj4.d.mts.map +0 -1
  431. package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
  432. package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
  433. package/dist/processAudits-BpRlPQMW.mjs +0 -77
  434. package/dist/processAudits-BpRlPQMW.mjs.map +0 -1
  435. package/dist/processAudits-D_2W5x8k.cjs +0 -88
  436. package/dist/processAudits-D_2W5x8k.cjs.map +0 -1
  437. package/dist/queue/index.cjs.map +0 -1
  438. package/dist/queue/index.d.cts.map +0 -1
  439. package/dist/queue/index.d.mts.map +0 -1
  440. package/dist/queue/index.mjs.map +0 -1
  441. package/dist/telemetry-DGcFlVpB.d.cts.map +0 -1
  442. package/dist/telemetry-DGcFlVpB.d.mts.map +0 -1
  443. package/dist/topic/index.cjs.map +0 -1
  444. package/dist/topic/index.mjs.map +0 -1
@@ -1,22 +1,66 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_functions = require("../functions-B6qCvfmy.cjs");
3
- const require_Endpoint = require("../Endpoint-s0AyrQGC.cjs");
4
- const require_lazyAccessors = require("../lazyAccessors-Dx9NLwJZ.cjs");
5
- const require_HonoEndpointAdaptor = require("../HonoEndpointAdaptor-7QagYKdP.cjs");
6
- const require_processAudits = require("../processAudits-D_2W5x8k.cjs");
2
+ const require_rolldown_runtime = require("../rolldown-runtime-y5ARvAq5.cjs");
3
+ const require_construct_interface = require("../construct-interface.cjs");
4
+ const require_auth = require("../auth.cjs");
5
+ const require_functions = require("../functions-DLF6-IK8.cjs");
6
+ const require_Endpoint = require("../Endpoint-BcUorcBa.cjs");
7
+ const require_Queue = require("../Queue-D4Iaidrs.cjs");
8
+ const require_email = require("../email.cjs");
9
+ const require_kysely = require("../kysely-CukArHJ0.cjs");
10
+ const require_readRequestBody = require("../readRequestBody-Dej_L3c4.cjs");
11
+ const require_Topic = require("../Topic-Dp9Q7Lj2.cjs");
12
+ const require_HonoEndpointAdaptor = require("../HonoEndpointAdaptor-BJlj20fQ.cjs");
13
+ const require_requestLogger = require("../requestLogger-BZcXwdBs.cjs");
14
+ let _geekmidas_manifest = require("@geekmidas/manifest");
15
+ let node_crypto = require("node:crypto");
16
+ let _geekmidas_services = require("@geekmidas/services");
7
17
  let _geekmidas_errors = require("@geekmidas/errors");
8
18
  let _geekmidas_envkit = require("@geekmidas/envkit");
9
- let _geekmidas_services = require("@geekmidas/services");
10
19
  let hono = require("hono");
11
20
  let _geekmidas_audit = require("@geekmidas/audit");
21
+ let _geekmidas_testkit_context = require("@geekmidas/testkit/context");
12
22
  let msw = require("msw");
13
- //#region src/endpoints/MswEndpointAdaptor.ts
23
+ let _geekmidas_testkit_browser = require("@geekmidas/testkit/browser");
24
+ let _geekmidas_testkit_faker = require("@geekmidas/testkit/faker");
25
+ let _geekmidas_testkit_mailbox = require("@geekmidas/testkit/mailbox");
26
+ let _geekmidas_testkit_transactions = require("@geekmidas/testkit/transactions");
27
+ let msw_node = require("msw/node");
28
+ let vitest = require("vitest");
29
+ let node_fs = require("node:fs");
30
+ let node_tls = require("node:tls");
31
+ node_tls = require_rolldown_runtime.__toESM(node_tls, 1);
32
+ let node_url = require("node:url");
33
+ //#region src/testing/peer.ts
14
34
  /**
15
- * Header used to identify which test context a request belongs to.
16
- * Each concurrent test registers its own context (services, db transaction, etc.)
17
- * and the MSW handler looks it up by this header value.
35
+ * The TCP peer a test's in-process requests arrive from.
36
+ *
37
+ * A feature test hands a request straight to a surface's Hono app — no
38
+ * socket, no server — so the app's bindings have no peer to read. Deployed,
39
+ * every request has one, and what a surface trusts follows from it: the auth
40
+ * server honours `x-gkm-client-ip` only from an internal caller, a loopback
41
+ * or private peer with no `Origin` and no forwarding header. With no peer at
42
+ * all the header was dropped, and every test's session check became the same
43
+ * client to Better Auth's rate limiter.
44
+ *
45
+ * So an in-process dispatch says where it came from, the way
46
+ * `@hono/node-server` does: its bindings carry `incoming.socket.remoteAddress`.
47
+ * The address is loopback because that is the truth — the request came from
48
+ * this process. A browser's own address still travels in its
49
+ * `x-forwarded-for`, which makes it outside traffic exactly as it would be
50
+ * behind the stack's proxy.
51
+ *
52
+ * Only a test's dispatch passes these. A runtime with no socket of its own
53
+ * (Lambda, Bun) still has no peer, and a request with no peer is still not an
54
+ * internal caller's.
18
55
  */
19
- const TEST_CONTEXT_HEADER = "x-test-context-id";
56
+ /** The address an in-process request presents as its peer. */
57
+ const IN_PROCESS_PEER_ADDRESS = "127.0.0.1";
58
+ /** Bindings for `app.fetch(request, bindings)` from inside this process. */
59
+ function inProcessBindings() {
60
+ return { incoming: { socket: { remoteAddress: IN_PROCESS_PEER_ADDRESS } } };
61
+ }
62
+ //#endregion
63
+ //#region src/endpoints/MswEndpointAdaptor.ts
20
64
  const MSW_HTTP_METHODS = [
21
65
  "get",
22
66
  "post",
@@ -64,7 +108,6 @@ function createMswHandlers(endpoints, options) {
64
108
  break;
65
109
  }
66
110
  }
67
- if (ctxOptions.publisher) serviceDefs.push(ctxOptions.publisher);
68
111
  if (ctxOptions.auditorStorage !== void 0) {
69
112
  for (const endpoint of endpoints) if (endpoint.auditorStorageService) {
70
113
  serviceDefs.push({
@@ -84,18 +127,18 @@ function createMswHandlers(endpoints, options) {
84
127
  const mswUrl = `${baseURL}${endpoint.route}`;
85
128
  const mswMethod = msw.http[method];
86
129
  handlers.push(mswMethod(mswUrl, async ({ request }) => {
87
- const contextId = request.headers.get(TEST_CONTEXT_HEADER);
130
+ const contextId = request.headers.get(_geekmidas_testkit_context.TEST_CONTEXT_HEADER);
88
131
  const ctx = contextId ? contexts.get(contextId) : void 0;
89
132
  if (!ctx) return new Response(JSON.stringify({
90
133
  error: "Missing or unknown test context ID",
91
- hint: `Set the '${TEST_CONTEXT_HEADER}' header to a registered context ID`
134
+ hint: `Set the '${_geekmidas_testkit_context.TEST_CONTEXT_HEADER}' header to a registered context ID`
92
135
  }), {
93
136
  status: 500,
94
137
  headers: { "content-type": "application/json" }
95
138
  });
96
139
  const app = new hono.Hono();
97
140
  require_HonoEndpointAdaptor.HonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery, app);
98
- const response = await app.request(request);
141
+ const response = await app.request(request, void 0, inProcessBindings());
99
142
  return new Response(response.body, {
100
143
  status: response.status,
101
144
  statusText: response.statusText,
@@ -140,21 +183,21 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
140
183
  const body = await this.endpoint.parseInput(ctx.body, "body");
141
184
  const query = await this.endpoint.parseInput(ctx.query, "query");
142
185
  const params = await this.endpoint.parseInput(ctx.params, "params");
143
- const header = require_lazyAccessors.createObjectHeaders(ctx.headers);
144
- const cookie = require_lazyAccessors.createCookieHeaderAccessor(ctx.headers.cookie);
186
+ const header = require_readRequestBody.createObjectHeaders(ctx.headers);
187
+ const cookie = require_readRequestBody.createCookieHeaderAccessor(ctx.headers.cookie);
145
188
  const startTime = Date.now();
146
189
  const requestId = ctx.requestId ?? ctx.headers["x-request-id"] ?? crypto.randomUUID();
147
- const logger = this.endpoint.logger.child({
190
+ let logger = require_requestLogger.requestLogger(this.endpoint, {
148
191
  requestId,
149
- route: this.endpoint.route,
150
- host: ctx.headers.host,
151
- method: this.endpoint.method
192
+ host: ctx.headers.host
152
193
  });
153
194
  const rawDb = ctx.database;
195
+ const operation = `${this.endpoint.method} ${this.endpoint.route}`;
154
196
  return (0, _geekmidas_services.runWithRequestContext)({
155
197
  logger,
156
198
  requestId,
157
- startTime
199
+ startTime,
200
+ operation
158
201
  }, async () => {
159
202
  const session = await this.endpoint.getSession({
160
203
  logger,
@@ -163,6 +206,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
163
206
  cookie,
164
207
  ...rawDb !== void 0 && { db: rawDb }
165
208
  });
209
+ logger = (0, _geekmidas_services.currentRequestContext)()?.logger ?? logger;
166
210
  if (!await this.endpoint.authorize({
167
211
  header,
168
212
  cookie,
@@ -177,6 +221,14 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
177
221
  logger.warn("Forbidden access attempt");
178
222
  throw new _geekmidas_errors.ForbiddenError("Forbidden access to the endpoint", "You do not have permission to access this resource.");
179
223
  }
224
+ const rateLimitHeaders = this.endpoint.rateLimit ? await require_requestLogger.enforceRateLimit(this.endpoint.rateLimit, {
225
+ header,
226
+ services: ctx.services,
227
+ logger,
228
+ session,
229
+ path: this.endpoint.route,
230
+ method: this.endpoint.method
231
+ }) : {};
180
232
  const auditorStorage = ctx.auditorStorage;
181
233
  let auditContext;
182
234
  if (auditorStorage) {
@@ -209,7 +261,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
209
261
  }
210
262
  const audits = this.endpoint.audits;
211
263
  if (!auditContext && audits?.length) logger.warn("No auditor storage service available");
212
- const { output, metadata } = await require_processAudits.executeWithAuditTransaction(auditContext, async (auditor) => {
264
+ const { output, metadata, redirect } = await require_requestLogger.executeWithAuditTransaction(auditContext, async (auditor) => {
213
265
  const db = auditor?.getTransaction?.() ?? rawDb;
214
266
  const responseBuilder = new require_Endpoint.ResponseBuilder();
215
267
  const response = await this.endpoint.handler({
@@ -230,13 +282,15 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
230
282
  data = response.data;
231
283
  metadata = response.metadata;
232
284
  }
285
+ const redirect = require_Endpoint.Endpoint.isRedirectStatus(metadata.status ?? this.endpoint.status);
233
286
  return {
234
- output: await this.endpoint.parseOutput(data),
287
+ output: redirect ? void 0 : await this.endpoint.parseOutput(data),
235
288
  metadata,
236
- responseBuilder
289
+ responseBuilder,
290
+ redirect
237
291
  };
238
292
  }, async (result, auditor) => {
239
- if (!audits?.length) return;
293
+ if (!audits?.length || result.redirect) return;
240
294
  for (const audit of audits) {
241
295
  if (audit.when && !audit.when(result.output)) continue;
242
296
  const payload = audit.payload(result.output);
@@ -247,9 +301,11 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
247
301
  });
248
302
  }
249
303
  }, { db: rawDb });
250
- ctx.publisher && await this.serviceDiscovery.register([ctx.publisher]);
251
- await require_lazyAccessors.publishConstructEvents(this.endpoint, output, this.serviceDiscovery);
252
- const headers = { ...metadata.headers || {} };
304
+ if (!redirect) await require_functions.publishConstructEvents(this.endpoint, output, this.serviceDiscovery, this.endpoint.logger, ctx.services);
305
+ const headers = {
306
+ ...rateLimitHeaders,
307
+ ...metadata.headers || {}
308
+ };
253
309
  if (metadata.cookies && metadata.cookies.size > 0) {
254
310
  const setCookieValues = [];
255
311
  for (const [name, cookie] of metadata.cookies.entries()) setCookieValues.push(serializeCookie(name, cookie.value, cookie.options));
@@ -257,7 +313,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
257
313
  }
258
314
  return {
259
315
  body: output,
260
- status: metadata.status || 200,
316
+ status: metadata.status ?? this.endpoint.status,
261
317
  headers
262
318
  };
263
319
  });
@@ -324,7 +380,7 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
324
380
  await auditor.flush();
325
381
  }
326
382
  }
327
- await require_lazyAccessors.publishEvents(logger, this.serviceDiscovery, this.fn.events, output, this.fn.publisherService);
383
+ await require_functions.publishEvents(logger, this.serviceDiscovery, this.fn.events, output, services);
328
384
  return output;
329
385
  });
330
386
  }
@@ -334,7 +390,8 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
334
390
  /**
335
391
  * In-memory test driver for a {@link Queue} worker. Hand it a batch of messages
336
392
  * and it registers the queue's services, runs the handler in a request context,
337
- * and returns the handler result — no SQS/pg-boss required.
393
+ * and returns the handler result — no SQS/pg-boss required. A queue with a
394
+ * database gets `db` registered from it, or the one the request passes.
338
395
  *
339
396
  * @example
340
397
  * const adapter = new TestQueueAdaptor(ordersQueue);
@@ -353,17 +410,27 @@ var TestQueueAdaptor = class TestQueueAdaptor {
353
410
  async invoke(request) {
354
411
  const logger = this.queue.logger.child({ test: true });
355
412
  const services = request.services ?? await this.serviceDiscovery.register(this.queue.services);
413
+ const db = request.db !== void 0 ? request.db : await this.getDatabase();
356
414
  const requestId = `test-${Date.now()}`;
415
+ const startTime = Date.now();
416
+ const operation = `queue ${this.queue.name}`;
357
417
  return (0, _geekmidas_services.runWithRequestContext)({
358
418
  logger,
359
419
  requestId,
360
- startTime: Date.now()
420
+ startTime,
421
+ operation
361
422
  }, () => this.queue.handler({
362
423
  messages: request.messages,
363
424
  services,
364
- logger
425
+ logger,
426
+ db
365
427
  }));
366
428
  }
429
+ async getDatabase() {
430
+ const service = this.queue.databaseService;
431
+ if (!service) return void 0;
432
+ return (await this.serviceDiscovery.register([service]))[service.serviceName];
433
+ }
367
434
  };
368
435
  //#endregion
369
436
  //#region src/subscribers/TestSubscriberAdaptor.ts
@@ -382,18 +449,23 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
382
449
  let services;
383
450
  if (request.services) services = request.services;
384
451
  else services = await this.serviceDiscovery.register(this.subscriber.services);
452
+ const db = request.db !== void 0 ? request.db : await this.getDatabase();
385
453
  const filteredEvents = this.filterEvents(request.events);
386
454
  if (filteredEvents.length === 0) return { batchItemFailures: [] };
387
455
  const requestId = `test-${Date.now()}`;
456
+ const startTime = Date.now();
457
+ const operation = `subscriber ${this.subscriber.topicName ?? "test"}`;
388
458
  return (0, _geekmidas_services.runWithRequestContext)({
389
459
  logger,
390
460
  requestId,
391
- startTime: Date.now()
461
+ startTime,
462
+ operation
392
463
  }, async () => {
393
464
  const result = await this.subscriber.handler({
394
465
  events: filteredEvents,
395
466
  services,
396
- logger
467
+ logger,
468
+ db
397
469
  });
398
470
  let output = result;
399
471
  if (this.subscriber.outputSchema && result) {
@@ -401,21 +473,735 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
401
473
  if (validationResult.issues) throw new Error("Subscriber output validation failed");
402
474
  output = validationResult.value;
403
475
  }
404
- await require_lazyAccessors.publishEvents(logger, this.serviceDiscovery, this.subscriber.events, output, this.subscriber.publisherService);
405
476
  return output;
406
477
  });
407
478
  }
479
+ async getDatabase() {
480
+ const service = this.subscriber.databaseService;
481
+ if (!service) return void 0;
482
+ return (await this.serviceDiscovery.register([service]))[service.serviceName];
483
+ }
408
484
  filterEvents(events) {
409
485
  if (!this.subscriber.subscribedEvents) return events;
410
486
  return events.filter((event) => this.subscriber.subscribedEvents.includes(event.type));
411
487
  }
412
488
  };
413
489
  //#endregion
414
- exports.TEST_CONTEXT_HEADER = TEST_CONTEXT_HEADER;
490
+ //#region src/testing/manifest.ts
491
+ /**
492
+ * The test manifest: what `gkm test` knows about an app, written down for the
493
+ * suite it starts.
494
+ *
495
+ * `gkm test` discovers the constructs, reconciles the test stage and resolves
496
+ * its environment — then, until this existed, threw all of it away and left a
497
+ * test to declare it again by hand. The manifest keeps it: which construct and
498
+ * endpoint is exported where, and the environment the test stage resolved,
499
+ * under the keys the constructs themselves derive. A feature test is built from
500
+ * it, so nothing a test says can drift from what the app declares.
501
+ */
502
+ /** The environment variable `gkm test` names the manifest in. */
503
+ const TEST_MANIFEST_ENV = "GKM_TEST_MANIFEST";
504
+ /**
505
+ * Read a test manifest: from a path, a `file:` URL, or — given nothing — the
506
+ * one `gkm test` named in `GKM_TEST_MANIFEST`.
507
+ */
508
+ function loadTestManifest(from) {
509
+ const location = from ?? process.env["GKM_TEST_MANIFEST"];
510
+ if (!location) throw new NoTestManifest();
511
+ trustLocalEdge();
512
+ const path = location instanceof URL || location.startsWith("file:") ? (0, node_url.fileURLToPath)(location) : location;
513
+ return JSON.parse((0, node_fs.readFileSync)(path, "utf-8"));
514
+ }
515
+ let trusted = false;
516
+ /**
517
+ * Trust the local edge's certificate authority in this thread.
518
+ *
519
+ * `NODE_EXTRA_CA_CERTS` does it for a process started with it — which a
520
+ * suite started by `gkm test` is, and one started by plain `vitest` or an
521
+ * editor is not: its setup only learns the path once Vitest is running, and a
522
+ * worker *thread* shares that process and keeps a TLS store of its own. Every
523
+ * feature test loads the manifest, so this is the one place each worker passes
524
+ * through.
525
+ */
526
+ function trustLocalEdge() {
527
+ const certificate = process.env.NODE_EXTRA_CA_CERTS;
528
+ if (trusted || !certificate || !(0, node_fs.existsSync)(certificate)) return;
529
+ trusted = true;
530
+ node_tls.default.setDefaultCACertificates([...node_tls.default.getCACertificates("default"), (0, node_fs.readFileSync)(certificate, "utf-8")]);
531
+ }
532
+ /** A feature test ran without a manifest to build itself from. */
533
+ var NoTestManifest = class extends Error {
534
+ constructor() {
535
+ 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}.`);
536
+ this.name = "NoTestManifest";
537
+ }
538
+ };
539
+ //#endregion
540
+ //#region src/testing/featureTest.ts
541
+ /**
542
+ * `featureTest`: an app, driven the way it runs deployed.
543
+ *
544
+ * A browser signs in and calls the API; the API calls the auth server; each
545
+ * over its URL, each database in its own transaction. Nothing runs as a server:
546
+ * every URL an app's constructs answer on is served in-process through MSW,
547
+ * from the real handler, for the test that made the request. Everything else
548
+ * with a real local equivalent — Postgres, Mailpit, MinIO — is used directly.
549
+ *
550
+ * It is built from the test manifest `gkm test` writes — the constructs and
551
+ * endpoints the app exports, and the environment the test stage resolved — so
552
+ * a test declares none of it. `gkm test` also generates the configured `it`
553
+ * and a `Browser` with a typed client per surface:
554
+ *
555
+ * ```ts
556
+ * import { it } from '#test';
557
+ *
558
+ * it('shows the signed-in user their profile', async ({ browser, mailbox }) => {
559
+ * await browser.auth.signIn.magicLink({ email: 'ada@shop.test' });
560
+ * await browser.visit((await mailbox('ada@shop.test').last()).link!);
561
+ * expect(await browser.api.get('/profile')).toMatchObject({ email: 'ada@shop.test' });
562
+ * });
563
+ * ```
564
+ */
565
+ /** Every test in flight in this process, by id. */
566
+ const contexts = /* @__PURE__ */ new Map();
567
+ /** Databases already resolving to test transactions — patched once each. */
568
+ const bound = /* @__PURE__ */ new WeakSet();
569
+ function featureTest(options = {}) {
570
+ const manifest = options.manifest ?? loadTestManifest();
571
+ const BrowserClass = options.browser ?? _geekmidas_testkit_browser.Browser;
572
+ let app;
573
+ let factoryDatabases = [];
574
+ let owned = [];
575
+ let network;
576
+ let restoreFetch = () => {};
577
+ (0, vitest.beforeAll)(async () => {
578
+ app = await load(manifest, options.modules ?? {});
579
+ owned = ownDatabases(app, manifest);
580
+ factoryDatabases = databasesFor(options.factories ?? {}, owned);
581
+ for (const database of app.databases) bindToTests(database);
582
+ network = (0, msw_node.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)));
583
+ network.listen({ onUnhandledRequest(request, print) {
584
+ if (isLocal(new URL(request.url))) return;
585
+ print.error();
586
+ } });
587
+ const restoreStamp = (0, _geekmidas_testkit_context.installContextFetch)();
588
+ const stamped = globalThis.fetch;
589
+ globalThis.fetch = deliveringFetch(stamped, (id) => {
590
+ const state = contexts.get(id);
591
+ return state ? deliver(app, state, id) : Promise.resolve();
592
+ });
593
+ restoreFetch = () => {
594
+ globalThis.fetch = stamped;
595
+ restoreStamp();
596
+ };
597
+ });
598
+ (0, vitest.afterAll)(() => {
599
+ restoreFetch();
600
+ network?.close();
601
+ });
602
+ const run = (name, fn) => async () => {
603
+ const id = (0, node_crypto.randomUUID)();
604
+ _geekmidas_testkit_faker.faker.seed(seedOf(name));
605
+ const state = {
606
+ transactions: new _geekmidas_testkit_transactions.TransactionRegistry(),
607
+ discovery: new _geekmidas_services.ServiceDiscovery(app.envParser),
608
+ surfaces: /* @__PURE__ */ new Map(),
609
+ auth: /* @__PURE__ */ new Map(),
610
+ addresses: /* @__PURE__ */ new Set(),
611
+ published: /* @__PURE__ */ new Map(),
612
+ pending: [],
613
+ delivering: false
614
+ };
615
+ const readMail = app.readMail;
616
+ if (readMail) state.mailbox = (address) => {
617
+ state.addresses.add(address);
618
+ return readMail(address);
619
+ };
620
+ contexts.set(id, state);
621
+ await state.discovery.register(recorders(app.channels, state));
622
+ await state.discovery.register(watchers(app, state));
623
+ try {
624
+ await (0, _geekmidas_testkit_context.runInTestContext)(id, async () => {
625
+ const browser = new BrowserClass();
626
+ const restore = browser.install();
627
+ try {
628
+ const transaction = (database) => state.transactions.get(database.id, urlOf(database, app.envParser), database.clientConfig);
629
+ const db = { get: (name) => {
630
+ const database = owned.find((candidate) => candidate.service.serviceName === name);
631
+ if (!database) throw new UnknownDatabase(name, owned.map((candidate) => candidate.service.serviceName));
632
+ return transaction(database);
633
+ } };
634
+ const built = /* @__PURE__ */ new Map();
635
+ await fn({
636
+ browser,
637
+ db,
638
+ factories: { get: (name) => {
639
+ const database = factoryDatabases.find(([candidate]) => candidate === name)?.[1];
640
+ if (!database) throw new UnknownFactory(name, factoryDatabases.map(([candidate]) => candidate));
641
+ let factory = built.get(name);
642
+ if (!factory) {
643
+ factory = transaction(database).then(options.factories[name]);
644
+ built.set(name, factory);
645
+ }
646
+ return factory;
647
+ } },
648
+ faker: _geekmidas_testkit_faker.faker,
649
+ mailbox: (address) => {
650
+ if (!state.mailbox) throw new NoInbox();
651
+ return state.mailbox(address);
652
+ },
653
+ published: (channel) => [...state.published.get(channel.id) ?? []],
654
+ services: { get: (name) => resolveService(app, state, name) },
655
+ subscriber: (subscriber) => thenDeliver(new TestSubscriberAdaptor(subscriber, state.discovery), () => deliver(app, state, id)),
656
+ queue: (queue) => thenDeliver(new TestQueueAdaptor(queue, state.discovery), () => deliver(app, state, id)),
657
+ objects: (bucket) => ({ emit: async (...events) => {
658
+ const watched = app.watched.find((candidate) => candidate.id === bucket.id);
659
+ if (!watched) throw new BucketNotWatched(bucket.id);
660
+ const name = bucketName(watched, app.envParser);
661
+ state.pending.push({
662
+ channel: watched,
663
+ messages: events.map(({ type, ...object }) => ({
664
+ type,
665
+ payload: {
666
+ bucket: name,
667
+ ...object
668
+ }
669
+ }))
670
+ });
671
+ await deliver(app, state, id);
672
+ } })
673
+ });
674
+ } finally {
675
+ restore();
676
+ }
677
+ });
678
+ } finally {
679
+ contexts.delete(id);
680
+ await Promise.all([state.transactions.rollbackAll(), ...[...state.addresses].map((address) => app.readMail?.(address).clear())]);
681
+ }
682
+ };
683
+ const it = ((name, fn, timeout) => (0, vitest.test)(name, run(name, fn), timeout));
684
+ it.only = (name, fn, timeout) => vitest.test.only(name, run(name, fn), timeout);
685
+ it.skip = (name, fn, timeout) => vitest.test.skip(name, run(name, fn), timeout);
686
+ return it;
687
+ }
688
+ /**
689
+ * A test's faker seed, from its name: the same test draws the same data on
690
+ * every run, and two tests draw different data.
691
+ */
692
+ function seedOf(name) {
693
+ let hash = 0;
694
+ for (const char of name) hash = Math.imul(hash, 31) + char.charCodeAt(0) | 0;
695
+ return hash >>> 0;
696
+ }
697
+ /**
698
+ * Import what the manifest points at.
699
+ *
700
+ * The same modules the app runs, so a construct here *is* the app's construct —
701
+ * the one its endpoints were built from — never a copy declared again.
702
+ */
703
+ async function load(manifest, modules) {
704
+ const envParser = new _geekmidas_envkit.EnvironmentParser({ ...manifest.env });
705
+ const imported = async ({ file, export: name }) => (modules[file] ?? await import(file))[name];
706
+ const constructs = await Promise.all(Object.values(manifest.constructs).map(({ source }) => imported(source)));
707
+ const endpoints = (await Promise.all(manifest.endpoints.map(({ source }) => imported(source)))).filter((value) => require_Endpoint.Endpoint.isEndpoint(value));
708
+ const subscribers = (await Promise.all((manifest.subscribers ?? []).map(async ({ source }) => ({
709
+ name: source.export,
710
+ subscriber: await imported(source)
711
+ })))).filter((entry) => entry.subscriber?.__IS_SUBSCRIBER__ === true);
712
+ const unique = (values) => [...new Set(values)];
713
+ const databases = unique(constructs.filter((value) => value instanceof require_kysely.KyselyDatabase));
714
+ const auths = unique(constructs.filter((value) => value instanceof require_auth.BetterAuth));
715
+ const emails = unique(constructs.filter((value) => value instanceof require_email.Email));
716
+ const consumables = unique(constructs.filter(require_construct_interface.isConsumable));
717
+ const channels = unique(constructs.filter((value) => value instanceof require_Topic.Topic || value instanceof require_Queue.Queue));
718
+ const watched = unique(constructs.filter((value) => isBucket(value) && subscribers.some(({ subscriber }) => subscriber.bucketName === value.id)));
719
+ const inbox = emails.map((email) => manifest.env[(0, _geekmidas_manifest.provideKey)(email.id, "inboxUrl")]).find(Boolean);
720
+ return {
721
+ envParser,
722
+ endpoints,
723
+ databases,
724
+ auths,
725
+ emails,
726
+ channels,
727
+ watched,
728
+ consumables,
729
+ subscribers,
730
+ ...inbox ? { readMail: (0, _geekmidas_testkit_mailbox.createMailbox)({ inbox }) } : {}
731
+ };
732
+ }
733
+ /**
734
+ * A publisher that records rather than sends, under the name a topic or queue
735
+ * is injected by — `services.users` — which is also the one `.event(users, …)`
736
+ * publishes through.
737
+ */
738
+ function recorders(channels, state) {
739
+ return channels.map((channel) => {
740
+ const publisher = { async publish(messages) {
741
+ const sent = messages.map(({ type, payload }) => ({
742
+ type,
743
+ payload
744
+ }));
745
+ state.published.set(channel.id, [...state.published.get(channel.id) ?? [], ...sent]);
746
+ state.pending.push({
747
+ channel,
748
+ messages: sent
749
+ });
750
+ } };
751
+ return {
752
+ serviceName: channel.service.serviceName,
753
+ register: () => publisher
754
+ };
755
+ });
756
+ }
757
+ /**
758
+ * The databases a test is handed: the app's own. A schema tenant an auth server
759
+ * owns is reached through that server, as the app reaches it, and a reader is
760
+ * the same database through a read-only role — neither is another database to
761
+ * test against.
762
+ */
763
+ function ownDatabases(app, manifest) {
764
+ const owners = new Set(app.auths.map((auth) => auth.databaseId));
765
+ return app.databases.filter((database) => !owners.has(database.id) && manifest.constructs[database.id]?.kind !== "database-reader");
766
+ }
767
+ /** Each factory's database, found by the service name it is keyed by. */
768
+ function databasesFor(factories, databases) {
769
+ return Object.keys(factories).map((name) => {
770
+ const database = databases.find((candidate) => candidate.service.serviceName === name);
771
+ if (!database) throw new UnknownFactory(name, databases.map((candidate) => candidate.service.serviceName));
772
+ return [name, database];
773
+ });
774
+ }
775
+ /**
776
+ * Make a database resolve, inside a test, to that test's transaction.
777
+ *
778
+ * Everything reaches a database through its service — an endpoint through
779
+ * service discovery, the auth server through its tenant directly — so this is
780
+ * the one place a test's connection can be handed over. Outside a test it is
781
+ * the database it always was.
782
+ */
783
+ /** Rounds of delivery before a chain of consumers is called a loop. */
784
+ const MAX_DELIVERY_ROUNDS = 25;
785
+ /**
786
+ * Deliver what this test published, in-process, as the broker would — and
787
+ * keep delivering what the consumers publish in turn, until nothing is left.
788
+ *
789
+ * - A queue's messages go to its one consumer, as a batch.
790
+ * - A topic's events go to every subscriber that named their type, and only
791
+ * those: fan-out, as the filter policy (SNS) or the per-subscriber queue
792
+ * (pg-boss) does it.
793
+ * - Each payload is checked against the consumer's schema first. Turning an
794
+ * SNS envelope or an SQS record into `{ type, payload }` is each adaptor's
795
+ * job and tested there; what is tested here is what the handler is handed.
796
+ * - Consumers run as the server side of this test, so their databases are
797
+ * this test's transactions and their writes roll back with it.
798
+ * - A consumer that throws fails the test. Deployed, the message would be
799
+ * retried; here a retry would only hide the bug.
800
+ */
801
+ async function deliver(app, state, id) {
802
+ if (state.delivering) return;
803
+ state.delivering = true;
804
+ try {
805
+ for (let round = 0; state.pending.length > 0; round++) {
806
+ if (round === MAX_DELIVERY_ROUNDS) throw new DeliveryDidNotSettle(MAX_DELIVERY_ROUNDS, [...new Set(state.pending.map(({ channel }) => channel.id))]);
807
+ for (const { channel, messages } of state.pending.splice(0)) if (channel instanceof require_Queue.Queue) await toQueue(channel, messages, state, id);
808
+ else if (channel instanceof require_Topic.Topic) await toSubscribers(channel, messages, app, state, id);
809
+ else await toObjectSubscribers(channel, messages, app, state, id);
810
+ }
811
+ } finally {
812
+ state.delivering = false;
813
+ }
814
+ }
815
+ async function toQueue(queue, messages, state, id) {
816
+ const payloads = [];
817
+ for (const message of messages) payloads.push(await accepted(queue.messageSchema, message, `queue '${queue.name}'`));
818
+ await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestQueueAdaptor(queue, state.discovery).invoke({ messages: payloads })).catch((error) => {
819
+ throw new DeliveryFailed(`queue '${queue.name}'`, messages, error);
820
+ });
821
+ }
822
+ async function toSubscribers(topic, messages, app, state, id) {
823
+ for (const { name, subscriber } of app.subscribers) {
824
+ if (subscriber.topicName !== topic.name) continue;
825
+ const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
826
+ if (named.length === 0) continue;
827
+ const consumer = `subscriber '${name}'`;
828
+ const events = [];
829
+ for (const message of named) {
830
+ const schema = topic.eventSchemas[message.type];
831
+ events.push({
832
+ type: message.type,
833
+ payload: await accepted(schema, message, consumer)
834
+ });
835
+ }
836
+ await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events })).catch((error) => {
837
+ throw new DeliveryFailed(consumer, named, error);
838
+ });
839
+ }
840
+ }
841
+ /**
842
+ * A bucket's changes to each subscriber bound to it that named their type —
843
+ * the subscriber keeps the keys it watches, as it does deployed.
844
+ */
845
+ async function toObjectSubscribers(bucket, messages, app, state, id) {
846
+ for (const { name, subscriber } of app.subscribers) {
847
+ if (subscriber.bucketName !== bucket.id) continue;
848
+ const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
849
+ if (named.length === 0) continue;
850
+ const consumer = `subscriber '${name}'`;
851
+ await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events: named })).catch((error) => {
852
+ throw new DeliveryFailed(consumer, named, error);
853
+ });
854
+ }
855
+ }
856
+ /**
857
+ * A client for each watched bucket that reports what it writes: the real
858
+ * client — the test's MinIO — under the name the bucket is injected by, so
859
+ * an upload a handler makes reaches the bucket's subscribers as the storage
860
+ * would report it.
861
+ */
862
+ function watchers(app, state) {
863
+ return app.watched.map((bucket) => ({
864
+ serviceName: bucket.service.serviceName,
865
+ register: async (options) => {
866
+ const client = await bucket.service.register(options);
867
+ const name = bucketName(bucket, app.envParser);
868
+ const report = async (message) => {
869
+ state.pending.push({
870
+ channel: bucket,
871
+ messages: [message]
872
+ });
873
+ const context = (0, _geekmidas_testkit_context.currentTestContext)();
874
+ if (context?.side === "client") await deliver(app, state, context.id);
875
+ };
876
+ const watching = Object.create(client);
877
+ watching.upload = async (key, data, contentType) => {
878
+ await client.upload(key, data, contentType);
879
+ await report({
880
+ type: "object.created",
881
+ payload: {
882
+ bucket: name,
883
+ key,
884
+ size: byteLength(data)
885
+ }
886
+ });
887
+ };
888
+ watching.delete = async (key) => {
889
+ await client.delete(key);
890
+ await report({
891
+ type: "object.deleted",
892
+ payload: {
893
+ bucket: name,
894
+ key
895
+ }
896
+ });
897
+ };
898
+ return watching;
899
+ }
900
+ }));
901
+ }
902
+ /** The bucket's name as the storage knows it — the host of its URL. */
903
+ function bucketName(bucket, envParser) {
904
+ const { url } = envParser.create((get) => ({ url: get((0, _geekmidas_manifest.provideKey)(bucket.id, "url")).string() })).parse();
905
+ try {
906
+ return new URL(url).hostname || bucket.id;
907
+ } catch {
908
+ return bucket.id;
909
+ }
910
+ }
911
+ function byteLength(data) {
912
+ return typeof data === "string" ? Buffer.byteLength(data) : data.length;
913
+ }
914
+ /** An `ObjectStorage`, recognised by what it declares — never by importing it. */
915
+ function isBucket(value) {
916
+ const declare = value?.declare;
917
+ return typeof declare === "function" && declare.call(value)[0]?.kind === "objects";
918
+ }
919
+ /** `objects(bucket)` named a bucket no subscriber in the app is bound to. */
920
+ var BucketNotWatched = class extends Error {
921
+ bucket;
922
+ constructor(bucket) {
923
+ super(`No subscriber is bound to '${bucket}', so nothing receives what is emitted on it. Bind one — worker.objects(${bucket.charAt(0).toLowerCase()}${bucket.slice(1)}) — or check the test manifest lists it.`);
924
+ this.bucket = bucket;
925
+ this.name = "BucketNotWatched";
926
+ }
927
+ };
928
+ /** The payload, if the consumer's schema takes it — what the handler is handed. */
929
+ async function accepted(schema, message, consumer) {
930
+ const standard = schema?.["~standard"];
931
+ if (!standard) return message.payload;
932
+ const result = await standard.validate(message.payload);
933
+ if (result.issues) throw new MessageRejected(consumer, message, result.issues);
934
+ return result.value;
935
+ }
936
+ /** `fetch`, delivering what the test published once each of its requests answers. */
937
+ function deliveringFetch(inner, settle) {
938
+ return async (input, init) => {
939
+ const context = (0, _geekmidas_testkit_context.currentTestContext)();
940
+ const response = await inner(input, init);
941
+ if (context?.side === "client") await settle(context.id);
942
+ return response;
943
+ };
944
+ }
945
+ /** An adaptor whose `invoke` delivers what it published before returning. */
946
+ function thenDeliver(adaptor, settle) {
947
+ const invoke = adaptor.invoke.bind(adaptor);
948
+ adaptor.invoke = (async (...args) => {
949
+ const result = await invoke(...args);
950
+ await settle();
951
+ return result;
952
+ });
953
+ return adaptor;
954
+ }
955
+ function bindToTests(database) {
956
+ if (bound.has(database)) return;
957
+ bound.add(database);
958
+ const service = database.service;
959
+ const register = service.register;
960
+ service.register = (options) => {
961
+ const context = (0, _geekmidas_testkit_context.currentTestContext)();
962
+ const state = context && contexts.get(context.id);
963
+ if (!state) return register(options);
964
+ return state.transactions.get(database.id, urlOf(database, options.envParser), database.clientConfig);
965
+ };
966
+ }
967
+ function urlOf(database, envParser) {
968
+ return envParser.create((get) => ({ url: get((0, _geekmidas_manifest.provideKey)(database.id, "url")).string() })).parse().url;
969
+ }
970
+ /** Each surface's endpoints, served at its URL for the test that asked. */
971
+ function surfaceHandlers(endpoints, env) {
972
+ const bySurface = /* @__PURE__ */ new Map();
973
+ for (const endpoint of endpoints) {
974
+ const surface = endpoint.surface?.id;
975
+ if (!surface) continue;
976
+ bySurface.set(surface, [...bySurface.get(surface) ?? [], endpoint]);
977
+ }
978
+ return [...bySurface].flatMap(([surface, served]) => {
979
+ const base = env[(0, _geekmidas_manifest.provideKey)(surface, "url")];
980
+ if (!base) return [];
981
+ return msw.http.all(`${trim(base)}/*`, ({ request }) => serve(request, async (state) => {
982
+ let app = state.surfaces.get(surface);
983
+ if (!app) {
984
+ app = Promise.resolve().then(() => {
985
+ const hono$1 = new hono.Hono();
986
+ require_HonoEndpointAdaptor.HonoEndpoint.addRoutes(served, state.discovery, hono$1);
987
+ return hono$1;
988
+ });
989
+ state.surfaces.set(surface, app);
990
+ }
991
+ return (await app).fetch(request, inProcessBindings());
992
+ }));
993
+ });
994
+ }
995
+ /**
996
+ * An external API's app fake, answering at the URL the test stage resolved for
997
+ * it — so a handler that calls Polar calls the fake, and the test sets up
998
+ * nothing.
999
+ *
1000
+ * Not per test, unlike a surface: a fake stands in for somebody else's server,
1001
+ * which no test's transaction reaches. An image fake has no handler here — its
1002
+ * container answers on localhost, which is let through.
1003
+ */
1004
+ function fakeHandler(id, fake, env) {
1005
+ const base = env[(0, _geekmidas_manifest.provideKey)(id, "url")];
1006
+ if (fake.kind !== "app" || !base) return [];
1007
+ return [msw.http.all(`${trim(base)}/*`, ({ request }) => fake.handler.fetch(request))];
1008
+ }
1009
+ /**
1010
+ * A construct's client for this test, by service name — through the test's own
1011
+ * discovery, so a topic or queue is its recorder and a database its
1012
+ * transaction, exactly as the test's endpoints get them.
1013
+ */
1014
+ async function resolveService(app, state, name) {
1015
+ const construct = app.consumables.find((candidate) => candidate.service.serviceName === name);
1016
+ if (!construct) throw new UnknownService(name, app.consumables.map((candidate) => candidate.service.serviceName));
1017
+ return (await state.discovery.register([construct.service]))[name];
1018
+ }
1019
+ /** An auth server, served at its URL, on the transaction of the test that asked. */
1020
+ function authHandler(auth, env, envParser) {
1021
+ const base = trim(env[(0, _geekmidas_manifest.provideKey)(auth.id, "url")] ?? "");
1022
+ return msw.http.all(`${base}/*`, ({ request }) => serve(request, async (state) => {
1023
+ let app = state.auth.get(auth);
1024
+ if (!app) {
1025
+ app = auth.server({
1026
+ envParser,
1027
+ context: _geekmidas_services.serviceContext
1028
+ }).then(({ app }) => app);
1029
+ state.auth.set(auth, app);
1030
+ }
1031
+ return (await app).fetch(request, inProcessBindings());
1032
+ }));
1033
+ }
1034
+ /** Handle a request as the server side of the test it was made for. */
1035
+ async function serve(request, handle) {
1036
+ const id = (0, _geekmidas_testkit_context.testContextOf)(request);
1037
+ const state = id ? contexts.get(id) : void 0;
1038
+ if (!id || !state) throw new UnknownTestContext(request.url, id);
1039
+ return (0, _geekmidas_testkit_context.runAsServer)(id, () => handle(state));
1040
+ }
1041
+ function trim(url) {
1042
+ return url.replace(/\/$/, "");
1043
+ }
1044
+ function isLocal(url) {
1045
+ return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname.endsWith(".localhost");
1046
+ }
1047
+ /**
1048
+ * Sign a test's browser in the way a person does: ask the auth server for a
1049
+ * magic link, open the email it sent, follow the link.
1050
+ *
1051
+ * What the generated `browser.signIn(email)` calls. The address's mail is
1052
+ * cleared first — so the link is this request's, not one an earlier test left
1053
+ * — and cleared again after the test, like any address a test reads. Returns
1054
+ * the session the auth server then reports, as better-auth hands it back.
1055
+ */
1056
+ async function signInWithMagicLink(browser, auth, email = freshAddress()) {
1057
+ const context = (0, _geekmidas_testkit_context.currentTestContext)();
1058
+ const state = context && contexts.get(context.id);
1059
+ if (!state) throw new UnknownTestContext("signIn", context?.id);
1060
+ if (!state.mailbox) throw new NoInbox();
1061
+ const inbox = state.mailbox(email);
1062
+ await inbox.clear();
1063
+ const requested = await auth.signIn.magicLink({ email });
1064
+ if (requested.error) throw new SignInFailed(email, `the auth server refused the magic link: ${requested.error.message ?? "no reason given"}`);
1065
+ const mail = await inbox.last();
1066
+ if (!mail.link) throw new SignInFailed(email, "its email held no link");
1067
+ await browser.visit(mail.link);
1068
+ const { data } = await auth.getSession();
1069
+ if (!data) throw new SignInFailed(email, "the auth server reported no session after the link was opened");
1070
+ return data;
1071
+ }
1072
+ /**
1073
+ * An address nobody else signs in as — what `browser.signIn()` uses when the
1074
+ * test does not care who it is.
1075
+ *
1076
+ * Unique rather than only seeded: tests in other files run at the same time,
1077
+ * against the same Mailpit and the same unique columns, and a seeded address
1078
+ * repeats wherever two tests share a name. The readable half is the seeded
1079
+ * faker's, so a failure still names somebody.
1080
+ */
1081
+ function freshAddress() {
1082
+ return `${_geekmidas_testkit_faker.faker.internet.username().toLowerCase().replace(/[^a-z0-9]/g, "")}.${(0, node_crypto.randomUUID)().slice(0, 8)}@example.test`;
1083
+ }
1084
+ /** `browser.signIn` finished without a session. */
1085
+ var SignInFailed = class extends Error {
1086
+ email;
1087
+ reason;
1088
+ constructor(email, reason) {
1089
+ super(`Signing ${email} in failed: ${reason}.`);
1090
+ this.email = email;
1091
+ this.reason = reason;
1092
+ this.name = "SignInFailed";
1093
+ }
1094
+ };
1095
+ /** A request reached an in-process server without a test to belong to. */
1096
+ var UnknownTestContext = class extends Error {
1097
+ url;
1098
+ id;
1099
+ constructor(url, id) {
1100
+ 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.`);
1101
+ this.url = url;
1102
+ this.id = id;
1103
+ this.name = "UnknownTestContext";
1104
+ }
1105
+ };
1106
+ /** `mailbox` was used in an app that declares no Email construct. */
1107
+ var NoInbox = class extends Error {
1108
+ constructor() {
1109
+ 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.");
1110
+ this.name = "NoInbox";
1111
+ }
1112
+ };
1113
+ /** `db.get(name)` named no database the test is handed. */
1114
+ var UnknownDatabase = class extends Error {
1115
+ database;
1116
+ known;
1117
+ constructor(database, known) {
1118
+ 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.");
1119
+ this.database = database;
1120
+ this.known = known;
1121
+ this.name = "UnknownDatabase";
1122
+ }
1123
+ };
1124
+ /** A factory keyed by a service name no database the app declares has. */
1125
+ var UnknownFactory = class extends Error {
1126
+ factory;
1127
+ known;
1128
+ constructor(factory, known) {
1129
+ 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.`);
1130
+ this.factory = factory;
1131
+ this.known = known;
1132
+ this.name = "UnknownFactory";
1133
+ }
1134
+ };
1135
+ /** A published message the consumer's own schema refuses. */
1136
+ var MessageRejected = class extends Error {
1137
+ consumer;
1138
+ published;
1139
+ issues;
1140
+ constructor(consumer, published, issues) {
1141
+ 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.`);
1142
+ this.consumer = consumer;
1143
+ this.published = published;
1144
+ this.issues = issues;
1145
+ this.name = "MessageRejected";
1146
+ }
1147
+ };
1148
+ /** A consumer that threw while handling what the test published. */
1149
+ var DeliveryFailed = class extends Error {
1150
+ consumer;
1151
+ messages;
1152
+ cause;
1153
+ constructor(consumer, messages, cause) {
1154
+ 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 });
1155
+ this.consumer = consumer;
1156
+ this.messages = messages;
1157
+ this.cause = cause;
1158
+ this.name = "DeliveryFailed";
1159
+ }
1160
+ };
1161
+ /** Consumers that kept publishing to each other without settling. */
1162
+ var DeliveryDidNotSettle = class extends Error {
1163
+ rounds;
1164
+ channels;
1165
+ constructor(rounds, channels) {
1166
+ 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.`);
1167
+ this.rounds = rounds;
1168
+ this.channels = channels;
1169
+ this.name = "DeliveryDidNotSettle";
1170
+ }
1171
+ };
1172
+ /** `services.get(name)` for a name no construct of the app is served by. */
1173
+ var UnknownService = class extends Error {
1174
+ serviceName;
1175
+ available;
1176
+ constructor(serviceName, available) {
1177
+ super(`The app declares no construct served as '${serviceName}'. Its services are: ${available.join(", ") || "none"}.`);
1178
+ this.serviceName = serviceName;
1179
+ this.available = available;
1180
+ this.name = "UnknownService";
1181
+ }
1182
+ };
1183
+ //#endregion
1184
+ exports.DeliveryDidNotSettle = DeliveryDidNotSettle;
1185
+ exports.DeliveryFailed = DeliveryFailed;
1186
+ exports.IN_PROCESS_PEER_ADDRESS = IN_PROCESS_PEER_ADDRESS;
1187
+ exports.MessageRejected = MessageRejected;
1188
+ exports.NoInbox = NoInbox;
1189
+ exports.NoTestManifest = NoTestManifest;
1190
+ exports.SignInFailed = SignInFailed;
1191
+ exports.TEST_CONTEXT_HEADER = _geekmidas_testkit_context.TEST_CONTEXT_HEADER;
1192
+ exports.TEST_MANIFEST_ENV = TEST_MANIFEST_ENV;
415
1193
  exports.TestEndpointAdaptor = TestEndpointAdaptor;
416
1194
  exports.TestFunctionAdaptor = TestFunctionAdaptor;
417
1195
  exports.TestQueueAdaptor = TestQueueAdaptor;
418
1196
  exports.TestSubscriberAdaptor = TestSubscriberAdaptor;
1197
+ exports.UnknownDatabase = UnknownDatabase;
1198
+ exports.UnknownFactory = UnknownFactory;
1199
+ exports.UnknownService = UnknownService;
1200
+ exports.UnknownTestContext = UnknownTestContext;
419
1201
  exports.createMswHandlers = createMswHandlers;
1202
+ exports.featureTest = featureTest;
1203
+ exports.inProcessBindings = inProcessBindings;
1204
+ exports.loadTestManifest = loadTestManifest;
1205
+ exports.signInWithMagicLink = signInWithMagicLink;
420
1206
 
421
1207
  //# sourceMappingURL=testing.cjs.map