@geekmidas/constructs 10.0.0-alpha.5 → 10.0.0-alpha.51
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.
- package/README.md +223 -158
- package/dist/{Construct-BD5neF7w.mjs → Construct-BO1X-kt9.mjs} +32 -33
- package/dist/Construct-BO1X-kt9.mjs.map +1 -0
- package/dist/Construct-BQALFCh2.d.cts +230 -0
- package/dist/Construct-BQALFCh2.d.cts.map +1 -0
- package/dist/{Construct-CyS3RpTL.cjs → Construct-DmvXceVY.cjs} +52 -47
- package/dist/Construct-DmvXceVY.cjs.map +1 -0
- package/dist/Construct-QXnl3VqT.d.mts +230 -0
- package/dist/Construct-QXnl3VqT.d.mts.map +1 -0
- package/dist/{Cron-B2OFsfDM.d.cts → Cron-DI3nKoic.d.cts} +22 -8
- package/dist/Cron-DI3nKoic.d.cts.map +1 -0
- package/dist/{Cron-CqEbBbwH.d.mts → Cron-uYAHPnp7.d.mts} +22 -8
- package/dist/Cron-uYAHPnp7.d.mts.map +1 -0
- package/dist/CronBuilder-BoHzlWU_.cjs +121 -0
- package/dist/CronBuilder-BoHzlWU_.cjs.map +1 -0
- package/dist/CronBuilder-CCgt0wCE.mjs +109 -0
- package/dist/CronBuilder-CCgt0wCE.mjs.map +1 -0
- package/dist/CronBuilder-DaSUm2Na.d.mts +47 -0
- package/dist/CronBuilder-DaSUm2Na.d.mts.map +1 -0
- package/dist/CronBuilder-g1lZLWyG.d.cts +47 -0
- package/dist/CronBuilder-g1lZLWyG.d.cts.map +1 -0
- package/dist/{Endpoint-Dem2XyCu.d.mts → Endpoint-Bm9HjTPc.d.cts} +70 -93
- package/dist/Endpoint-Bm9HjTPc.d.cts.map +1 -0
- package/dist/{Endpoint-Dij_wOcc.mjs → Endpoint-CQ9RJ7p2.mjs} +130 -109
- package/dist/Endpoint-CQ9RJ7p2.mjs.map +1 -0
- package/dist/{Endpoint-DrD8a1yH.d.cts → Endpoint-CwM8Rzfs.d.mts} +71 -94
- package/dist/Endpoint-CwM8Rzfs.d.mts.map +1 -0
- package/dist/{Endpoint-DODn1RhN.cjs → Endpoint-DOi8c_Gy.cjs} +158 -131
- package/dist/Endpoint-DOi8c_Gy.cjs.map +1 -0
- package/dist/{index-B8g8POkr.d.cts → EndpointFactory-0plFjvb7.d.mts} +64 -134
- package/dist/EndpointFactory-0plFjvb7.d.mts.map +1 -0
- package/dist/{index-DbKmfl-q.d.mts → EndpointFactory-B6eZ3RDd.d.cts} +64 -134
- package/dist/EndpointFactory-B6eZ3RDd.d.cts.map +1 -0
- package/dist/{EndpointFactory-BHFMmFkV.cjs → EndpointFactory-Bo9lkMqB.cjs} +75 -110
- package/dist/EndpointFactory-Bo9lkMqB.cjs.map +1 -0
- package/dist/{EndpointFactory-b4ituq-s.mjs → EndpointFactory-DR1rebok.mjs} +39 -74
- package/dist/EndpointFactory-DR1rebok.mjs.map +1 -0
- package/dist/Function-DuqGcbOI.d.mts +76 -0
- package/dist/Function-DuqGcbOI.d.mts.map +1 -0
- package/dist/Function-Pu-1kKZz.d.cts +76 -0
- package/dist/Function-Pu-1kKZz.d.cts.map +1 -0
- package/dist/{HonoEndpointAdaptor-BM2jbWht.mjs → HonoEndpointAdaptor-BIS0O3M9.mjs} +41 -47
- package/dist/HonoEndpointAdaptor-BIS0O3M9.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-De6IlBZe.cjs → HonoEndpointAdaptor-CMi0MJsF.cjs} +50 -53
- package/dist/HonoEndpointAdaptor-CMi0MJsF.cjs.map +1 -0
- package/dist/Queue-D5jcw0mu.cjs +109 -0
- package/dist/Queue-D5jcw0mu.cjs.map +1 -0
- package/dist/{Queue-D7ZuwBhy.d.cts → Queue-DlsHRzUp.d.mts} +48 -48
- package/dist/Queue-DlsHRzUp.d.mts.map +1 -0
- package/dist/{Queue-gVGfi2Yk.d.mts → Queue-HPyi0e1i.d.cts} +49 -49
- package/dist/Queue-HPyi0e1i.d.cts.map +1 -0
- package/dist/Queue-hwPN-t31.mjs +104 -0
- package/dist/Queue-hwPN-t31.mjs.map +1 -0
- package/dist/QueueBuilder-BFQn3OzZ.cjs +135 -0
- package/dist/QueueBuilder-BFQn3OzZ.cjs.map +1 -0
- package/dist/QueueBuilder-DCuYdjMw.mjs +118 -0
- package/dist/QueueBuilder-DCuYdjMw.mjs.map +1 -0
- package/dist/QueueBuilder-OSi6LkV9.d.cts +75 -0
- package/dist/QueueBuilder-OSi6LkV9.d.cts.map +1 -0
- package/dist/QueueBuilder-QHsnVt1P.d.mts +75 -0
- package/dist/QueueBuilder-QHsnVt1P.d.mts.map +1 -0
- package/dist/{Subscriber-2mEi0ImH.d.cts → Subscriber-Bpp02cGr.d.cts} +29 -20
- package/dist/Subscriber-Bpp02cGr.d.cts.map +1 -0
- package/dist/{Subscriber-xTJ9ayPN.d.mts → Subscriber-CtN9R48-.d.mts} +29 -20
- package/dist/Subscriber-CtN9R48-.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-4OPehf2R.cjs → SubscriberBuilder-C2PwqwIl.cjs} +61 -36
- package/dist/SubscriberBuilder-C2PwqwIl.cjs.map +1 -0
- package/dist/SubscriberBuilder-CuCMFpYW.d.mts +67 -0
- package/dist/SubscriberBuilder-CuCMFpYW.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-BjkbeT9l.mjs → SubscriberBuilder-DMFk_Ap1.mjs} +50 -24
- package/dist/SubscriberBuilder-DMFk_Ap1.mjs.map +1 -0
- package/dist/SubscriberBuilder-g3fAVWgs.d.cts +67 -0
- package/dist/SubscriberBuilder-g3fAVWgs.d.cts.map +1 -0
- package/dist/Topic-CkxOTrMv.cjs +104 -0
- package/dist/Topic-CkxOTrMv.cjs.map +1 -0
- package/dist/Topic-hPffOsot.mjs +99 -0
- package/dist/Topic-hPffOsot.mjs.map +1 -0
- package/dist/adaptors/aws.cjs +189 -110
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +81 -45
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +82 -46
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +161 -85
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +3 -10
- package/dist/adaptors/hono.d.cts +7 -16
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +8 -17
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +2 -10
- package/dist/adaptors/testing.cjs +704 -90
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +325 -54
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +325 -54
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +669 -71
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth-CIFXNuDk.d.cts +194 -0
- package/dist/auth-CIFXNuDk.d.cts.map +1 -0
- package/dist/auth-CJ9Ff6Lu.d.mts +194 -0
- package/dist/auth-CJ9Ff6Lu.d.mts.map +1 -0
- package/dist/auth.cjs +172 -31
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -108
- package/dist/auth.d.mts +2 -108
- package/dist/auth.mjs +161 -24
- package/dist/auth.mjs.map +1 -1
- package/dist/{cache-BrRz3fEB.d.mts → cache-CXh6GIgb.d.mts} +3 -6
- package/dist/cache-CXh6GIgb.d.mts.map +1 -0
- package/dist/{cache-BtZY_tHe.d.cts → cache-DnGDGly3.d.cts} +3 -6
- package/dist/cache-DnGDGly3.d.cts.map +1 -0
- package/dist/cache.cjs +68 -2
- package/dist/cache.cjs.map +1 -0
- package/dist/cache.d.cts +1 -2
- package/dist/cache.d.mts +1 -2
- package/dist/cache.mjs +67 -2
- package/dist/cache.mjs.map +1 -0
- package/dist/cipher-C1lEFX63.mjs +225 -0
- package/dist/cipher-C1lEFX63.mjs.map +1 -0
- package/dist/cipher-CVxfwLjk.cjs +332 -0
- package/dist/cipher-CVxfwLjk.cjs.map +1 -0
- package/dist/{clone-DblgEZZa.mjs → clone-EKNovYHu.mjs} +3 -3
- package/dist/clone-EKNovYHu.mjs.map +1 -0
- package/dist/{clone-Dy0cR2SZ.cjs → clone-UGJpvQnL.cjs} +7 -8
- package/dist/clone-UGJpvQnL.cjs.map +1 -0
- package/dist/{construct-interface-D9d4Gm4p.d.cts → construct-interface-B1AfqRl4.d.cts} +42 -11
- package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
- package/dist/{construct-interface-g5GM5pwR.d.mts → construct-interface-DluK3_da.d.mts} +42 -11
- package/dist/construct-interface-DluK3_da.d.mts.map +1 -0
- package/dist/construct-interface.cjs +113 -7
- package/dist/construct-interface.cjs.map +1 -0
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +106 -2
- package/dist/construct-interface.mjs.map +1 -0
- package/dist/credential.cjs +63 -16
- package/dist/credential.cjs.map +1 -1
- package/dist/credential.d.cts +16 -9
- package/dist/credential.d.cts.map +1 -1
- package/dist/credential.d.mts +16 -9
- package/dist/credential.d.mts.map +1 -1
- package/dist/credential.mjs +58 -12
- package/dist/credential.mjs.map +1 -1
- package/dist/crons/index.cjs +68 -10
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +32 -14
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +32 -14
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +66 -10
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +40 -15
- package/dist/database/kysely.cjs.map +1 -1
- package/dist/database/kysely.d.cts +2 -152
- package/dist/database/kysely.d.mts +2 -152
- package/dist/database/kysely.mjs +28 -5
- package/dist/database/kysely.mjs.map +1 -1
- package/dist/email.cjs +25 -12
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +3 -7
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts +3 -7
- package/dist/email.d.mts.map +1 -1
- package/dist/email.mjs +16 -3
- package/dist/email.mjs.map +1 -1
- package/dist/encryption.cjs +96 -0
- package/dist/encryption.cjs.map +1 -0
- package/dist/encryption.d.cts +117 -0
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +117 -0
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +83 -0
- package/dist/encryption.mjs.map +1 -0
- package/dist/endpoints/index.cjs +8 -10
- package/dist/endpoints/index.d.cts +51 -7
- package/dist/endpoints/index.d.cts.map +1 -0
- package/dist/endpoints/index.d.mts +51 -7
- package/dist/endpoints/index.d.mts.map +1 -0
- package/dist/endpoints/index.mjs +6 -10
- package/dist/external-api-CWY9orcO.d.mts +86 -0
- package/dist/external-api-CWY9orcO.d.mts.map +1 -0
- package/dist/external-api-D-5WB-sr.d.cts +86 -0
- package/dist/external-api-D-5WB-sr.d.cts.map +1 -0
- package/dist/external-api.cjs +124 -0
- package/dist/external-api.cjs.map +1 -0
- package/dist/external-api.d.cts +2 -0
- package/dist/external-api.d.mts +2 -0
- package/dist/external-api.mjs +121 -0
- package/dist/external-api.mjs.map +1 -0
- package/dist/file-server.cjs +42 -10
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +6 -10
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +6 -10
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +34 -2
- package/dist/file-server.mjs.map +1 -1
- package/dist/functions/index.cjs +2 -6
- package/dist/functions/index.d.cts +3 -4
- package/dist/functions/index.d.mts +3 -4
- package/dist/functions/index.mjs +2 -6
- package/dist/{functions-DJJA7VGc.cjs → functions-CbP5ZKma.cjs} +421 -273
- package/dist/functions-CbP5ZKma.cjs.map +1 -0
- package/dist/{functions-Ck21Uyq0.mjs → functions-Di6n5ltG.mjs} +383 -241
- package/dist/functions-Di6n5ltG.mjs.map +1 -0
- package/dist/index-BuzRvKOQ.d.cts +115 -0
- package/dist/index-BuzRvKOQ.d.cts.map +1 -0
- package/dist/index-CTkKOer4.d.mts +115 -0
- package/dist/index-CTkKOer4.d.mts.map +1 -0
- package/dist/index-CeEtxDmK.d.cts +79 -0
- package/dist/index-CeEtxDmK.d.cts.map +1 -0
- package/dist/index-CeEtxDmK.d.mts +79 -0
- package/dist/index-CeEtxDmK.d.mts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -3
- package/dist/kms-B-Hm3d5r.cjs +85 -0
- package/dist/kms-B-Hm3d5r.cjs.map +1 -0
- package/dist/kms-BdUlMJEZ.mjs +85 -0
- package/dist/kms-BdUlMJEZ.mjs.map +1 -0
- package/dist/kysely-Bqov3fwv.d.mts +159 -0
- package/dist/kysely-Bqov3fwv.d.mts.map +1 -0
- package/dist/kysely-DTnkZsub.d.cts +159 -0
- package/dist/kysely-DTnkZsub.d.cts.map +1 -0
- package/dist/{lazyAccessors-BoJN3SMd.mjs → lazyAccessors-CFanua0O.mjs} +20 -60
- package/dist/lazyAccessors-CFanua0O.mjs.map +1 -0
- package/dist/{lazyAccessors-e3j2oE2m.cjs → lazyAccessors-hJKGv8Ay.cjs} +60 -113
- package/dist/lazyAccessors-hJKGv8Ay.cjs.map +1 -0
- package/dist/mobile-app.cjs +73 -0
- package/dist/mobile-app.cjs.map +1 -0
- package/dist/mobile-app.d.cts +61 -0
- package/dist/mobile-app.d.cts.map +1 -0
- package/dist/mobile-app.d.mts +61 -0
- package/dist/mobile-app.d.mts.map +1 -0
- package/dist/mobile-app.mjs +72 -0
- package/dist/mobile-app.mjs.map +1 -0
- package/dist/object-storage.cjs +18 -10
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +3 -7
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +3 -7
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +11 -3
- package/dist/object-storage.mjs.map +1 -1
- package/dist/{processAudits-Dmts9H_b.mjs → processAudits-BpRlPQMW.mjs} +16 -19
- package/dist/processAudits-BpRlPQMW.mjs.map +1 -0
- package/dist/{processAudits-CGqttuXm.cjs → processAudits-D_2W5x8k.cjs} +26 -30
- package/dist/processAudits-D_2W5x8k.cjs.map +1 -0
- package/dist/queue/index.cjs +6 -189
- package/dist/queue/index.d.cts +3 -60
- package/dist/queue/index.d.mts +3 -60
- package/dist/queue/index.mjs +3 -186
- package/dist/rest-api.cjs +88 -63
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +68 -61
- package/dist/rest-api.d.cts.map +1 -1
- package/dist/rest-api.d.mts +68 -61
- package/dist/rest-api.d.mts.map +1 -1
- package/dist/rest-api.mjs +80 -55
- package/dist/rest-api.mjs.map +1 -1
- package/dist/{chunk-DWy1uDak.cjs → rolldown-runtime-y5ARvAq5.cjs} +14 -18
- package/dist/site.cjs +34 -9
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +17 -22
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +17 -22
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +30 -5
- package/dist/site.mjs.map +1 -1
- package/dist/subscribers/index.cjs +2 -11
- package/dist/subscribers/index.d.cts +3 -14
- package/dist/subscribers/index.d.mts +3 -14
- package/dist/subscribers/index.mjs +2 -11
- package/dist/surfaceEnv-CNimK76p.cjs +56 -0
- package/dist/surfaceEnv-CNimK76p.cjs.map +1 -0
- package/dist/surfaceEnv-wMT5QzgZ.mjs +45 -0
- package/dist/surfaceEnv-wMT5QzgZ.mjs.map +1 -0
- package/dist/{telemetry-C3L0iS28.d.cts → telemetry-DGcFlVpB.d.cts} +2 -5
- package/dist/telemetry-DGcFlVpB.d.cts.map +1 -0
- package/dist/{telemetry-D7bVFLGi.d.mts → telemetry-DGcFlVpB.d.mts} +2 -5
- package/dist/telemetry-DGcFlVpB.d.mts.map +1 -0
- package/dist/topic/index.cjs +3 -137
- package/dist/topic/index.d.cts +2 -32
- package/dist/topic/index.d.mts +2 -32
- package/dist/topic/index.mjs +2 -134
- package/dist/{types-BlAkSuGI.d.cts → types-DMuSQeLL.d.cts} +3 -5
- package/dist/types-DMuSQeLL.d.cts.map +1 -0
- package/dist/{types-aKksMEWL.d.mts → types-DMuSQeLL.d.mts} +3 -5
- package/dist/types-DMuSQeLL.d.mts.map +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -0
- package/dist/worker.cjs +137 -38
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +113 -44
- package/dist/worker.d.cts.map +1 -1
- package/dist/worker.d.mts +113 -43
- package/dist/worker.d.mts.map +1 -1
- package/dist/worker.mjs +132 -33
- package/dist/worker.mjs.map +1 -1
- package/package.json +81 -41
- package/dist/Construct-BD5neF7w.mjs.map +0 -1
- package/dist/Construct-C0ijr2qp.d.cts +0 -117
- package/dist/Construct-C0ijr2qp.d.cts.map +0 -1
- package/dist/Construct-Ct8nalEi.d.mts +0 -117
- package/dist/Construct-Ct8nalEi.d.mts.map +0 -1
- package/dist/Construct-CyS3RpTL.cjs.map +0 -1
- package/dist/Cron-B2OFsfDM.d.cts.map +0 -1
- package/dist/Cron-CqEbBbwH.d.mts.map +0 -1
- package/dist/CronBuilder-Bg-9h2cc.d.mts +0 -44
- package/dist/CronBuilder-Bg-9h2cc.d.mts.map +0 -1
- package/dist/CronBuilder-CdibiHNB.mjs +0 -84
- package/dist/CronBuilder-CdibiHNB.mjs.map +0 -1
- package/dist/CronBuilder-DyUr6nYz.cjs +0 -96
- package/dist/CronBuilder-DyUr6nYz.cjs.map +0 -1
- package/dist/CronBuilder-LSJMfqnq.d.cts +0 -44
- package/dist/CronBuilder-LSJMfqnq.d.cts.map +0 -1
- package/dist/Endpoint-DODn1RhN.cjs.map +0 -1
- package/dist/Endpoint-Dem2XyCu.d.mts.map +0 -1
- package/dist/Endpoint-Dij_wOcc.mjs.map +0 -1
- package/dist/Endpoint-DrD8a1yH.d.cts.map +0 -1
- package/dist/EndpointFactory-BHFMmFkV.cjs.map +0 -1
- package/dist/EndpointFactory-b4ituq-s.mjs.map +0 -1
- package/dist/HonoEndpointAdaptor-BM2jbWht.mjs.map +0 -1
- package/dist/HonoEndpointAdaptor-De6IlBZe.cjs.map +0 -1
- package/dist/Queue-D7ZuwBhy.d.cts.map +0 -1
- package/dist/Queue-gVGfi2Yk.d.mts.map +0 -1
- package/dist/Subscriber-2mEi0ImH.d.cts.map +0 -1
- package/dist/Subscriber-xTJ9ayPN.d.mts.map +0 -1
- package/dist/SubscriberBuilder-4OPehf2R.cjs.map +0 -1
- package/dist/SubscriberBuilder-BjkbeT9l.mjs.map +0 -1
- package/dist/SubscriberBuilder-Dptmo-1A.d.mts +0 -62
- package/dist/SubscriberBuilder-Dptmo-1A.d.mts.map +0 -1
- package/dist/SubscriberBuilder-waNhzjSM.d.cts +0 -62
- package/dist/SubscriberBuilder-waNhzjSM.d.cts.map +0 -1
- package/dist/Topic-19QeHBIR.d.cts +0 -91
- package/dist/Topic-19QeHBIR.d.cts.map +0 -1
- package/dist/Topic-DuFeqkBh.d.mts +0 -91
- package/dist/Topic-DuFeqkBh.d.mts.map +0 -1
- package/dist/auth.d.cts.map +0 -1
- package/dist/auth.d.mts.map +0 -1
- package/dist/cache-0ANvRQnD.mjs +0 -51
- package/dist/cache-0ANvRQnD.mjs.map +0 -1
- package/dist/cache-3WSvAulx.cjs +0 -57
- package/dist/cache-3WSvAulx.cjs.map +0 -1
- package/dist/cache-BrRz3fEB.d.mts.map +0 -1
- package/dist/cache-BtZY_tHe.d.cts.map +0 -1
- package/dist/clone-DblgEZZa.mjs.map +0 -1
- package/dist/clone-Dy0cR2SZ.cjs.map +0 -1
- package/dist/construct-interface-BfjcOD_E.cjs +0 -117
- package/dist/construct-interface-BfjcOD_E.cjs.map +0 -1
- package/dist/construct-interface-D9d4Gm4p.d.cts.map +0 -1
- package/dist/construct-interface-Z4CpS8tK.mjs +0 -81
- package/dist/construct-interface-Z4CpS8tK.mjs.map +0 -1
- package/dist/construct-interface-g5GM5pwR.d.mts.map +0 -1
- package/dist/database/kysely.d.cts.map +0 -1
- package/dist/database/kysely.d.mts.map +0 -1
- package/dist/functions-Ck21Uyq0.mjs.map +0 -1
- package/dist/functions-DJJA7VGc.cjs.map +0 -1
- package/dist/index-AIfVzkhi.d.cts +0 -170
- package/dist/index-AIfVzkhi.d.cts.map +0 -1
- package/dist/index-B8g8POkr.d.cts.map +0 -1
- package/dist/index-D3zjrwjr.d.mts +0 -169
- package/dist/index-D3zjrwjr.d.mts.map +0 -1
- package/dist/index-DbKmfl-q.d.mts.map +0 -1
- package/dist/lazyAccessors-BoJN3SMd.mjs.map +0 -1
- package/dist/lazyAccessors-e3j2oE2m.cjs.map +0 -1
- package/dist/processAudits-CGqttuXm.cjs.map +0 -1
- package/dist/processAudits-Dmts9H_b.mjs.map +0 -1
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts.map +0 -1
- package/dist/queue/index.d.mts.map +0 -1
- package/dist/queue/index.mjs.map +0 -1
- package/dist/subscribers/index.cjs.map +0 -1
- package/dist/subscribers/index.d.cts.map +0 -1
- package/dist/subscribers/index.d.mts.map +0 -1
- package/dist/subscribers/index.mjs.map +0 -1
- package/dist/surfaceEnv-BFXEms2f.cjs +0 -39
- package/dist/surfaceEnv-BFXEms2f.cjs.map +0 -1
- package/dist/surfaceEnv-C3Ktahea.mjs +0 -27
- package/dist/surfaceEnv-C3Ktahea.mjs.map +0 -1
- package/dist/telemetry-C3L0iS28.d.cts.map +0 -1
- package/dist/telemetry-D7bVFLGi.d.mts.map +0 -1
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts.map +0 -1
- package/dist/topic/index.d.mts.map +0 -1
- package/dist/topic/index.mjs.map +0 -1
- package/dist/types-BlAkSuGI.d.cts.map +0 -1
- package/dist/types-aKksMEWL.d.mts.map +0 -1
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import { FunctionBuilder } from "../functions-
|
|
4
|
-
import "../
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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-Di6n5ltG.mjs";
|
|
4
|
+
import { n as ResponseBuilder, t as Endpoint } from "../Endpoint-CQ9RJ7p2.mjs";
|
|
5
|
+
import { t as Queue } from "../Queue-hwPN-t31.mjs";
|
|
6
|
+
import { Email } from "../email.mjs";
|
|
7
|
+
import { KyselyDatabase } from "../database/kysely.mjs";
|
|
8
|
+
import { c as createObjectHeaders, r as createCookieHeaderAccessor } from "../lazyAccessors-CFanua0O.mjs";
|
|
9
|
+
import { t as Topic } from "../Topic-hPffOsot.mjs";
|
|
10
|
+
import { t as HonoEndpoint } from "../HonoEndpointAdaptor-BIS0O3M9.mjs";
|
|
11
|
+
import { n as executeWithAuditTransaction } from "../processAudits-BpRlPQMW.mjs";
|
|
12
|
+
import { provideKey } from "@geekmidas/manifest";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
9
14
|
import { ForbiddenError } from "@geekmidas/errors";
|
|
10
15
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
11
|
-
import { ServiceDiscovery, runWithRequestContext } from "@geekmidas/services";
|
|
12
|
-
import { DefaultAuditor } from "@geekmidas/audit";
|
|
16
|
+
import { ServiceDiscovery, runWithRequestContext, serviceContext } from "@geekmidas/services";
|
|
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
|
-
|
|
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";
|
|
16
30
|
//#region src/endpoints/MswEndpointAdaptor.ts
|
|
17
|
-
/**
|
|
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.
|
|
21
|
-
*/
|
|
22
|
-
const TEST_CONTEXT_HEADER = "x-test-context-id";
|
|
23
31
|
const MSW_HTTP_METHODS = [
|
|
24
32
|
"get",
|
|
25
33
|
"post",
|
|
@@ -67,7 +75,6 @@ function createMswHandlers(endpoints, options) {
|
|
|
67
75
|
break;
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
|
-
if (ctxOptions.publisher) serviceDefs.push(ctxOptions.publisher);
|
|
71
78
|
if (ctxOptions.auditorStorage !== void 0) {
|
|
72
79
|
for (const endpoint of endpoints) if (endpoint.auditorStorageService) {
|
|
73
80
|
serviceDefs.push({
|
|
@@ -111,7 +118,6 @@ function createMswHandlers(endpoints, options) {
|
|
|
111
118
|
registerContext
|
|
112
119
|
};
|
|
113
120
|
}
|
|
114
|
-
|
|
115
121
|
//#endregion
|
|
116
122
|
//#region src/endpoints/TestEndpointAdaptor.ts
|
|
117
123
|
/**
|
|
@@ -131,6 +137,8 @@ function serializeCookie(name, value, options) {
|
|
|
131
137
|
return cookieString;
|
|
132
138
|
}
|
|
133
139
|
var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
140
|
+
endpoint;
|
|
141
|
+
serviceDiscovery;
|
|
134
142
|
static getDefaultServiceDiscover(_endpoint) {
|
|
135
143
|
return ServiceDiscovery.getInstance(new EnvironmentParser({}));
|
|
136
144
|
}
|
|
@@ -165,7 +173,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
165
173
|
cookie,
|
|
166
174
|
...rawDb !== void 0 && { db: rawDb }
|
|
167
175
|
});
|
|
168
|
-
|
|
176
|
+
if (!await this.endpoint.authorize({
|
|
169
177
|
header,
|
|
170
178
|
cookie,
|
|
171
179
|
services: ctx.services,
|
|
@@ -175,8 +183,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
175
183
|
body,
|
|
176
184
|
query,
|
|
177
185
|
params
|
|
178
|
-
})
|
|
179
|
-
if (!isAuthorized) {
|
|
186
|
+
})) {
|
|
180
187
|
logger.warn("Forbidden access attempt");
|
|
181
188
|
throw new ForbiddenError("Forbidden access to the endpoint", "You do not have permission to access this resource.");
|
|
182
189
|
}
|
|
@@ -198,24 +205,22 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
198
205
|
} catch (error) {
|
|
199
206
|
logger.error(error, "Failed to extract actor for audits");
|
|
200
207
|
}
|
|
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
208
|
auditContext = {
|
|
210
|
-
auditor
|
|
209
|
+
auditor: new DefaultAuditor({
|
|
210
|
+
actor,
|
|
211
|
+
storage: auditorStorage,
|
|
212
|
+
metadata: {
|
|
213
|
+
endpoint: this.endpoint.route,
|
|
214
|
+
method: this.endpoint.method
|
|
215
|
+
}
|
|
216
|
+
}),
|
|
211
217
|
storage: auditorStorage
|
|
212
218
|
};
|
|
213
219
|
}
|
|
214
220
|
const audits = this.endpoint.audits;
|
|
215
221
|
if (!auditContext && audits?.length) logger.warn("No auditor storage service available");
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const db = trx ?? rawDb;
|
|
222
|
+
const { output, metadata } = await executeWithAuditTransaction(auditContext, async (auditor) => {
|
|
223
|
+
const db = auditor?.getTransaction?.() ?? rawDb;
|
|
219
224
|
const responseBuilder = new ResponseBuilder();
|
|
220
225
|
const response = await this.endpoint.handler({
|
|
221
226
|
body,
|
|
@@ -230,36 +235,33 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
230
235
|
db
|
|
231
236
|
}, responseBuilder);
|
|
232
237
|
let data = response;
|
|
233
|
-
let metadata
|
|
238
|
+
let metadata = responseBuilder.getMetadata();
|
|
234
239
|
if (Endpoint.hasMetadata(response)) {
|
|
235
240
|
data = response.data;
|
|
236
|
-
metadata
|
|
241
|
+
metadata = response.metadata;
|
|
237
242
|
}
|
|
238
|
-
const output$1 = await this.endpoint.parseOutput(data);
|
|
239
243
|
return {
|
|
240
|
-
output:
|
|
241
|
-
metadata
|
|
244
|
+
output: await this.endpoint.parseOutput(data),
|
|
245
|
+
metadata,
|
|
242
246
|
responseBuilder
|
|
243
247
|
};
|
|
244
|
-
}, async (result
|
|
248
|
+
}, async (result, auditor) => {
|
|
245
249
|
if (!audits?.length) return;
|
|
246
250
|
for (const audit of audits) {
|
|
247
|
-
if (audit.when && !audit.when(result
|
|
248
|
-
const payload = audit.payload(result
|
|
249
|
-
const entityId = audit.entityId?.(result
|
|
251
|
+
if (audit.when && !audit.when(result.output)) continue;
|
|
252
|
+
const payload = audit.payload(result.output);
|
|
253
|
+
const entityId = audit.entityId?.(result.output);
|
|
250
254
|
auditor.audit(audit.type, payload, {
|
|
251
255
|
table: audit.table,
|
|
252
256
|
entityId
|
|
253
257
|
});
|
|
254
258
|
}
|
|
255
259
|
}, { db: rawDb });
|
|
256
|
-
|
|
257
|
-
ctx.publisher && await this.serviceDiscovery.register([ctx.publisher]);
|
|
258
|
-
await publishConstructEvents(this.endpoint, output, this.serviceDiscovery);
|
|
260
|
+
await publishConstructEvents(this.endpoint, output, this.serviceDiscovery, this.endpoint.logger, ctx.services);
|
|
259
261
|
const headers = { ...metadata.headers || {} };
|
|
260
262
|
if (metadata.cookies && metadata.cookies.size > 0) {
|
|
261
263
|
const setCookieValues = [];
|
|
262
|
-
for (const [name, cookie
|
|
264
|
+
for (const [name, cookie] of metadata.cookies.entries()) setCookieValues.push(serializeCookie(name, cookie.value, cookie.options));
|
|
263
265
|
headers["set-cookie"] = setCookieValues;
|
|
264
266
|
}
|
|
265
267
|
return {
|
|
@@ -270,14 +272,14 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
274
|
async request(ctx) {
|
|
273
|
-
|
|
274
|
-
return response.body;
|
|
275
|
+
return (await this.fullRequest(ctx)).body;
|
|
275
276
|
}
|
|
276
277
|
};
|
|
277
|
-
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/functions/TestFunctionAdaptor.ts
|
|
280
280
|
var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
281
|
+
fn;
|
|
282
|
+
serviceDiscovery;
|
|
281
283
|
static getDefaultServiceDiscovery(_fn) {
|
|
282
284
|
return ServiceDiscovery.getInstance(new EnvironmentParser({}));
|
|
283
285
|
}
|
|
@@ -293,15 +295,11 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
293
295
|
else services = await this.serviceDiscovery.register(this.fn.services);
|
|
294
296
|
let db;
|
|
295
297
|
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
|
-
}
|
|
298
|
+
else if (this.fn.databaseService) db = (await this.serviceDiscovery.register([this.fn.databaseService]))[this.fn.databaseService.serviceName];
|
|
300
299
|
let auditor;
|
|
301
300
|
if ("auditor" in ctx && ctx.auditor !== void 0) auditor = ctx.auditor;
|
|
302
301
|
else if (this.fn.auditorStorageService) {
|
|
303
|
-
const
|
|
304
|
-
const storage = auditServices[this.fn.auditorStorageService.serviceName];
|
|
302
|
+
const storage = (await this.serviceDiscovery.register([this.fn.auditorStorageService]))[this.fn.auditorStorageService.serviceName];
|
|
305
303
|
auditor = new DefaultAuditor({
|
|
306
304
|
actor: {
|
|
307
305
|
id: "system",
|
|
@@ -315,11 +313,10 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
315
313
|
});
|
|
316
314
|
}
|
|
317
315
|
const requestId = `test-${Date.now()}`;
|
|
318
|
-
const startTime = Date.now();
|
|
319
316
|
return runWithRequestContext({
|
|
320
317
|
logger,
|
|
321
318
|
requestId,
|
|
322
|
-
startTime
|
|
319
|
+
startTime: Date.now()
|
|
323
320
|
}, async () => {
|
|
324
321
|
const response = await this.fn.fn({
|
|
325
322
|
input: parsedInput,
|
|
@@ -336,24 +333,26 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
336
333
|
await auditor.flush();
|
|
337
334
|
}
|
|
338
335
|
}
|
|
339
|
-
await publishEvents(logger, this.serviceDiscovery, this.fn.events, output,
|
|
336
|
+
await publishEvents(logger, this.serviceDiscovery, this.fn.events, output, services);
|
|
340
337
|
return output;
|
|
341
338
|
});
|
|
342
339
|
}
|
|
343
340
|
};
|
|
344
|
-
|
|
345
341
|
//#endregion
|
|
346
342
|
//#region src/queue/TestQueueAdaptor.ts
|
|
347
343
|
/**
|
|
348
344
|
* In-memory test driver for a {@link Queue} worker. Hand it a batch of messages
|
|
349
345
|
* 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.
|
|
346
|
+
* and returns the handler result — no SQS/pg-boss required. A queue with a
|
|
347
|
+
* database gets `db` registered from it, or the one the request passes.
|
|
351
348
|
*
|
|
352
349
|
* @example
|
|
353
350
|
* const adapter = new TestQueueAdaptor(ordersQueue);
|
|
354
351
|
* await adapter.invoke({ messages: [{ orderId: '123' }] });
|
|
355
352
|
*/
|
|
356
353
|
var TestQueueAdaptor = class TestQueueAdaptor {
|
|
354
|
+
queue;
|
|
355
|
+
serviceDiscovery;
|
|
357
356
|
static getDefaultServiceDiscovery() {
|
|
358
357
|
return ServiceDiscovery.getInstance(new EnvironmentParser({}));
|
|
359
358
|
}
|
|
@@ -364,23 +363,30 @@ var TestQueueAdaptor = class TestQueueAdaptor {
|
|
|
364
363
|
async invoke(request) {
|
|
365
364
|
const logger = this.queue.logger.child({ test: true });
|
|
366
365
|
const services = request.services ?? await this.serviceDiscovery.register(this.queue.services);
|
|
366
|
+
const db = request.db !== void 0 ? request.db : await this.getDatabase();
|
|
367
367
|
const requestId = `test-${Date.now()}`;
|
|
368
|
-
const startTime = Date.now();
|
|
369
368
|
return runWithRequestContext({
|
|
370
369
|
logger,
|
|
371
370
|
requestId,
|
|
372
|
-
startTime
|
|
371
|
+
startTime: Date.now()
|
|
373
372
|
}, () => this.queue.handler({
|
|
374
373
|
messages: request.messages,
|
|
375
374
|
services,
|
|
376
|
-
logger
|
|
375
|
+
logger,
|
|
376
|
+
db
|
|
377
377
|
}));
|
|
378
378
|
}
|
|
379
|
+
async getDatabase() {
|
|
380
|
+
const service = this.queue.databaseService;
|
|
381
|
+
if (!service) return void 0;
|
|
382
|
+
return (await this.serviceDiscovery.register([service]))[service.serviceName];
|
|
383
|
+
}
|
|
379
384
|
};
|
|
380
|
-
|
|
381
385
|
//#endregion
|
|
382
386
|
//#region src/subscribers/TestSubscriberAdaptor.ts
|
|
383
387
|
var TestSubscriberAdaptor = class TestSubscriberAdaptor {
|
|
388
|
+
subscriber;
|
|
389
|
+
serviceDiscovery;
|
|
384
390
|
static getDefaultServiceDiscovery() {
|
|
385
391
|
return ServiceDiscovery.getInstance(new EnvironmentParser({}));
|
|
386
392
|
}
|
|
@@ -393,19 +399,20 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
|
|
|
393
399
|
let services;
|
|
394
400
|
if (request.services) services = request.services;
|
|
395
401
|
else services = await this.serviceDiscovery.register(this.subscriber.services);
|
|
402
|
+
const db = request.db !== void 0 ? request.db : await this.getDatabase();
|
|
396
403
|
const filteredEvents = this.filterEvents(request.events);
|
|
397
404
|
if (filteredEvents.length === 0) return { batchItemFailures: [] };
|
|
398
405
|
const requestId = `test-${Date.now()}`;
|
|
399
|
-
const startTime = Date.now();
|
|
400
406
|
return runWithRequestContext({
|
|
401
407
|
logger,
|
|
402
408
|
requestId,
|
|
403
|
-
startTime
|
|
409
|
+
startTime: Date.now()
|
|
404
410
|
}, async () => {
|
|
405
411
|
const result = await this.subscriber.handler({
|
|
406
412
|
events: filteredEvents,
|
|
407
413
|
services,
|
|
408
|
-
logger
|
|
414
|
+
logger,
|
|
415
|
+
db
|
|
409
416
|
});
|
|
410
417
|
let output = result;
|
|
411
418
|
if (this.subscriber.outputSchema && result) {
|
|
@@ -413,16 +420,607 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
|
|
|
413
420
|
if (validationResult.issues) throw new Error("Subscriber output validation failed");
|
|
414
421
|
output = validationResult.value;
|
|
415
422
|
}
|
|
416
|
-
await publishEvents(logger, this.serviceDiscovery, this.subscriber.events, output, this.subscriber.publisherService);
|
|
417
423
|
return output;
|
|
418
424
|
});
|
|
419
425
|
}
|
|
426
|
+
async getDatabase() {
|
|
427
|
+
const service = this.subscriber.databaseService;
|
|
428
|
+
if (!service) return void 0;
|
|
429
|
+
return (await this.serviceDiscovery.register([service]))[service.serviceName];
|
|
430
|
+
}
|
|
420
431
|
filterEvents(events) {
|
|
421
432
|
if (!this.subscriber.subscribedEvents) return events;
|
|
422
433
|
return events.filter((event) => this.subscriber.subscribedEvents.includes(event.type));
|
|
423
434
|
}
|
|
424
435
|
};
|
|
425
|
-
|
|
426
436
|
//#endregion
|
|
427
|
-
|
|
437
|
+
//#region src/testing/manifest.ts
|
|
438
|
+
/**
|
|
439
|
+
* The test manifest: what `gkm test` knows about an app, written down for the
|
|
440
|
+
* suite it starts.
|
|
441
|
+
*
|
|
442
|
+
* `gkm test` discovers the constructs, reconciles the test stage and resolves
|
|
443
|
+
* its environment — then, until this existed, threw all of it away and left a
|
|
444
|
+
* test to declare it again by hand. The manifest keeps it: which construct and
|
|
445
|
+
* endpoint is exported where, and the environment the test stage resolved,
|
|
446
|
+
* under the keys the constructs themselves derive. A feature test is built from
|
|
447
|
+
* it, so nothing a test says can drift from what the app declares.
|
|
448
|
+
*/
|
|
449
|
+
/** The environment variable `gkm test` names the manifest in. */
|
|
450
|
+
const TEST_MANIFEST_ENV = "GKM_TEST_MANIFEST";
|
|
451
|
+
/**
|
|
452
|
+
* Read a test manifest: from a path, a `file:` URL, or — given nothing — the
|
|
453
|
+
* one `gkm test` named in `GKM_TEST_MANIFEST`.
|
|
454
|
+
*/
|
|
455
|
+
function loadTestManifest(from) {
|
|
456
|
+
const location = from ?? process.env["GKM_TEST_MANIFEST"];
|
|
457
|
+
if (!location) throw new NoTestManifest();
|
|
458
|
+
trustLocalEdge();
|
|
459
|
+
const path = location instanceof URL || location.startsWith("file:") ? fileURLToPath(location) : location;
|
|
460
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
461
|
+
}
|
|
462
|
+
let trusted = false;
|
|
463
|
+
/**
|
|
464
|
+
* Trust the local edge's certificate authority in this thread.
|
|
465
|
+
*
|
|
466
|
+
* `NODE_EXTRA_CA_CERTS` does it for a process started with it — which a
|
|
467
|
+
* suite started by `gkm test` is, and one started by plain `vitest` or an
|
|
468
|
+
* editor is not: its setup only learns the path once Vitest is running, and a
|
|
469
|
+
* worker *thread* shares that process and keeps a TLS store of its own. Every
|
|
470
|
+
* feature test loads the manifest, so this is the one place each worker passes
|
|
471
|
+
* through.
|
|
472
|
+
*/
|
|
473
|
+
function trustLocalEdge() {
|
|
474
|
+
const certificate = process.env.NODE_EXTRA_CA_CERTS;
|
|
475
|
+
if (trusted || !certificate || !existsSync(certificate)) return;
|
|
476
|
+
trusted = true;
|
|
477
|
+
tls.setDefaultCACertificates([...tls.getCACertificates("default"), readFileSync(certificate, "utf-8")]);
|
|
478
|
+
}
|
|
479
|
+
/** A feature test ran without a manifest to build itself from. */
|
|
480
|
+
var NoTestManifest = class extends Error {
|
|
481
|
+
constructor() {
|
|
482
|
+
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}.`);
|
|
483
|
+
this.name = "NoTestManifest";
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/testing/featureTest.ts
|
|
488
|
+
/**
|
|
489
|
+
* `featureTest`: an app, driven the way it runs deployed.
|
|
490
|
+
*
|
|
491
|
+
* A browser signs in and calls the API; the API calls the auth server; each
|
|
492
|
+
* over its URL, each database in its own transaction. Nothing runs as a server:
|
|
493
|
+
* every URL an app's constructs answer on is served in-process through MSW,
|
|
494
|
+
* from the real handler, for the test that made the request. Everything else
|
|
495
|
+
* with a real local equivalent — Postgres, Mailpit, MinIO — is used directly.
|
|
496
|
+
*
|
|
497
|
+
* It is built from the test manifest `gkm test` writes — the constructs and
|
|
498
|
+
* endpoints the app exports, and the environment the test stage resolved — so
|
|
499
|
+
* a test declares none of it. `gkm test` also generates the configured `it`
|
|
500
|
+
* and a `Browser` with a typed client per surface:
|
|
501
|
+
*
|
|
502
|
+
* ```ts
|
|
503
|
+
* import { it } from '#test';
|
|
504
|
+
*
|
|
505
|
+
* it('shows the signed-in user their profile', async ({ browser, mailbox }) => {
|
|
506
|
+
* await browser.auth.signIn.magicLink({ email: 'ada@shop.test' });
|
|
507
|
+
* await browser.visit((await mailbox('ada@shop.test').last()).link!);
|
|
508
|
+
* expect(await browser.api.get('/profile')).toMatchObject({ email: 'ada@shop.test' });
|
|
509
|
+
* });
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
/** Every test in flight in this process, by id. */
|
|
513
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
514
|
+
/** Databases already resolving to test transactions — patched once each. */
|
|
515
|
+
const bound = /* @__PURE__ */ new WeakSet();
|
|
516
|
+
function featureTest(options = {}) {
|
|
517
|
+
const manifest = options.manifest ?? loadTestManifest();
|
|
518
|
+
const BrowserClass = options.browser ?? Browser;
|
|
519
|
+
let app;
|
|
520
|
+
let factoryDatabases = [];
|
|
521
|
+
let owned = [];
|
|
522
|
+
let network;
|
|
523
|
+
let restoreFetch = () => {};
|
|
524
|
+
beforeAll(async () => {
|
|
525
|
+
app = await load(manifest, options.modules ?? {});
|
|
526
|
+
owned = ownDatabases(app, manifest);
|
|
527
|
+
factoryDatabases = databasesFor(options.factories ?? {}, owned);
|
|
528
|
+
for (const database of app.databases) bindToTests(database);
|
|
529
|
+
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)));
|
|
530
|
+
network.listen({ onUnhandledRequest(request, print) {
|
|
531
|
+
if (isLocal(new URL(request.url))) return;
|
|
532
|
+
print.error();
|
|
533
|
+
} });
|
|
534
|
+
const restoreStamp = installContextFetch();
|
|
535
|
+
const stamped = globalThis.fetch;
|
|
536
|
+
globalThis.fetch = deliveringFetch(stamped, (id) => {
|
|
537
|
+
const state = contexts.get(id);
|
|
538
|
+
return state ? deliver(app, state, id) : Promise.resolve();
|
|
539
|
+
});
|
|
540
|
+
restoreFetch = () => {
|
|
541
|
+
globalThis.fetch = stamped;
|
|
542
|
+
restoreStamp();
|
|
543
|
+
};
|
|
544
|
+
});
|
|
545
|
+
afterAll(() => {
|
|
546
|
+
restoreFetch();
|
|
547
|
+
network?.close();
|
|
548
|
+
});
|
|
549
|
+
const run = (name, fn) => async () => {
|
|
550
|
+
const id = randomUUID();
|
|
551
|
+
faker.seed(seedOf(name));
|
|
552
|
+
const state = {
|
|
553
|
+
transactions: new TransactionRegistry(),
|
|
554
|
+
discovery: new ServiceDiscovery(app.envParser),
|
|
555
|
+
surfaces: /* @__PURE__ */ new Map(),
|
|
556
|
+
auth: /* @__PURE__ */ new Map(),
|
|
557
|
+
addresses: /* @__PURE__ */ new Set(),
|
|
558
|
+
published: /* @__PURE__ */ new Map(),
|
|
559
|
+
pending: [],
|
|
560
|
+
delivering: false
|
|
561
|
+
};
|
|
562
|
+
const readMail = app.readMail;
|
|
563
|
+
if (readMail) state.mailbox = (address) => {
|
|
564
|
+
state.addresses.add(address);
|
|
565
|
+
return readMail(address);
|
|
566
|
+
};
|
|
567
|
+
contexts.set(id, state);
|
|
568
|
+
await state.discovery.register(recorders(app.channels, state));
|
|
569
|
+
try {
|
|
570
|
+
await runInTestContext(id, async () => {
|
|
571
|
+
const browser = new BrowserClass();
|
|
572
|
+
const restore = browser.install();
|
|
573
|
+
try {
|
|
574
|
+
const transaction = (database) => state.transactions.get(database.id, urlOf(database, app.envParser), database.clientConfig);
|
|
575
|
+
const db = { get: (name) => {
|
|
576
|
+
const database = owned.find((candidate) => candidate.service.serviceName === name);
|
|
577
|
+
if (!database) throw new UnknownDatabase(name, owned.map((candidate) => candidate.service.serviceName));
|
|
578
|
+
return transaction(database);
|
|
579
|
+
} };
|
|
580
|
+
const built = /* @__PURE__ */ new Map();
|
|
581
|
+
await fn({
|
|
582
|
+
browser,
|
|
583
|
+
db,
|
|
584
|
+
factories: { get: (name) => {
|
|
585
|
+
const database = factoryDatabases.find(([candidate]) => candidate === name)?.[1];
|
|
586
|
+
if (!database) throw new UnknownFactory(name, factoryDatabases.map(([candidate]) => candidate));
|
|
587
|
+
let factory = built.get(name);
|
|
588
|
+
if (!factory) {
|
|
589
|
+
factory = transaction(database).then(options.factories[name]);
|
|
590
|
+
built.set(name, factory);
|
|
591
|
+
}
|
|
592
|
+
return factory;
|
|
593
|
+
} },
|
|
594
|
+
faker,
|
|
595
|
+
mailbox: (address) => {
|
|
596
|
+
if (!state.mailbox) throw new NoInbox();
|
|
597
|
+
return state.mailbox(address);
|
|
598
|
+
},
|
|
599
|
+
published: (channel) => [...state.published.get(channel.id) ?? []],
|
|
600
|
+
services: { get: (name) => resolveService(app, state, name) },
|
|
601
|
+
subscriber: (subscriber) => thenDeliver(new TestSubscriberAdaptor(subscriber, state.discovery), () => deliver(app, state, id)),
|
|
602
|
+
queue: (queue) => thenDeliver(new TestQueueAdaptor(queue, state.discovery), () => deliver(app, state, id))
|
|
603
|
+
});
|
|
604
|
+
} finally {
|
|
605
|
+
restore();
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
} finally {
|
|
609
|
+
contexts.delete(id);
|
|
610
|
+
await Promise.all([state.transactions.rollbackAll(), ...[...state.addresses].map((address) => app.readMail?.(address).clear())]);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
const it = ((name, fn, timeout) => test(name, run(name, fn), timeout));
|
|
614
|
+
it.only = (name, fn, timeout) => test.only(name, run(name, fn), timeout);
|
|
615
|
+
it.skip = (name, fn, timeout) => test.skip(name, run(name, fn), timeout);
|
|
616
|
+
return it;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* A test's faker seed, from its name: the same test draws the same data on
|
|
620
|
+
* every run, and two tests draw different data.
|
|
621
|
+
*/
|
|
622
|
+
function seedOf(name) {
|
|
623
|
+
let hash = 0;
|
|
624
|
+
for (const char of name) hash = Math.imul(hash, 31) + char.charCodeAt(0) | 0;
|
|
625
|
+
return hash >>> 0;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Import what the manifest points at.
|
|
629
|
+
*
|
|
630
|
+
* The same modules the app runs, so a construct here *is* the app's construct —
|
|
631
|
+
* the one its endpoints were built from — never a copy declared again.
|
|
632
|
+
*/
|
|
633
|
+
async function load(manifest, modules) {
|
|
634
|
+
const envParser = new EnvironmentParser({ ...manifest.env });
|
|
635
|
+
const imported = async ({ file, export: name }) => (modules[file] ?? await import(file))[name];
|
|
636
|
+
const constructs = await Promise.all(Object.values(manifest.constructs).map(({ source }) => imported(source)));
|
|
637
|
+
const endpoints = (await Promise.all(manifest.endpoints.map(({ source }) => imported(source)))).filter((value) => Endpoint.isEndpoint(value));
|
|
638
|
+
const subscribers = (await Promise.all((manifest.subscribers ?? []).map(async ({ source }) => ({
|
|
639
|
+
name: source.export,
|
|
640
|
+
subscriber: await imported(source)
|
|
641
|
+
})))).filter((entry) => entry.subscriber?.__IS_SUBSCRIBER__ === true);
|
|
642
|
+
const unique = (values) => [...new Set(values)];
|
|
643
|
+
const databases = unique(constructs.filter((value) => value instanceof KyselyDatabase));
|
|
644
|
+
const auths = unique(constructs.filter((value) => value instanceof BetterAuth));
|
|
645
|
+
const emails = unique(constructs.filter((value) => value instanceof Email));
|
|
646
|
+
const consumables = unique(constructs.filter(isConsumable));
|
|
647
|
+
const channels = unique(constructs.filter((value) => value instanceof Topic || value instanceof Queue));
|
|
648
|
+
const inbox = emails.map((email) => manifest.env[provideKey(email.id, "inboxUrl")]).find(Boolean);
|
|
649
|
+
return {
|
|
650
|
+
envParser,
|
|
651
|
+
endpoints,
|
|
652
|
+
databases,
|
|
653
|
+
auths,
|
|
654
|
+
emails,
|
|
655
|
+
channels,
|
|
656
|
+
consumables,
|
|
657
|
+
subscribers,
|
|
658
|
+
...inbox ? { readMail: createMailbox({ inbox }) } : {}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* A publisher that records rather than sends, under the name a topic or queue
|
|
663
|
+
* is injected by — `services.users` — which is also the one `.event(users, …)`
|
|
664
|
+
* publishes through.
|
|
665
|
+
*/
|
|
666
|
+
function recorders(channels, state) {
|
|
667
|
+
return channels.map((channel) => {
|
|
668
|
+
const publisher = { async publish(messages) {
|
|
669
|
+
const sent = messages.map(({ type, payload }) => ({
|
|
670
|
+
type,
|
|
671
|
+
payload
|
|
672
|
+
}));
|
|
673
|
+
state.published.set(channel.id, [...state.published.get(channel.id) ?? [], ...sent]);
|
|
674
|
+
state.pending.push({
|
|
675
|
+
channel,
|
|
676
|
+
messages: sent
|
|
677
|
+
});
|
|
678
|
+
} };
|
|
679
|
+
return {
|
|
680
|
+
serviceName: channel.service.serviceName,
|
|
681
|
+
register: () => publisher
|
|
682
|
+
};
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The databases a test is handed: the app's own. A schema tenant an auth server
|
|
687
|
+
* owns is reached through that server, as the app reaches it, and a reader is
|
|
688
|
+
* the same database through a read-only role — neither is another database to
|
|
689
|
+
* test against.
|
|
690
|
+
*/
|
|
691
|
+
function ownDatabases(app, manifest) {
|
|
692
|
+
const owners = new Set(app.auths.map((auth) => auth.databaseId));
|
|
693
|
+
return app.databases.filter((database) => !owners.has(database.id) && manifest.constructs[database.id]?.kind !== "database-reader");
|
|
694
|
+
}
|
|
695
|
+
/** Each factory's database, found by the service name it is keyed by. */
|
|
696
|
+
function databasesFor(factories, databases) {
|
|
697
|
+
return Object.keys(factories).map((name) => {
|
|
698
|
+
const database = databases.find((candidate) => candidate.service.serviceName === name);
|
|
699
|
+
if (!database) throw new UnknownFactory(name, databases.map((candidate) => candidate.service.serviceName));
|
|
700
|
+
return [name, database];
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Make a database resolve, inside a test, to that test's transaction.
|
|
705
|
+
*
|
|
706
|
+
* Everything reaches a database through its service — an endpoint through
|
|
707
|
+
* service discovery, the auth server through its tenant directly — so this is
|
|
708
|
+
* the one place a test's connection can be handed over. Outside a test it is
|
|
709
|
+
* the database it always was.
|
|
710
|
+
*/
|
|
711
|
+
/** Rounds of delivery before a chain of consumers is called a loop. */
|
|
712
|
+
const MAX_DELIVERY_ROUNDS = 25;
|
|
713
|
+
/**
|
|
714
|
+
* Deliver what this test published, in-process, as the broker would — and
|
|
715
|
+
* keep delivering what the consumers publish in turn, until nothing is left.
|
|
716
|
+
*
|
|
717
|
+
* - A queue's messages go to its one consumer, as a batch.
|
|
718
|
+
* - A topic's events go to every subscriber that named their type, and only
|
|
719
|
+
* those: fan-out, as the filter policy (SNS) or the per-subscriber queue
|
|
720
|
+
* (pg-boss) does it.
|
|
721
|
+
* - Each payload is checked against the consumer's schema first. Turning an
|
|
722
|
+
* SNS envelope or an SQS record into `{ type, payload }` is each adaptor's
|
|
723
|
+
* job and tested there; what is tested here is what the handler is handed.
|
|
724
|
+
* - Consumers run as the server side of this test, so their databases are
|
|
725
|
+
* this test's transactions and their writes roll back with it.
|
|
726
|
+
* - A consumer that throws fails the test. Deployed, the message would be
|
|
727
|
+
* retried; here a retry would only hide the bug.
|
|
728
|
+
*/
|
|
729
|
+
async function deliver(app, state, id) {
|
|
730
|
+
if (state.delivering) return;
|
|
731
|
+
state.delivering = true;
|
|
732
|
+
try {
|
|
733
|
+
for (let round = 0; state.pending.length > 0; round++) {
|
|
734
|
+
if (round === MAX_DELIVERY_ROUNDS) throw new DeliveryDidNotSettle(MAX_DELIVERY_ROUNDS, [...new Set(state.pending.map(({ channel }) => channel.id))]);
|
|
735
|
+
for (const { channel, messages } of state.pending.splice(0)) if (channel instanceof Queue) await toQueue(channel, messages, state, id);
|
|
736
|
+
else await toSubscribers(channel, messages, app, state, id);
|
|
737
|
+
}
|
|
738
|
+
} finally {
|
|
739
|
+
state.delivering = false;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
async function toQueue(queue, messages, state, id) {
|
|
743
|
+
const payloads = [];
|
|
744
|
+
for (const message of messages) payloads.push(await accepted(queue.messageSchema, message, `queue '${queue.name}'`));
|
|
745
|
+
await runAsServer(id, () => new TestQueueAdaptor(queue, state.discovery).invoke({ messages: payloads })).catch((error) => {
|
|
746
|
+
throw new DeliveryFailed(`queue '${queue.name}'`, messages, error);
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
async function toSubscribers(topic, messages, app, state, id) {
|
|
750
|
+
for (const { name, subscriber } of app.subscribers) {
|
|
751
|
+
if (subscriber.topicName !== topic.name) continue;
|
|
752
|
+
const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
|
|
753
|
+
if (named.length === 0) continue;
|
|
754
|
+
const consumer = `subscriber '${name}'`;
|
|
755
|
+
const events = [];
|
|
756
|
+
for (const message of named) {
|
|
757
|
+
const schema = topic.eventSchemas[message.type];
|
|
758
|
+
events.push({
|
|
759
|
+
type: message.type,
|
|
760
|
+
payload: await accepted(schema, message, consumer)
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
await runAsServer(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events })).catch((error) => {
|
|
764
|
+
throw new DeliveryFailed(consumer, named, error);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
/** The payload, if the consumer's schema takes it — what the handler is handed. */
|
|
769
|
+
async function accepted(schema, message, consumer) {
|
|
770
|
+
const standard = schema?.["~standard"];
|
|
771
|
+
if (!standard) return message.payload;
|
|
772
|
+
const result = await standard.validate(message.payload);
|
|
773
|
+
if (result.issues) throw new MessageRejected(consumer, message, result.issues);
|
|
774
|
+
return result.value;
|
|
775
|
+
}
|
|
776
|
+
/** `fetch`, delivering what the test published once each of its requests answers. */
|
|
777
|
+
function deliveringFetch(inner, settle) {
|
|
778
|
+
return async (input, init) => {
|
|
779
|
+
const context = currentTestContext();
|
|
780
|
+
const response = await inner(input, init);
|
|
781
|
+
if (context?.side === "client") await settle(context.id);
|
|
782
|
+
return response;
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
/** An adaptor whose `invoke` delivers what it published before returning. */
|
|
786
|
+
function thenDeliver(adaptor, settle) {
|
|
787
|
+
const invoke = adaptor.invoke.bind(adaptor);
|
|
788
|
+
adaptor.invoke = (async (...args) => {
|
|
789
|
+
const result = await invoke(...args);
|
|
790
|
+
await settle();
|
|
791
|
+
return result;
|
|
792
|
+
});
|
|
793
|
+
return adaptor;
|
|
794
|
+
}
|
|
795
|
+
function bindToTests(database) {
|
|
796
|
+
if (bound.has(database)) return;
|
|
797
|
+
bound.add(database);
|
|
798
|
+
const service = database.service;
|
|
799
|
+
const register = service.register;
|
|
800
|
+
service.register = (options) => {
|
|
801
|
+
const context = currentTestContext();
|
|
802
|
+
const state = context && contexts.get(context.id);
|
|
803
|
+
if (!state) return register(options);
|
|
804
|
+
return state.transactions.get(database.id, urlOf(database, options.envParser), database.clientConfig);
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
function urlOf(database, envParser) {
|
|
808
|
+
return envParser.create((get) => ({ url: get(provideKey(database.id, "url")).string() })).parse().url;
|
|
809
|
+
}
|
|
810
|
+
/** Each surface's endpoints, served at its URL for the test that asked. */
|
|
811
|
+
function surfaceHandlers(endpoints, env) {
|
|
812
|
+
const bySurface = /* @__PURE__ */ new Map();
|
|
813
|
+
for (const endpoint of endpoints) {
|
|
814
|
+
const surface = endpoint.surface?.id;
|
|
815
|
+
if (!surface) continue;
|
|
816
|
+
bySurface.set(surface, [...bySurface.get(surface) ?? [], endpoint]);
|
|
817
|
+
}
|
|
818
|
+
return [...bySurface].flatMap(([surface, served]) => {
|
|
819
|
+
const base = env[provideKey(surface, "url")];
|
|
820
|
+
if (!base) return [];
|
|
821
|
+
return http.all(`${trim(base)}/*`, ({ request }) => serve(request, async (state) => {
|
|
822
|
+
let app = state.surfaces.get(surface);
|
|
823
|
+
if (!app) {
|
|
824
|
+
app = Promise.resolve().then(() => {
|
|
825
|
+
const hono = new Hono();
|
|
826
|
+
HonoEndpoint.addRoutes(served, state.discovery, hono);
|
|
827
|
+
return hono;
|
|
828
|
+
});
|
|
829
|
+
state.surfaces.set(surface, app);
|
|
830
|
+
}
|
|
831
|
+
return (await app).fetch(request);
|
|
832
|
+
}));
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* An external API's app fake, answering at the URL the test stage resolved for
|
|
837
|
+
* it — so a handler that calls Polar calls the fake, and the test sets up
|
|
838
|
+
* nothing.
|
|
839
|
+
*
|
|
840
|
+
* Not per test, unlike a surface: a fake stands in for somebody else's server,
|
|
841
|
+
* which no test's transaction reaches. An image fake has no handler here — its
|
|
842
|
+
* container answers on localhost, which is let through.
|
|
843
|
+
*/
|
|
844
|
+
function fakeHandler(id, fake, env) {
|
|
845
|
+
const base = env[provideKey(id, "url")];
|
|
846
|
+
if (fake.kind !== "app" || !base) return [];
|
|
847
|
+
return [http.all(`${trim(base)}/*`, ({ request }) => fake.handler.fetch(request))];
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* A construct's client for this test, by service name — through the test's own
|
|
851
|
+
* discovery, so a topic or queue is its recorder and a database its
|
|
852
|
+
* transaction, exactly as the test's endpoints get them.
|
|
853
|
+
*/
|
|
854
|
+
async function resolveService(app, state, name) {
|
|
855
|
+
const construct = app.consumables.find((candidate) => candidate.service.serviceName === name);
|
|
856
|
+
if (!construct) throw new UnknownService(name, app.consumables.map((candidate) => candidate.service.serviceName));
|
|
857
|
+
return (await state.discovery.register([construct.service]))[name];
|
|
858
|
+
}
|
|
859
|
+
/** An auth server, served at its URL, on the transaction of the test that asked. */
|
|
860
|
+
function authHandler(auth, env, envParser) {
|
|
861
|
+
const base = trim(env[provideKey(auth.id, "url")] ?? "");
|
|
862
|
+
return http.all(`${base}/*`, ({ request }) => serve(request, async (state) => {
|
|
863
|
+
let app = state.auth.get(auth);
|
|
864
|
+
if (!app) {
|
|
865
|
+
app = auth.server({
|
|
866
|
+
envParser,
|
|
867
|
+
context: serviceContext
|
|
868
|
+
}).then(({ app }) => app);
|
|
869
|
+
state.auth.set(auth, app);
|
|
870
|
+
}
|
|
871
|
+
return (await app).fetch(request);
|
|
872
|
+
}));
|
|
873
|
+
}
|
|
874
|
+
/** Handle a request as the server side of the test it was made for. */
|
|
875
|
+
async function serve(request, handle) {
|
|
876
|
+
const id = testContextOf(request);
|
|
877
|
+
const state = id ? contexts.get(id) : void 0;
|
|
878
|
+
if (!id || !state) throw new UnknownTestContext(request.url, id);
|
|
879
|
+
return runAsServer(id, () => handle(state));
|
|
880
|
+
}
|
|
881
|
+
function trim(url) {
|
|
882
|
+
return url.replace(/\/$/, "");
|
|
883
|
+
}
|
|
884
|
+
function isLocal(url) {
|
|
885
|
+
return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname.endsWith(".localhost");
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Sign a test's browser in the way a person does: ask the auth server for a
|
|
889
|
+
* magic link, open the email it sent, follow the link.
|
|
890
|
+
*
|
|
891
|
+
* What the generated `browser.signIn(email)` calls. The address's mail is
|
|
892
|
+
* cleared first — so the link is this request's, not one an earlier test left
|
|
893
|
+
* — and cleared again after the test, like any address a test reads. Returns
|
|
894
|
+
* the session the auth server then reports, as better-auth hands it back.
|
|
895
|
+
*/
|
|
896
|
+
async function signInWithMagicLink(browser, auth, email = freshAddress()) {
|
|
897
|
+
const context = currentTestContext();
|
|
898
|
+
const state = context && contexts.get(context.id);
|
|
899
|
+
if (!state) throw new UnknownTestContext("signIn", context?.id);
|
|
900
|
+
if (!state.mailbox) throw new NoInbox();
|
|
901
|
+
const inbox = state.mailbox(email);
|
|
902
|
+
await inbox.clear();
|
|
903
|
+
const requested = await auth.signIn.magicLink({ email });
|
|
904
|
+
if (requested.error) throw new SignInFailed(email, `the auth server refused the magic link: ${requested.error.message ?? "no reason given"}`);
|
|
905
|
+
const mail = await inbox.last();
|
|
906
|
+
if (!mail.link) throw new SignInFailed(email, "its email held no link");
|
|
907
|
+
await browser.visit(mail.link);
|
|
908
|
+
const { data } = await auth.getSession();
|
|
909
|
+
if (!data) throw new SignInFailed(email, "the auth server reported no session after the link was opened");
|
|
910
|
+
return data;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* An address nobody else signs in as — what `browser.signIn()` uses when the
|
|
914
|
+
* test does not care who it is.
|
|
915
|
+
*
|
|
916
|
+
* Unique rather than only seeded: tests in other files run at the same time,
|
|
917
|
+
* against the same Mailpit and the same unique columns, and a seeded address
|
|
918
|
+
* repeats wherever two tests share a name. The readable half is the seeded
|
|
919
|
+
* faker's, so a failure still names somebody.
|
|
920
|
+
*/
|
|
921
|
+
function freshAddress() {
|
|
922
|
+
return `${faker.internet.username().toLowerCase().replace(/[^a-z0-9]/g, "")}.${randomUUID().slice(0, 8)}@example.test`;
|
|
923
|
+
}
|
|
924
|
+
/** `browser.signIn` finished without a session. */
|
|
925
|
+
var SignInFailed = class extends Error {
|
|
926
|
+
email;
|
|
927
|
+
reason;
|
|
928
|
+
constructor(email, reason) {
|
|
929
|
+
super(`Signing ${email} in failed: ${reason}.`);
|
|
930
|
+
this.email = email;
|
|
931
|
+
this.reason = reason;
|
|
932
|
+
this.name = "SignInFailed";
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
/** A request reached an in-process server without a test to belong to. */
|
|
936
|
+
var UnknownTestContext = class extends Error {
|
|
937
|
+
url;
|
|
938
|
+
id;
|
|
939
|
+
constructor(url, id) {
|
|
940
|
+
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.`);
|
|
941
|
+
this.url = url;
|
|
942
|
+
this.id = id;
|
|
943
|
+
this.name = "UnknownTestContext";
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
/** `mailbox` was used in an app that declares no Email construct. */
|
|
947
|
+
var NoInbox = class extends Error {
|
|
948
|
+
constructor() {
|
|
949
|
+
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.");
|
|
950
|
+
this.name = "NoInbox";
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
/** `db.get(name)` named no database the test is handed. */
|
|
954
|
+
var UnknownDatabase = class extends Error {
|
|
955
|
+
database;
|
|
956
|
+
known;
|
|
957
|
+
constructor(database, known) {
|
|
958
|
+
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.");
|
|
959
|
+
this.database = database;
|
|
960
|
+
this.known = known;
|
|
961
|
+
this.name = "UnknownDatabase";
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
/** A factory keyed by a service name no database the app declares has. */
|
|
965
|
+
var UnknownFactory = class extends Error {
|
|
966
|
+
factory;
|
|
967
|
+
known;
|
|
968
|
+
constructor(factory, known) {
|
|
969
|
+
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.`);
|
|
970
|
+
this.factory = factory;
|
|
971
|
+
this.known = known;
|
|
972
|
+
this.name = "UnknownFactory";
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
/** A published message the consumer's own schema refuses. */
|
|
976
|
+
var MessageRejected = class extends Error {
|
|
977
|
+
consumer;
|
|
978
|
+
published;
|
|
979
|
+
issues;
|
|
980
|
+
constructor(consumer, published, issues) {
|
|
981
|
+
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.`);
|
|
982
|
+
this.consumer = consumer;
|
|
983
|
+
this.published = published;
|
|
984
|
+
this.issues = issues;
|
|
985
|
+
this.name = "MessageRejected";
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
/** A consumer that threw while handling what the test published. */
|
|
989
|
+
var DeliveryFailed = class extends Error {
|
|
990
|
+
consumer;
|
|
991
|
+
messages;
|
|
992
|
+
cause;
|
|
993
|
+
constructor(consumer, messages, cause) {
|
|
994
|
+
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 });
|
|
995
|
+
this.consumer = consumer;
|
|
996
|
+
this.messages = messages;
|
|
997
|
+
this.cause = cause;
|
|
998
|
+
this.name = "DeliveryFailed";
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
/** Consumers that kept publishing to each other without settling. */
|
|
1002
|
+
var DeliveryDidNotSettle = class extends Error {
|
|
1003
|
+
rounds;
|
|
1004
|
+
channels;
|
|
1005
|
+
constructor(rounds, channels) {
|
|
1006
|
+
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.`);
|
|
1007
|
+
this.rounds = rounds;
|
|
1008
|
+
this.channels = channels;
|
|
1009
|
+
this.name = "DeliveryDidNotSettle";
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
/** `services.get(name)` for a name no construct of the app is served by. */
|
|
1013
|
+
var UnknownService = class extends Error {
|
|
1014
|
+
serviceName;
|
|
1015
|
+
available;
|
|
1016
|
+
constructor(serviceName, available) {
|
|
1017
|
+
super(`The app declares no construct served as '${serviceName}'. Its services are: ${available.join(", ") || "none"}.`);
|
|
1018
|
+
this.serviceName = serviceName;
|
|
1019
|
+
this.available = available;
|
|
1020
|
+
this.name = "UnknownService";
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
//#endregion
|
|
1024
|
+
export { DeliveryDidNotSettle, DeliveryFailed, MessageRejected, NoInbox, NoTestManifest, SignInFailed, TEST_CONTEXT_HEADER, TEST_MANIFEST_ENV, TestEndpointAdaptor, TestFunctionAdaptor, TestQueueAdaptor, TestSubscriberAdaptor, UnknownDatabase, UnknownFactory, UnknownService, UnknownTestContext, createMswHandlers, featureTest, loadTestManifest, signInWithMagicLink };
|
|
1025
|
+
|
|
428
1026
|
//# sourceMappingURL=testing.mjs.map
|