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