@geekmidas/constructs 10.0.0-alpha.17 → 10.0.0-alpha.171
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 +246 -158
- package/dist/Construct-127M7yrl.d.cts +231 -0
- package/dist/Construct-127M7yrl.d.cts.map +1 -0
- package/dist/Construct-BMk_CRSD.d.mts +231 -0
- package/dist/Construct-BMk_CRSD.d.mts.map +1 -0
- package/dist/{Construct-BeYVu_QF.mjs → Construct-CGuc_Ijk.mjs} +8 -9
- package/dist/Construct-CGuc_Ijk.mjs.map +1 -0
- package/dist/{Construct-DqdlARxq.cjs → Construct-DorKS0Ua.cjs} +8 -9
- package/dist/Construct-DorKS0Ua.cjs.map +1 -0
- package/dist/{Cron-l4Wlz6G9.d.mts → Cron-BcA8F0S-.d.cts} +16 -9
- package/dist/Cron-BcA8F0S-.d.cts.map +1 -0
- package/dist/{Cron-zsoSAwZo.d.cts → Cron-z2CiuQT_.d.mts} +15 -8
- package/dist/Cron-z2CiuQT_.d.mts.map +1 -0
- package/dist/{CronBuilder-D_0HNBTr.mjs → CronBuilder-BJ5LoadF.mjs} +28 -11
- package/dist/CronBuilder-BJ5LoadF.mjs.map +1 -0
- package/dist/CronBuilder-BZvo34X2.d.cts +47 -0
- package/dist/CronBuilder-BZvo34X2.d.cts.map +1 -0
- package/dist/{CronBuilder-BdnI6lxF.cjs → CronBuilder-B_NSP-Y5.cjs} +27 -10
- package/dist/CronBuilder-B_NSP-Y5.cjs.map +1 -0
- package/dist/CronBuilder-BbgKo8OI.d.mts +47 -0
- package/dist/CronBuilder-BbgKo8OI.d.mts.map +1 -0
- package/dist/Endpoint-52z1P0Ue.cjs +581 -0
- package/dist/Endpoint-52z1P0Ue.cjs.map +1 -0
- package/dist/{Endpoint-oS-Fe3d_.d.mts → Endpoint-CIDUreMW.d.mts} +104 -23
- package/dist/Endpoint-CIDUreMW.d.mts.map +1 -0
- package/dist/{Endpoint-DBflWAe4.d.cts → Endpoint-COisi9jw.d.cts} +101 -20
- package/dist/Endpoint-COisi9jw.d.cts.map +1 -0
- package/dist/Endpoint-sUOU7uLx.mjs +552 -0
- package/dist/Endpoint-sUOU7uLx.mjs.map +1 -0
- package/dist/{EndpointFactory-Bm3aKRdV.mjs → EndpointFactory-Bzi9Sl7r.mjs} +269 -53
- package/dist/EndpointFactory-Bzi9Sl7r.mjs.map +1 -0
- package/dist/{index-Cc4kKPag.d.mts → EndpointFactory-CIM80WIK.d.mts} +189 -106
- package/dist/EndpointFactory-CIM80WIK.d.mts.map +1 -0
- package/dist/{index-C1ZwNOOk.d.cts → EndpointFactory-CfBg6jJE.d.cts} +187 -104
- package/dist/EndpointFactory-CfBg6jJE.d.cts.map +1 -0
- package/dist/{EndpointFactory-CLvWuHyt.cjs → EndpointFactory-Cf_Cs1ym.cjs} +309 -51
- package/dist/EndpointFactory-Cf_Cs1ym.cjs.map +1 -0
- package/dist/Function-BIEsY0Hm.d.cts +76 -0
- package/dist/Function-BIEsY0Hm.d.cts.map +1 -0
- package/dist/Function-BKReud5p.d.mts +76 -0
- package/dist/Function-BKReud5p.d.mts.map +1 -0
- package/dist/{HonoEndpointAdaptor-92zavCsV.cjs → HonoEndpointAdaptor-BTbqfSaa.cjs} +115 -41
- package/dist/HonoEndpointAdaptor-BTbqfSaa.cjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-yYaU7jVJ.mjs → HonoEndpointAdaptor-CBVey2cY.mjs} +112 -38
- package/dist/HonoEndpointAdaptor-CBVey2cY.mjs.map +1 -0
- package/dist/ObjectSubscriberBuilder-Ci_Cc-WZ.d.mts +129 -0
- package/dist/ObjectSubscriberBuilder-Ci_Cc-WZ.d.mts.map +1 -0
- package/dist/ObjectSubscriberBuilder-DWtLxfAJ.d.cts +129 -0
- package/dist/ObjectSubscriberBuilder-DWtLxfAJ.d.cts.map +1 -0
- package/dist/ProcessorBuilder-CdLwJK4k.d.mts +216 -0
- package/dist/ProcessorBuilder-CdLwJK4k.d.mts.map +1 -0
- package/dist/ProcessorBuilder-ClD7tmEe.d.cts +216 -0
- package/dist/ProcessorBuilder-ClD7tmEe.d.cts.map +1 -0
- package/dist/Queue-9Hh20ZCk.mjs +104 -0
- package/dist/Queue-9Hh20ZCk.mjs.map +1 -0
- package/dist/{Queue-D9X6OoON.d.mts → Queue-B8HGg439.d.mts} +42 -41
- package/dist/Queue-B8HGg439.d.mts.map +1 -0
- package/dist/{Queue-DYPB2KWL.d.cts → Queue-C4rijiM7.d.cts} +43 -42
- package/dist/Queue-C4rijiM7.d.cts.map +1 -0
- package/dist/Queue-W1wueijP.cjs +109 -0
- package/dist/Queue-W1wueijP.cjs.map +1 -0
- package/dist/QueueBuilder-BDcv9B71.cjs +135 -0
- package/dist/QueueBuilder-BDcv9B71.cjs.map +1 -0
- package/dist/QueueBuilder-CjULiiDN.d.mts +75 -0
- package/dist/QueueBuilder-CjULiiDN.d.mts.map +1 -0
- package/dist/QueueBuilder-CrZL8HHs.mjs +118 -0
- package/dist/QueueBuilder-CrZL8HHs.mjs.map +1 -0
- package/dist/QueueBuilder-Dacm9qAv.d.cts +75 -0
- package/dist/QueueBuilder-Dacm9qAv.d.cts.map +1 -0
- package/dist/Subscriber-5rCX1Nph.d.cts +83 -0
- package/dist/Subscriber-5rCX1Nph.d.cts.map +1 -0
- package/dist/Subscriber-CtQXhcL7.d.mts +83 -0
- package/dist/Subscriber-CtQXhcL7.d.mts.map +1 -0
- package/dist/SubscriberBuilder-CpFhShTJ.mjs +238 -0
- package/dist/SubscriberBuilder-CpFhShTJ.mjs.map +1 -0
- package/dist/SubscriberBuilder-DJEvNRdD.cjs +261 -0
- package/dist/SubscriberBuilder-DJEvNRdD.cjs.map +1 -0
- package/dist/Topic-BGoOeCT6.mjs +99 -0
- package/dist/Topic-BGoOeCT6.mjs.map +1 -0
- package/dist/Topic-DLCZBNwK.cjs +104 -0
- package/dist/Topic-DLCZBNwK.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +147 -168
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +57 -48
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +58 -49
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +142 -164
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/awsWebsocket.cjs +354 -0
- package/dist/adaptors/awsWebsocket.cjs.map +1 -0
- package/dist/adaptors/awsWebsocket.d.cts +156 -0
- package/dist/adaptors/awsWebsocket.d.cts.map +1 -0
- package/dist/adaptors/awsWebsocket.d.mts +156 -0
- package/dist/adaptors/awsWebsocket.d.mts.map +1 -0
- package/dist/adaptors/awsWebsocket.mjs +347 -0
- package/dist/adaptors/awsWebsocket.mjs.map +1 -0
- package/dist/adaptors/hono.cjs +1 -1
- package/dist/adaptors/hono.d.cts +8 -7
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +10 -9
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +1 -1
- package/dist/adaptors/testing.cjs +1174 -41
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +517 -40
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +517 -40
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +1140 -36
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth-CutSfNlr.d.mts +274 -0
- package/dist/auth-CutSfNlr.d.mts.map +1 -0
- package/dist/auth-b9ADezz9.d.cts +274 -0
- package/dist/auth-b9ADezz9.d.cts.map +1 -0
- package/dist/auth.cjs +311 -26
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -104
- package/dist/auth.d.mts +2 -104
- package/dist/auth.mjs +307 -28
- package/dist/auth.mjs.map +1 -1
- package/dist/cache-9wLNSy3O.d.cts +44 -0
- package/dist/cache-9wLNSy3O.d.cts.map +1 -0
- package/dist/cache-BFPs_CGs.d.mts +44 -0
- package/dist/cache-BFPs_CGs.d.mts.map +1 -0
- package/dist/cache.cjs +4 -20
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.cts +2 -43
- package/dist/cache.d.mts +2 -43
- package/dist/cache.mjs +4 -20
- package/dist/cache.mjs.map +1 -1
- 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/cipher-DSDxPRIp.d.cts +106 -0
- package/dist/cipher-DSDxPRIp.d.cts.map +1 -0
- package/dist/cipher-DSDxPRIp.d.mts +106 -0
- package/dist/cipher-DSDxPRIp.d.mts.map +1 -0
- package/dist/{construct-interface-DPlxfpoS.d.mts → construct-interface-CVoejIpo.d.cts} +79 -8
- package/dist/construct-interface-CVoejIpo.d.cts.map +1 -0
- package/dist/{construct-interface-DgXTJcOD.d.cts → construct-interface-Nw5Dt9AC.d.mts} +79 -8
- package/dist/construct-interface-Nw5Dt9AC.d.mts.map +1 -0
- package/dist/construct-interface.cjs +62 -4
- package/dist/construct-interface.cjs.map +1 -1
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +59 -5
- package/dist/construct-interface.mjs.map +1 -1
- package/dist/credential-B80mOxwT.mjs +222 -0
- package/dist/credential-B80mOxwT.mjs.map +1 -0
- package/dist/credential-RlgbzZAc.cjs +257 -0
- package/dist/credential-RlgbzZAc.cjs.map +1 -0
- package/dist/credential.cjs +7 -129
- package/dist/credential.d.cts +2 -58
- package/dist/credential.d.mts +2 -58
- package/dist/credential.mjs +2 -128
- package/dist/crons/index.cjs +127 -1
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +43 -3
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +43 -3
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +126 -2
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +3 -194
- package/dist/database/kysely.d.cts +2 -149
- package/dist/database/kysely.d.mts +2 -149
- package/dist/database/kysely.mjs +2 -192
- package/dist/email.cjs +24 -17
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +15 -5
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts +16 -6
- package/dist/email.d.mts.map +1 -1
- package/dist/email.mjs +23 -17
- package/dist/email.mjs.map +1 -1
- package/dist/encryption/kms.cjs +95 -0
- package/dist/encryption/kms.cjs.map +1 -0
- package/dist/encryption/kms.d.cts +7 -0
- package/dist/encryption/kms.d.cts.map +1 -0
- package/dist/encryption/kms.d.mts +7 -0
- package/dist/encryption/kms.d.mts.map +1 -0
- package/dist/encryption/kms.mjs +93 -0
- package/dist/encryption/kms.mjs.map +1 -0
- package/dist/encryption.cjs +116 -0
- package/dist/encryption.cjs.map +1 -0
- package/dist/encryption.d.cts +37 -0
- package/dist/encryption.d.cts.map +1 -0
- package/dist/encryption.d.mts +37 -0
- package/dist/encryption.d.mts.map +1 -0
- package/dist/encryption.mjs +101 -0
- package/dist/encryption.mjs.map +1 -0
- package/dist/endpoints/index.cjs +32 -10
- package/dist/endpoints/index.d.cts +106 -3
- package/dist/endpoints/index.d.cts.map +1 -0
- package/dist/endpoints/index.d.mts +106 -3
- package/dist/endpoints/index.d.mts.map +1 -0
- package/dist/endpoints/index.mjs +6 -4
- package/dist/expire-C586zznE.d.cts +38 -0
- package/dist/expire-C586zznE.d.cts.map +1 -0
- package/dist/expire-C586zznE.d.mts +38 -0
- package/dist/expire-C586zznE.d.mts.map +1 -0
- package/dist/external-api.cjs +106 -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 +103 -0
- package/dist/external-api.mjs.map +1 -0
- package/dist/fake-JI5uN1SF.d.cts +201 -0
- package/dist/fake-JI5uN1SF.d.cts.map +1 -0
- package/dist/fake-zpuXpBmY.d.mts +201 -0
- package/dist/fake-zpuXpBmY.d.mts.map +1 -0
- package/dist/file-server.cjs +170 -49
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +148 -16
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +148 -16
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +168 -51
- package/dist/file-server.mjs.map +1 -1
- package/dist/functions/index.cjs +1 -1
- package/dist/functions/index.d.cts +2 -1
- package/dist/functions/index.d.mts +2 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/{functions-C53GW2eQ.mjs → functions-BvIDQKAA.mjs} +117 -22
- package/dist/functions-BvIDQKAA.mjs.map +1 -0
- package/dist/{functions-B6qCvfmy.cjs → functions-DLF6-IK8.cjs} +122 -18
- package/dist/functions-DLF6-IK8.cjs.map +1 -0
- package/dist/inbox-CXLU7h_8.d.cts +195 -0
- package/dist/inbox-CXLU7h_8.d.cts.map +1 -0
- package/dist/inbox-DYFsLd9A.d.mts +195 -0
- package/dist/inbox-DYFsLd9A.d.mts.map +1 -0
- package/dist/inbox.cjs +291 -0
- package/dist/inbox.cjs.map +1 -0
- package/dist/inbox.d.cts +2 -0
- package/dist/inbox.d.mts +2 -0
- package/dist/inbox.mjs +283 -0
- package/dist/inbox.mjs.map +1 -0
- package/dist/index-BpE9_6l5.d.mts +115 -0
- package/dist/index-BpE9_6l5.d.mts.map +1 -0
- package/dist/{index-CeEtxDmK.d.cts → index-DdRjYhiJ.d.cts} +42 -2
- package/dist/{index-CeEtxDmK.d.cts.map → index-DdRjYhiJ.d.cts.map} +1 -1
- package/dist/{index-CeEtxDmK.d.mts → index-DdRjYhiJ.d.mts} +42 -2
- package/dist/{index-CeEtxDmK.d.mts.map → index-DdRjYhiJ.d.mts.map} +1 -1
- package/dist/index-zRChehJ9.d.cts +115 -0
- package/dist/index-zRChehJ9.d.cts.map +1 -0
- package/dist/index.cjs +4 -1
- package/dist/index.d.cts +26 -3
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +26 -3
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -2
- package/dist/kysely-5PAqFBzo.d.mts +216 -0
- package/dist/kysely-5PAqFBzo.d.mts.map +1 -0
- package/dist/kysely-Bc9xzaik.mjs +371 -0
- package/dist/kysely-Bc9xzaik.mjs.map +1 -0
- package/dist/kysely-D7f6J2lh.cjs +384 -0
- package/dist/kysely-D7f6J2lh.cjs.map +1 -0
- package/dist/kysely-lxNUBSTP.d.cts +216 -0
- package/dist/kysely-lxNUBSTP.d.cts.map +1 -0
- package/dist/{telemetry-DGcFlVpB.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +2 -2
- package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
- package/dist/{telemetry-DGcFlVpB.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +2 -2
- package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
- package/dist/mobile-app.cjs +79 -0
- package/dist/mobile-app.cjs.map +1 -0
- package/dist/mobile-app.d.cts +78 -0
- package/dist/mobile-app.d.cts.map +1 -0
- package/dist/mobile-app.d.mts +78 -0
- package/dist/mobile-app.d.mts.map +1 -0
- package/dist/mobile-app.mjs +78 -0
- package/dist/mobile-app.mjs.map +1 -0
- package/dist/object-storage.cjs +50 -7
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +37 -3
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +37 -3
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +49 -9
- package/dist/object-storage.mjs.map +1 -1
- package/dist/optionalPeers-D7Wt6dnF.mjs +140 -0
- package/dist/optionalPeers-D7Wt6dnF.mjs.map +1 -0
- package/dist/optionalPeers-DuNQXXe1.cjs +223 -0
- package/dist/optionalPeers-DuNQXXe1.cjs.map +1 -0
- package/dist/origins-BjxYht13.cjs +96 -0
- package/dist/origins-BjxYht13.cjs.map +1 -0
- package/dist/origins-Boc9qbo-.mjs +73 -0
- package/dist/origins-Boc9qbo-.mjs.map +1 -0
- package/dist/pattern-C1CEcglD.mjs +241 -0
- package/dist/pattern-C1CEcglD.mjs.map +1 -0
- package/dist/pattern-QFaUIr77.cjs +288 -0
- package/dist/pattern-QFaUIr77.cjs.map +1 -0
- package/dist/privateAddress-Bg5fUsbp.mjs +21 -0
- package/dist/privateAddress-Bg5fUsbp.mjs.map +1 -0
- package/dist/privateAddress-CqGyuFHn.cjs +26 -0
- package/dist/privateAddress-CqGyuFHn.cjs.map +1 -0
- package/dist/processors/index.cjs +214 -0
- package/dist/processors/index.cjs.map +1 -0
- package/dist/processors/index.d.cts +78 -0
- package/dist/processors/index.d.cts.map +1 -0
- package/dist/processors/index.d.mts +78 -0
- package/dist/processors/index.d.mts.map +1 -0
- package/dist/processors/index.mjs +193 -0
- package/dist/processors/index.mjs.map +1 -0
- package/dist/queue/index.cjs +5 -192
- package/dist/queue/index.d.cts +3 -53
- package/dist/queue/index.d.mts +3 -53
- package/dist/queue/index.mjs +3 -190
- package/dist/random-password.cjs +86 -0
- package/dist/random-password.cjs.map +1 -0
- package/dist/random-password.d.cts +30 -0
- package/dist/random-password.d.cts.map +1 -0
- package/dist/random-password.d.mts +30 -0
- package/dist/random-password.d.mts.map +1 -0
- package/dist/random-password.mjs +84 -0
- package/dist/random-password.mjs.map +1 -0
- package/dist/readOnlyStorage-C7bCe-z5.cjs +101 -0
- package/dist/readOnlyStorage-C7bCe-z5.cjs.map +1 -0
- package/dist/readOnlyStorage-DMCeLuS2.mjs +78 -0
- package/dist/readOnlyStorage-DMCeLuS2.mjs.map +1 -0
- package/dist/readRequestBody-BmKnPl0a.mjs +293 -0
- package/dist/readRequestBody-BmKnPl0a.mjs.map +1 -0
- package/dist/{lazyAccessors-Dx9NLwJZ.cjs → readRequestBody-CN9GVdeE.cjs} +141 -47
- package/dist/readRequestBody-CN9GVdeE.cjs.map +1 -0
- package/dist/{processAudits-D_2W5x8k.cjs → requestLogger-CnoYd-Ah.cjs} +63 -3
- package/dist/requestLogger-CnoYd-Ah.cjs.map +1 -0
- package/dist/{processAudits-BpRlPQMW.mjs → requestLogger-D2JS7pPM.mjs} +51 -3
- package/dist/requestLogger-D2JS7pPM.mjs.map +1 -0
- package/dist/rest-api.cjs +100 -73
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +83 -59
- package/dist/rest-api.d.cts.map +1 -1
- package/dist/rest-api.d.mts +83 -59
- package/dist/rest-api.d.mts.map +1 -1
- package/dist/rest-api.mjs +97 -76
- package/dist/rest-api.mjs.map +1 -1
- package/dist/runSubscriber-HEqXkin1.mjs +117 -0
- package/dist/runSubscriber-HEqXkin1.mjs.map +1 -0
- package/dist/runSubscriber-sVJfLA0-.cjs +134 -0
- package/dist/runSubscriber-sVJfLA0-.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 +140 -10
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +156 -3
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +156 -3
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +120 -13
- package/dist/site.mjs.map +1 -1
- package/dist/stages-DaTaoQei.d.cts +73 -0
- package/dist/stages-DaTaoQei.d.cts.map +1 -0
- package/dist/stages-DaTaoQei.d.mts +73 -0
- package/dist/stages-DaTaoQei.d.mts.map +1 -0
- package/dist/subscribers/index.cjs +134 -1
- package/dist/subscribers/index.cjs.map +1 -0
- package/dist/subscribers/index.d.cts +74 -3
- package/dist/subscribers/index.d.cts.map +1 -0
- package/dist/subscribers/index.d.mts +74 -3
- package/dist/subscribers/index.d.mts.map +1 -0
- package/dist/subscribers/index.mjs +132 -2
- package/dist/subscribers/index.mjs.map +1 -0
- package/dist/telemetry-BbLyS7ln.d.cts +57 -0
- package/dist/telemetry-BbLyS7ln.d.cts.map +1 -0
- package/dist/telemetry-DWX-qKUh.d.mts +57 -0
- package/dist/telemetry-DWX-qKUh.d.mts.map +1 -0
- package/dist/telemetry.cjs +64 -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 +63 -0
- package/dist/telemetry.mjs.map +1 -0
- package/dist/topic/index.cjs +2 -134
- package/dist/topic/index.d.cts +2 -3
- package/dist/topic/index.d.mts +2 -3
- package/dist/topic/index.mjs +2 -132
- package/dist/tracing-Bbj1uoFJ.mjs +127 -0
- package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
- package/dist/tracing-C0ooU0V2.cjs +150 -0
- package/dist/tracing-C0ooU0V2.cjs.map +1 -0
- package/dist/websocket-api-9ndLBolx.d.cts +1207 -0
- package/dist/websocket-api-9ndLBolx.d.cts.map +1 -0
- package/dist/websocket-api-BPPXF79i.d.mts +1207 -0
- package/dist/websocket-api-BPPXF79i.d.mts.map +1 -0
- package/dist/websocket-api-C6LGg9-D.mjs +1716 -0
- package/dist/websocket-api-C6LGg9-D.mjs.map +1 -0
- package/dist/websocket-api-CoKPJJRl.cjs +1895 -0
- package/dist/websocket-api-CoKPJJRl.cjs.map +1 -0
- package/dist/websocket-api.cjs +42 -0
- package/dist/websocket-api.d.cts +2 -0
- package/dist/websocket-api.d.mts +2 -0
- package/dist/websocket-api.mjs +3 -0
- package/dist/worker.cjs +174 -32
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +147 -47
- package/dist/worker.d.cts.map +1 -1
- package/dist/worker.d.mts +147 -47
- package/dist/worker.d.mts.map +1 -1
- package/dist/worker.mjs +175 -33
- package/dist/worker.mjs.map +1 -1
- package/package.json +180 -43
- package/dist/Construct-BeYVu_QF.mjs.map +0 -1
- package/dist/Construct-DfbwIntp.d.cts +0 -115
- package/dist/Construct-DfbwIntp.d.cts.map +0 -1
- package/dist/Construct-DqdlARxq.cjs.map +0 -1
- package/dist/Construct-l5aOn_jv.d.mts +0 -115
- package/dist/Construct-l5aOn_jv.d.mts.map +0 -1
- package/dist/Cron-l4Wlz6G9.d.mts.map +0 -1
- package/dist/Cron-zsoSAwZo.d.cts.map +0 -1
- package/dist/CronBuilder-BdnI6lxF.cjs.map +0 -1
- package/dist/CronBuilder-CyT71Nzg.d.cts +0 -41
- package/dist/CronBuilder-CyT71Nzg.d.cts.map +0 -1
- package/dist/CronBuilder-D_0HNBTr.mjs.map +0 -1
- package/dist/CronBuilder-UoNgFe8S.d.mts +0 -41
- package/dist/CronBuilder-UoNgFe8S.d.mts.map +0 -1
- package/dist/Endpoint-BpZHtJ2W.cjs +0 -1689
- package/dist/Endpoint-BpZHtJ2W.cjs.map +0 -1
- package/dist/Endpoint-DBflWAe4.d.cts.map +0 -1
- package/dist/Endpoint-ONsly_dq.mjs +0 -1671
- package/dist/Endpoint-ONsly_dq.mjs.map +0 -1
- package/dist/Endpoint-oS-Fe3d_.d.mts.map +0 -1
- package/dist/EndpointFactory-Bm3aKRdV.mjs.map +0 -1
- package/dist/EndpointFactory-CLvWuHyt.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-92zavCsV.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-yYaU7jVJ.mjs.map +0 -1
- package/dist/Queue-D9X6OoON.d.mts.map +0 -1
- package/dist/Queue-DYPB2KWL.d.cts.map +0 -1
- package/dist/Subscriber-C4heaAyO.d.mts +0 -51
- package/dist/Subscriber-C4heaAyO.d.mts.map +0 -1
- package/dist/Subscriber-CotDUELC.d.cts +0 -51
- package/dist/Subscriber-CotDUELC.d.cts.map +0 -1
- package/dist/SubscriberBuilder-BEv0eoHy.d.cts +0 -59
- package/dist/SubscriberBuilder-BEv0eoHy.d.cts.map +0 -1
- package/dist/SubscriberBuilder-C0ZEtGDI.cjs +0 -125
- package/dist/SubscriberBuilder-C0ZEtGDI.cjs.map +0 -1
- package/dist/SubscriberBuilder-h7B_cHMr.mjs +0 -114
- package/dist/SubscriberBuilder-h7B_cHMr.mjs.map +0 -1
- package/dist/SubscriberBuilder-tyH5yTk5.d.mts +0 -59
- package/dist/SubscriberBuilder-tyH5yTk5.d.mts.map +0 -1
- package/dist/Topic-DEVGo0Dm.d.cts +0 -89
- package/dist/Topic-DEVGo0Dm.d.cts.map +0 -1
- package/dist/Topic-zk_6Gthr.d.mts +0 -89
- package/dist/Topic-zk_6Gthr.d.mts.map +0 -1
- package/dist/auth.d.cts.map +0 -1
- package/dist/auth.d.mts.map +0 -1
- package/dist/cache.d.cts.map +0 -1
- package/dist/cache.d.mts.map +0 -1
- package/dist/construct-interface-DPlxfpoS.d.mts.map +0 -1
- package/dist/construct-interface-DgXTJcOD.d.cts.map +0 -1
- package/dist/credential.cjs.map +0 -1
- package/dist/credential.d.cts.map +0 -1
- package/dist/credential.d.mts.map +0 -1
- package/dist/credential.mjs.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-B6qCvfmy.cjs.map +0 -1
- package/dist/functions-C53GW2eQ.mjs.map +0 -1
- package/dist/index-B2urf3YI.d.cts +0 -26
- package/dist/index-B2urf3YI.d.cts.map +0 -1
- package/dist/index-C1ZwNOOk.d.cts.map +0 -1
- package/dist/index-Cc4kKPag.d.mts.map +0 -1
- package/dist/index-DMCDvnsM.d.mts +0 -26
- package/dist/index-DMCDvnsM.d.mts.map +0 -1
- package/dist/index-D_frT6MP.d.cts +0 -165
- package/dist/index-D_frT6MP.d.cts.map +0 -1
- package/dist/index-DcyIYbDS.d.mts +0 -165
- package/dist/index-DcyIYbDS.d.mts.map +0 -1
- package/dist/lazyAccessors-BHtcqgz2.mjs +0 -211
- package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
- package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
- package/dist/processAudits-BpRlPQMW.mjs.map +0 -1
- package/dist/processAudits-D_2W5x8k.cjs.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/telemetry-DGcFlVpB.d.cts.map +0 -1
- package/dist/telemetry-DGcFlVpB.d.mts.map +0 -1
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.mjs.map +0 -1
|
@@ -1,22 +1,67 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-y5ARvAq5.cjs");
|
|
3
|
+
const require_construct_interface = require("../construct-interface.cjs");
|
|
4
|
+
const require_optionalPeers = require("../optionalPeers-DuNQXXe1.cjs");
|
|
5
|
+
const require_auth = require("../auth.cjs");
|
|
6
|
+
const require_functions = require("../functions-DLF6-IK8.cjs");
|
|
7
|
+
const require_Endpoint = require("../Endpoint-52z1P0Ue.cjs");
|
|
8
|
+
const require_websocket_api = require("../websocket-api-CoKPJJRl.cjs");
|
|
9
|
+
const require_Queue = require("../Queue-W1wueijP.cjs");
|
|
10
|
+
const require_email = require("../email.cjs");
|
|
11
|
+
const require_Topic = require("../Topic-DLCZBNwK.cjs");
|
|
12
|
+
const require_kysely = require("../kysely-D7f6J2lh.cjs");
|
|
13
|
+
const require_readRequestBody = require("../readRequestBody-CN9GVdeE.cjs");
|
|
14
|
+
const require_HonoEndpointAdaptor = require("../HonoEndpointAdaptor-BTbqfSaa.cjs");
|
|
15
|
+
const require_requestLogger = require("../requestLogger-CnoYd-Ah.cjs");
|
|
16
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
17
|
+
let node_crypto = require("node:crypto");
|
|
18
|
+
let _geekmidas_services = require("@geekmidas/services");
|
|
7
19
|
let _geekmidas_errors = require("@geekmidas/errors");
|
|
8
20
|
let _geekmidas_envkit = require("@geekmidas/envkit");
|
|
9
|
-
let _geekmidas_services = require("@geekmidas/services");
|
|
10
21
|
let hono = require("hono");
|
|
11
|
-
let
|
|
22
|
+
let _geekmidas_testkit_context = require("@geekmidas/testkit/context");
|
|
12
23
|
let msw = require("msw");
|
|
13
|
-
|
|
24
|
+
let _geekmidas_testkit_browser = require("@geekmidas/testkit/browser");
|
|
25
|
+
let _geekmidas_testkit_faker = require("@geekmidas/testkit/faker");
|
|
26
|
+
let _geekmidas_testkit_mailbox = require("@geekmidas/testkit/mailbox");
|
|
27
|
+
let _geekmidas_testkit_transactions = require("@geekmidas/testkit/transactions");
|
|
28
|
+
let msw_node = require("msw/node");
|
|
29
|
+
let vitest = require("vitest");
|
|
30
|
+
let node_fs = require("node:fs");
|
|
31
|
+
let node_tls = require("node:tls");
|
|
32
|
+
node_tls = require_rolldown_runtime.__toESM(node_tls, 1);
|
|
33
|
+
let node_url = require("node:url");
|
|
34
|
+
//#region src/testing/peer.ts
|
|
14
35
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
36
|
+
* The TCP peer a test's in-process requests arrive from.
|
|
37
|
+
*
|
|
38
|
+
* A feature test hands a request straight to a surface's Hono app — no
|
|
39
|
+
* socket, no server — so the app's bindings have no peer to read. Deployed,
|
|
40
|
+
* every request has one, and what a surface trusts follows from it: the auth
|
|
41
|
+
* server honours `x-gkm-client-ip` only from an internal caller, a loopback
|
|
42
|
+
* or private peer with no `Origin` and no forwarding header. With no peer at
|
|
43
|
+
* all the header was dropped, and every test's session check became the same
|
|
44
|
+
* client to Better Auth's rate limiter.
|
|
45
|
+
*
|
|
46
|
+
* So an in-process dispatch says where it came from, the way
|
|
47
|
+
* `@hono/node-server` does: its bindings carry `incoming.socket.remoteAddress`.
|
|
48
|
+
* The address is loopback because that is the truth — the request came from
|
|
49
|
+
* this process. A browser's own address still travels in its
|
|
50
|
+
* `x-forwarded-for`, which makes it outside traffic exactly as it would be
|
|
51
|
+
* behind the stack's proxy.
|
|
52
|
+
*
|
|
53
|
+
* Only a test's dispatch passes these. A runtime with no socket of its own
|
|
54
|
+
* (Lambda, Bun) still has no peer, and a request with no peer is still not an
|
|
55
|
+
* internal caller's.
|
|
18
56
|
*/
|
|
19
|
-
|
|
57
|
+
/** The address an in-process request presents as its peer. */
|
|
58
|
+
const IN_PROCESS_PEER_ADDRESS = "127.0.0.1";
|
|
59
|
+
/** Bindings for `app.fetch(request, bindings)` from inside this process. */
|
|
60
|
+
function inProcessBindings() {
|
|
61
|
+
return { incoming: { socket: { remoteAddress: IN_PROCESS_PEER_ADDRESS } } };
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/endpoints/MswEndpointAdaptor.ts
|
|
20
65
|
const MSW_HTTP_METHODS = [
|
|
21
66
|
"get",
|
|
22
67
|
"post",
|
|
@@ -64,7 +109,6 @@ function createMswHandlers(endpoints, options) {
|
|
|
64
109
|
break;
|
|
65
110
|
}
|
|
66
111
|
}
|
|
67
|
-
if (ctxOptions.publisher) serviceDefs.push(ctxOptions.publisher);
|
|
68
112
|
if (ctxOptions.auditorStorage !== void 0) {
|
|
69
113
|
for (const endpoint of endpoints) if (endpoint.auditorStorageService) {
|
|
70
114
|
serviceDefs.push({
|
|
@@ -84,18 +128,18 @@ function createMswHandlers(endpoints, options) {
|
|
|
84
128
|
const mswUrl = `${baseURL}${endpoint.route}`;
|
|
85
129
|
const mswMethod = msw.http[method];
|
|
86
130
|
handlers.push(mswMethod(mswUrl, async ({ request }) => {
|
|
87
|
-
const contextId = request.headers.get(TEST_CONTEXT_HEADER);
|
|
131
|
+
const contextId = request.headers.get(_geekmidas_testkit_context.TEST_CONTEXT_HEADER);
|
|
88
132
|
const ctx = contextId ? contexts.get(contextId) : void 0;
|
|
89
133
|
if (!ctx) return new Response(JSON.stringify({
|
|
90
134
|
error: "Missing or unknown test context ID",
|
|
91
|
-
hint: `Set the '${TEST_CONTEXT_HEADER}' header to a registered context ID`
|
|
135
|
+
hint: `Set the '${_geekmidas_testkit_context.TEST_CONTEXT_HEADER}' header to a registered context ID`
|
|
92
136
|
}), {
|
|
93
137
|
status: 500,
|
|
94
138
|
headers: { "content-type": "application/json" }
|
|
95
139
|
});
|
|
96
140
|
const app = new hono.Hono();
|
|
97
141
|
require_HonoEndpointAdaptor.HonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery, app);
|
|
98
|
-
const response = await app.request(request);
|
|
142
|
+
const response = await app.request(request, void 0, inProcessBindings());
|
|
99
143
|
return new Response(response.body, {
|
|
100
144
|
status: response.status,
|
|
101
145
|
statusText: response.statusText,
|
|
@@ -140,21 +184,21 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
140
184
|
const body = await this.endpoint.parseInput(ctx.body, "body");
|
|
141
185
|
const query = await this.endpoint.parseInput(ctx.query, "query");
|
|
142
186
|
const params = await this.endpoint.parseInput(ctx.params, "params");
|
|
143
|
-
const header =
|
|
144
|
-
const cookie =
|
|
187
|
+
const header = require_readRequestBody.createObjectHeaders(ctx.headers);
|
|
188
|
+
const cookie = require_readRequestBody.createCookieHeaderAccessor(ctx.headers.cookie);
|
|
145
189
|
const startTime = Date.now();
|
|
146
190
|
const requestId = ctx.requestId ?? ctx.headers["x-request-id"] ?? crypto.randomUUID();
|
|
147
|
-
|
|
191
|
+
let logger = require_requestLogger.requestLogger(this.endpoint, {
|
|
148
192
|
requestId,
|
|
149
|
-
|
|
150
|
-
host: ctx.headers.host,
|
|
151
|
-
method: this.endpoint.method
|
|
193
|
+
host: ctx.headers.host
|
|
152
194
|
});
|
|
153
195
|
const rawDb = ctx.database;
|
|
196
|
+
const operation = `${this.endpoint.method} ${this.endpoint.route}`;
|
|
154
197
|
return (0, _geekmidas_services.runWithRequestContext)({
|
|
155
198
|
logger,
|
|
156
199
|
requestId,
|
|
157
|
-
startTime
|
|
200
|
+
startTime,
|
|
201
|
+
operation
|
|
158
202
|
}, async () => {
|
|
159
203
|
const session = await this.endpoint.getSession({
|
|
160
204
|
logger,
|
|
@@ -163,6 +207,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
163
207
|
cookie,
|
|
164
208
|
...rawDb !== void 0 && { db: rawDb }
|
|
165
209
|
});
|
|
210
|
+
logger = (0, _geekmidas_services.currentRequestContext)()?.logger ?? logger;
|
|
166
211
|
if (!await this.endpoint.authorize({
|
|
167
212
|
header,
|
|
168
213
|
cookie,
|
|
@@ -177,6 +222,14 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
177
222
|
logger.warn("Forbidden access attempt");
|
|
178
223
|
throw new _geekmidas_errors.ForbiddenError("Forbidden access to the endpoint", "You do not have permission to access this resource.");
|
|
179
224
|
}
|
|
225
|
+
const rateLimitHeaders = this.endpoint.rateLimit ? await require_requestLogger.enforceRateLimit(this.endpoint.rateLimit, {
|
|
226
|
+
header,
|
|
227
|
+
services: ctx.services,
|
|
228
|
+
logger,
|
|
229
|
+
session,
|
|
230
|
+
path: this.endpoint.route,
|
|
231
|
+
method: this.endpoint.method
|
|
232
|
+
}) : {};
|
|
180
233
|
const auditorStorage = ctx.auditorStorage;
|
|
181
234
|
let auditContext;
|
|
182
235
|
if (auditorStorage) {
|
|
@@ -195,8 +248,9 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
195
248
|
} catch (error) {
|
|
196
249
|
logger.error(error, "Failed to extract actor for audits");
|
|
197
250
|
}
|
|
251
|
+
const { DefaultAuditor } = await require_optionalPeers.loadAudit();
|
|
198
252
|
auditContext = {
|
|
199
|
-
auditor: new
|
|
253
|
+
auditor: new DefaultAuditor({
|
|
200
254
|
actor,
|
|
201
255
|
storage: auditorStorage,
|
|
202
256
|
metadata: {
|
|
@@ -209,7 +263,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
209
263
|
}
|
|
210
264
|
const audits = this.endpoint.audits;
|
|
211
265
|
if (!auditContext && audits?.length) logger.warn("No auditor storage service available");
|
|
212
|
-
const { output, metadata } = await
|
|
266
|
+
const { output, metadata, redirect } = await require_requestLogger.executeWithAuditTransaction(auditContext, async (auditor) => {
|
|
213
267
|
const db = auditor?.getTransaction?.() ?? rawDb;
|
|
214
268
|
const responseBuilder = new require_Endpoint.ResponseBuilder();
|
|
215
269
|
const response = await this.endpoint.handler({
|
|
@@ -230,13 +284,15 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
230
284
|
data = response.data;
|
|
231
285
|
metadata = response.metadata;
|
|
232
286
|
}
|
|
287
|
+
const redirect = require_Endpoint.Endpoint.isRedirectStatus(metadata.status ?? this.endpoint.status);
|
|
233
288
|
return {
|
|
234
|
-
output: await this.endpoint.parseOutput(data),
|
|
289
|
+
output: redirect ? void 0 : await this.endpoint.parseOutput(data),
|
|
235
290
|
metadata,
|
|
236
|
-
responseBuilder
|
|
291
|
+
responseBuilder,
|
|
292
|
+
redirect
|
|
237
293
|
};
|
|
238
294
|
}, async (result, auditor) => {
|
|
239
|
-
if (!audits?.length) return;
|
|
295
|
+
if (!audits?.length || result.redirect) return;
|
|
240
296
|
for (const audit of audits) {
|
|
241
297
|
if (audit.when && !audit.when(result.output)) continue;
|
|
242
298
|
const payload = audit.payload(result.output);
|
|
@@ -247,9 +303,11 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
247
303
|
});
|
|
248
304
|
}
|
|
249
305
|
}, { db: rawDb });
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
306
|
+
if (!redirect) await require_functions.publishConstructEvents(this.endpoint, output, this.serviceDiscovery, this.endpoint.logger, ctx.services);
|
|
307
|
+
const headers = {
|
|
308
|
+
...rateLimitHeaders,
|
|
309
|
+
...metadata.headers || {}
|
|
310
|
+
};
|
|
253
311
|
if (metadata.cookies && metadata.cookies.size > 0) {
|
|
254
312
|
const setCookieValues = [];
|
|
255
313
|
for (const [name, cookie] of metadata.cookies.entries()) setCookieValues.push(serializeCookie(name, cookie.value, cookie.options));
|
|
@@ -257,7 +315,7 @@ var TestEndpointAdaptor = class TestEndpointAdaptor {
|
|
|
257
315
|
}
|
|
258
316
|
return {
|
|
259
317
|
body: output,
|
|
260
|
-
status: metadata.status
|
|
318
|
+
status: metadata.status ?? this.endpoint.status,
|
|
261
319
|
headers
|
|
262
320
|
};
|
|
263
321
|
});
|
|
@@ -291,7 +349,8 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
291
349
|
if ("auditor" in ctx && ctx.auditor !== void 0) auditor = ctx.auditor;
|
|
292
350
|
else if (this.fn.auditorStorageService) {
|
|
293
351
|
const storage = (await this.serviceDiscovery.register([this.fn.auditorStorageService]))[this.fn.auditorStorageService.serviceName];
|
|
294
|
-
|
|
352
|
+
const { DefaultAuditor } = await require_optionalPeers.loadAudit();
|
|
353
|
+
auditor = new DefaultAuditor({
|
|
295
354
|
actor: {
|
|
296
355
|
id: "system",
|
|
297
356
|
type: "system"
|
|
@@ -324,7 +383,7 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
324
383
|
await auditor.flush();
|
|
325
384
|
}
|
|
326
385
|
}
|
|
327
|
-
await
|
|
386
|
+
await require_functions.publishEvents(logger, this.serviceDiscovery, this.fn.events, output, services);
|
|
328
387
|
return output;
|
|
329
388
|
});
|
|
330
389
|
}
|
|
@@ -334,7 +393,8 @@ var TestFunctionAdaptor = class TestFunctionAdaptor {
|
|
|
334
393
|
/**
|
|
335
394
|
* In-memory test driver for a {@link Queue} worker. Hand it a batch of messages
|
|
336
395
|
* and it registers the queue's services, runs the handler in a request context,
|
|
337
|
-
* and returns the handler result — no SQS/pg-boss required.
|
|
396
|
+
* and returns the handler result — no SQS/pg-boss required. A queue with a
|
|
397
|
+
* database gets `db` registered from it, or the one the request passes.
|
|
338
398
|
*
|
|
339
399
|
* @example
|
|
340
400
|
* const adapter = new TestQueueAdaptor(ordersQueue);
|
|
@@ -353,17 +413,27 @@ var TestQueueAdaptor = class TestQueueAdaptor {
|
|
|
353
413
|
async invoke(request) {
|
|
354
414
|
const logger = this.queue.logger.child({ test: true });
|
|
355
415
|
const services = request.services ?? await this.serviceDiscovery.register(this.queue.services);
|
|
416
|
+
const db = request.db !== void 0 ? request.db : await this.getDatabase();
|
|
356
417
|
const requestId = `test-${Date.now()}`;
|
|
418
|
+
const startTime = Date.now();
|
|
419
|
+
const operation = `queue ${this.queue.name}`;
|
|
357
420
|
return (0, _geekmidas_services.runWithRequestContext)({
|
|
358
421
|
logger,
|
|
359
422
|
requestId,
|
|
360
|
-
startTime
|
|
423
|
+
startTime,
|
|
424
|
+
operation
|
|
361
425
|
}, () => this.queue.handler({
|
|
362
426
|
messages: request.messages,
|
|
363
427
|
services,
|
|
364
|
-
logger
|
|
428
|
+
logger,
|
|
429
|
+
db
|
|
365
430
|
}));
|
|
366
431
|
}
|
|
432
|
+
async getDatabase() {
|
|
433
|
+
const service = this.queue.databaseService;
|
|
434
|
+
if (!service) return void 0;
|
|
435
|
+
return (await this.serviceDiscovery.register([service]))[service.serviceName];
|
|
436
|
+
}
|
|
367
437
|
};
|
|
368
438
|
//#endregion
|
|
369
439
|
//#region src/subscribers/TestSubscriberAdaptor.ts
|
|
@@ -382,18 +452,23 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
|
|
|
382
452
|
let services;
|
|
383
453
|
if (request.services) services = request.services;
|
|
384
454
|
else services = await this.serviceDiscovery.register(this.subscriber.services);
|
|
455
|
+
const db = request.db !== void 0 ? request.db : await this.getDatabase();
|
|
385
456
|
const filteredEvents = this.filterEvents(request.events);
|
|
386
457
|
if (filteredEvents.length === 0) return { batchItemFailures: [] };
|
|
387
458
|
const requestId = `test-${Date.now()}`;
|
|
459
|
+
const startTime = Date.now();
|
|
460
|
+
const operation = `subscriber ${this.subscriber.topicName ?? "test"}`;
|
|
388
461
|
return (0, _geekmidas_services.runWithRequestContext)({
|
|
389
462
|
logger,
|
|
390
463
|
requestId,
|
|
391
|
-
startTime
|
|
464
|
+
startTime,
|
|
465
|
+
operation
|
|
392
466
|
}, async () => {
|
|
393
467
|
const result = await this.subscriber.handler({
|
|
394
468
|
events: filteredEvents,
|
|
395
469
|
services,
|
|
396
|
-
logger
|
|
470
|
+
logger,
|
|
471
|
+
db
|
|
397
472
|
});
|
|
398
473
|
let output = result;
|
|
399
474
|
if (this.subscriber.outputSchema && result) {
|
|
@@ -401,21 +476,1079 @@ var TestSubscriberAdaptor = class TestSubscriberAdaptor {
|
|
|
401
476
|
if (validationResult.issues) throw new Error("Subscriber output validation failed");
|
|
402
477
|
output = validationResult.value;
|
|
403
478
|
}
|
|
404
|
-
await require_lazyAccessors.publishEvents(logger, this.serviceDiscovery, this.subscriber.events, output, this.subscriber.publisherService);
|
|
405
479
|
return output;
|
|
406
480
|
});
|
|
407
481
|
}
|
|
482
|
+
async getDatabase() {
|
|
483
|
+
const service = this.subscriber.databaseService;
|
|
484
|
+
if (!service) return void 0;
|
|
485
|
+
return (await this.serviceDiscovery.register([service]))[service.serviceName];
|
|
486
|
+
}
|
|
408
487
|
filterEvents(events) {
|
|
409
488
|
if (!this.subscriber.subscribedEvents) return events;
|
|
410
489
|
return events.filter((event) => this.subscriber.subscribedEvents.includes(event.type));
|
|
411
490
|
}
|
|
412
491
|
};
|
|
413
492
|
//#endregion
|
|
414
|
-
|
|
493
|
+
//#region src/testing/manifest.ts
|
|
494
|
+
/**
|
|
495
|
+
* The test manifest: what `gkm test` knows about an app, written down for the
|
|
496
|
+
* suite it starts.
|
|
497
|
+
*
|
|
498
|
+
* `gkm test` discovers the constructs, reconciles the test stage and resolves
|
|
499
|
+
* its environment — then, until this existed, threw all of it away and left a
|
|
500
|
+
* test to declare it again by hand. The manifest keeps it: which construct and
|
|
501
|
+
* endpoint is exported where, and the environment the test stage resolved,
|
|
502
|
+
* under the keys the constructs themselves derive. A feature test is built from
|
|
503
|
+
* it, so nothing a test says can drift from what the app declares.
|
|
504
|
+
*/
|
|
505
|
+
/** The environment variable `gkm test` names the manifest in. */
|
|
506
|
+
const TEST_MANIFEST_ENV = "GKM_TEST_MANIFEST";
|
|
507
|
+
/**
|
|
508
|
+
* Read a test manifest: from a path, a `file:` URL, or — given nothing — the
|
|
509
|
+
* one `gkm test` named in `GKM_TEST_MANIFEST`.
|
|
510
|
+
*/
|
|
511
|
+
function loadTestManifest(from) {
|
|
512
|
+
const location = from ?? process.env["GKM_TEST_MANIFEST"];
|
|
513
|
+
if (!location) throw new NoTestManifest();
|
|
514
|
+
trustLocalEdge();
|
|
515
|
+
const path = location instanceof URL || location.startsWith("file:") ? (0, node_url.fileURLToPath)(location) : location;
|
|
516
|
+
return JSON.parse((0, node_fs.readFileSync)(path, "utf-8"));
|
|
517
|
+
}
|
|
518
|
+
let trusted = false;
|
|
519
|
+
/**
|
|
520
|
+
* Trust the local edge's certificate authority in this thread.
|
|
521
|
+
*
|
|
522
|
+
* `NODE_EXTRA_CA_CERTS` does it for a process started with it — which a
|
|
523
|
+
* suite started by `gkm test` is, and one started by plain `vitest` or an
|
|
524
|
+
* editor is not: its setup only learns the path once Vitest is running, and a
|
|
525
|
+
* worker *thread* shares that process and keeps a TLS store of its own. Every
|
|
526
|
+
* feature test loads the manifest, so this is the one place each worker passes
|
|
527
|
+
* through.
|
|
528
|
+
*/
|
|
529
|
+
function trustLocalEdge() {
|
|
530
|
+
const certificate = process.env.NODE_EXTRA_CA_CERTS;
|
|
531
|
+
if (trusted || !certificate || !(0, node_fs.existsSync)(certificate)) return;
|
|
532
|
+
trusted = true;
|
|
533
|
+
node_tls.default.setDefaultCACertificates([...node_tls.default.getCACertificates("default"), (0, node_fs.readFileSync)(certificate, "utf-8")]);
|
|
534
|
+
}
|
|
535
|
+
/** A feature test ran without a manifest to build itself from. */
|
|
536
|
+
var NoTestManifest = class extends Error {
|
|
537
|
+
constructor() {
|
|
538
|
+
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}.`);
|
|
539
|
+
this.name = "NoTestManifest";
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/testing/receive.ts
|
|
544
|
+
/** `mailbox.receive` named no recipient. */
|
|
545
|
+
var ReceiveNeedsRecipient = class extends Error {
|
|
546
|
+
constructor() {
|
|
547
|
+
super("mailbox.receive needs `to`: the envelope recipient routes the message to an inbox, and nothing else does.");
|
|
548
|
+
this.name = "ReceiveNeedsRecipient";
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
/** `mailbox.receive` was given fields and a raw message, or neither a sender nor raw. */
|
|
552
|
+
var ReceiveFieldsOrRaw = class extends Error {
|
|
553
|
+
reason;
|
|
554
|
+
constructor(reason) {
|
|
555
|
+
super(reason === "both" ? "mailbox.receive takes either a raw message or the fields to build one (subject, text, html, attachments, headers…), not both: the raw message already says them." : "mailbox.receive needs `from` when it builds the message — or a `raw` message, whose From: it uses.");
|
|
556
|
+
this.reason = reason;
|
|
557
|
+
this.name = "ReceiveFieldsOrRaw";
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
/** No declared inbox receives at the address `mailbox.receive` was given. */
|
|
561
|
+
var NoInboxForAddress = class extends Error {
|
|
562
|
+
address;
|
|
563
|
+
inboxes;
|
|
564
|
+
constructor(address, inboxes) {
|
|
565
|
+
super(inboxes.length === 0 ? `No inbox is declared, so nothing receives at '${address}'.` : `No inbox receives at '${address}'. ${inboxes.map((i) => `'${i}'`).join(", ")} take only their declared addresses on this stage's domain — as the deployed receipt rule does.`);
|
|
566
|
+
this.address = address;
|
|
567
|
+
this.inboxes = inboxes;
|
|
568
|
+
this.name = "NoInboxForAddress";
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
/** An inbox the test can receive for: no Mailpit to deliver to. */
|
|
572
|
+
var InboxNotLocal = class extends Error {
|
|
573
|
+
inbox;
|
|
574
|
+
constructor(inbox) {
|
|
575
|
+
super(`'${inbox}' has no ${(0, _geekmidas_manifest.providedKeyFor)(inbox, "inbox", "smtpUrl")} in this test's environment, so there is no Mailpit to deliver to. Run it under \`gkm test\`, which resolves it.`);
|
|
576
|
+
this.inbox = inbox;
|
|
577
|
+
this.name = "InboxNotLocal";
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
/** Whether `value` is an inbox construct — by what it declares, so nothing imports one. */
|
|
581
|
+
function isInboxConstruct(value) {
|
|
582
|
+
const candidate = value;
|
|
583
|
+
return typeof candidate?.declare === "function" && typeof candidate.id === "string" && candidate.addressing !== void 0 && candidate.topic !== void 0 && candidate.declare().some((d) => d.kind === "inbox" && d.id === candidate.id);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Deliver `mail` to Mailpit and receive it: each inbox its envelope
|
|
587
|
+
* recipient is addressed to gets the receipt notification, through
|
|
588
|
+
* `publish`.
|
|
589
|
+
*/
|
|
590
|
+
async function receiveInTest(mail, inboxes, env, publish) {
|
|
591
|
+
if (!mail.to) throw new ReceiveNeedsRecipient();
|
|
592
|
+
const fields = mail;
|
|
593
|
+
const built = fields.subject !== void 0 || fields.text !== void 0 || fields.html !== void 0 || fields.attachments !== void 0 || fields.headers !== void 0 || fields.headerTo !== void 0 || fields.cc !== void 0 || fields.replyTo !== void 0;
|
|
594
|
+
if (mail.raw !== void 0 && built) throw new ReceiveFieldsOrRaw("both");
|
|
595
|
+
const addressed = inboxes.filter((inbox) => {
|
|
596
|
+
const domain = env[(0, _geekmidas_manifest.providedKeyFor)(inbox.id, "inbox", "domain")];
|
|
597
|
+
return domain && (0, _geekmidas_manifest.inboxRecipient)(mail.to, inbox.addressing, domain);
|
|
598
|
+
});
|
|
599
|
+
if (addressed.length === 0) throw new NoInboxForAddress(mail.to, inboxes.map((inbox) => inbox.id));
|
|
600
|
+
let inbound;
|
|
601
|
+
let inbox;
|
|
602
|
+
try {
|
|
603
|
+
inbound = await import("@geekmidas/emailkit/inbound");
|
|
604
|
+
inbox = await Promise.resolve().then(() => require("../inbox.cjs"));
|
|
605
|
+
} catch (cause) {
|
|
606
|
+
throw new require_optionalPeers.OptionalPeerMissing("@geekmidas/emailkit and @geekmidas/storage", "Receiving mail into an Inbox", cause);
|
|
607
|
+
}
|
|
608
|
+
const { composeEmail, deliverRaw, parseEmail } = inbound;
|
|
609
|
+
const { receiveMail } = inbox;
|
|
610
|
+
let raw;
|
|
611
|
+
let from;
|
|
612
|
+
if (mail.raw !== void 0) {
|
|
613
|
+
raw = mail.raw;
|
|
614
|
+
const sender = mail.from ?? (await parseEmail(raw)).from?.address;
|
|
615
|
+
if (!sender) throw new ReceiveFieldsOrRaw("no-sender");
|
|
616
|
+
from = sender;
|
|
617
|
+
} else {
|
|
618
|
+
if (!fields.from) throw new ReceiveFieldsOrRaw("no-sender");
|
|
619
|
+
from = fields.from;
|
|
620
|
+
raw = await composeEmail({
|
|
621
|
+
from: fields.from,
|
|
622
|
+
to: fields.headerTo ?? mail.to,
|
|
623
|
+
...fields.cc !== void 0 ? { cc: fields.cc } : {},
|
|
624
|
+
...fields.replyTo ? { replyTo: fields.replyTo } : {},
|
|
625
|
+
...fields.subject !== void 0 ? { subject: fields.subject } : {},
|
|
626
|
+
...fields.text !== void 0 ? { text: fields.text } : {},
|
|
627
|
+
...fields.html !== void 0 ? { html: fields.html } : {},
|
|
628
|
+
...fields.attachments ? { attachments: fields.attachments } : {},
|
|
629
|
+
...fields.headers ? { headers: fields.headers } : {}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
const smtp = env[(0, _geekmidas_manifest.providedKeyFor)(addressed[0].id, "inbox", "smtpUrl")];
|
|
633
|
+
if (!smtp) throw new InboxNotLocal(addressed[0].id);
|
|
634
|
+
return receiveMail({
|
|
635
|
+
key: await deliverRaw(smtp, {
|
|
636
|
+
from,
|
|
637
|
+
to: [mail.to]
|
|
638
|
+
}, raw),
|
|
639
|
+
store: "mailpit",
|
|
640
|
+
from,
|
|
641
|
+
recipients: [mail.to],
|
|
642
|
+
...mail.verdicts ? { verdicts: mail.verdicts } : {}
|
|
643
|
+
}, addressed.map((inbox) => ({
|
|
644
|
+
id: inbox.id,
|
|
645
|
+
addressing: inbox.addressing,
|
|
646
|
+
domain: env[(0, _geekmidas_manifest.providedKeyFor)(inbox.id, "inbox", "domain")],
|
|
647
|
+
publish: (notification) => publish(inbox, notification)
|
|
648
|
+
})));
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/testing/featureTest.ts
|
|
652
|
+
/**
|
|
653
|
+
* `featureTest`: an app, driven the way it runs deployed.
|
|
654
|
+
*
|
|
655
|
+
* A browser signs in and calls the API; the API calls the auth server; each
|
|
656
|
+
* over its URL, each database in its own transaction. Nothing runs as a server:
|
|
657
|
+
* every URL an app's constructs answer on is served in-process through MSW,
|
|
658
|
+
* from the real handler, for the test that made the request. Everything else
|
|
659
|
+
* with a real local equivalent — Postgres, Mailpit, MinIO — is used directly.
|
|
660
|
+
*
|
|
661
|
+
* It is built from the test manifest `gkm test` writes — the constructs and
|
|
662
|
+
* endpoints the app exports, and the environment the test stage resolved — so
|
|
663
|
+
* a test declares none of it. `gkm test` also generates the configured `it`
|
|
664
|
+
* and a `Browser` with a typed client per surface:
|
|
665
|
+
*
|
|
666
|
+
* ```ts
|
|
667
|
+
* import { it } from '#test';
|
|
668
|
+
*
|
|
669
|
+
* it('shows the signed-in user their profile', async ({ browser, mailbox }) => {
|
|
670
|
+
* await browser.auth.signIn.magicLink({ email: 'ada@shop.test' });
|
|
671
|
+
* await browser.visit((await mailbox('ada@shop.test').last()).link!);
|
|
672
|
+
* expect(await browser.api.get('/profile')).toMatchObject({ email: 'ada@shop.test' });
|
|
673
|
+
* });
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
/** Every test in flight in this process, by id. */
|
|
677
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
678
|
+
/** Databases already resolving to test transactions — patched once each. */
|
|
679
|
+
const bound = /* @__PURE__ */ new WeakSet();
|
|
680
|
+
function featureTest(options = {}) {
|
|
681
|
+
const manifest = options.manifest ?? loadTestManifest();
|
|
682
|
+
const BrowserClass = options.browser ?? _geekmidas_testkit_browser.Browser;
|
|
683
|
+
const site = wildcardSiteUrl(manifest);
|
|
684
|
+
let app;
|
|
685
|
+
let factoryDatabases = [];
|
|
686
|
+
let owned = [];
|
|
687
|
+
let network;
|
|
688
|
+
let restoreFetch = () => {};
|
|
689
|
+
(0, vitest.beforeAll)(async () => {
|
|
690
|
+
app = await load(manifest, options.modules ?? {});
|
|
691
|
+
owned = ownDatabases(app, manifest);
|
|
692
|
+
factoryDatabases = databasesFor(options.factories ?? {}, owned);
|
|
693
|
+
for (const database of app.databases) bindToTests(database);
|
|
694
|
+
network = (0, msw_node.setupServer)(...surfaceHandlers(app.endpoints, manifest.env), ...app.auths.map((auth) => authHandler(auth, manifest.env, app.envParser)), ...Object.entries(options.fakes ?? {}).flatMap(([id, fake]) => fakeHandler(id, fake, manifest.env)));
|
|
695
|
+
network.listen({ onUnhandledRequest(request, print) {
|
|
696
|
+
if (isLocal(new URL(request.url))) return;
|
|
697
|
+
print.error();
|
|
698
|
+
} });
|
|
699
|
+
const restoreStamp = (0, _geekmidas_testkit_context.installContextFetch)();
|
|
700
|
+
const stamped = globalThis.fetch;
|
|
701
|
+
globalThis.fetch = deliveringFetch(stamped, (id) => {
|
|
702
|
+
const state = contexts.get(id);
|
|
703
|
+
return state ? deliver(app, state, id) : Promise.resolve();
|
|
704
|
+
});
|
|
705
|
+
restoreFetch = () => {
|
|
706
|
+
globalThis.fetch = stamped;
|
|
707
|
+
restoreStamp();
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
(0, vitest.afterAll)(() => {
|
|
711
|
+
restoreFetch();
|
|
712
|
+
network?.close();
|
|
713
|
+
});
|
|
714
|
+
const run = (name, fn) => async () => {
|
|
715
|
+
const id = (0, node_crypto.randomUUID)();
|
|
716
|
+
_geekmidas_testkit_faker.faker.seed(seedOf(name));
|
|
717
|
+
const state = {
|
|
718
|
+
transactions: new _geekmidas_testkit_transactions.TransactionRegistry(),
|
|
719
|
+
discovery: new _geekmidas_services.ServiceDiscovery(app.envParser),
|
|
720
|
+
surfaces: /* @__PURE__ */ new Map(),
|
|
721
|
+
auth: /* @__PURE__ */ new Map(),
|
|
722
|
+
addresses: /* @__PURE__ */ new Set(),
|
|
723
|
+
published: /* @__PURE__ */ new Map(),
|
|
724
|
+
sockets: /* @__PURE__ */ new Map(),
|
|
725
|
+
pending: [],
|
|
726
|
+
delivering: false
|
|
727
|
+
};
|
|
728
|
+
const readMail = app.readMail;
|
|
729
|
+
if (readMail) state.mailbox = (address) => {
|
|
730
|
+
state.addresses.add(address);
|
|
731
|
+
return readMail(address);
|
|
732
|
+
};
|
|
733
|
+
contexts.set(id, state);
|
|
734
|
+
await state.discovery.register(recorders(app.channels, state));
|
|
735
|
+
await state.discovery.register(socketRecorders(app.surfaces, state));
|
|
736
|
+
await state.discovery.register(watchers(app, state));
|
|
737
|
+
try {
|
|
738
|
+
await (0, _geekmidas_testkit_context.runInTestContext)(id, async () => {
|
|
739
|
+
const browser = new BrowserClass(site ? { site } : {});
|
|
740
|
+
const restore = browser.install();
|
|
741
|
+
try {
|
|
742
|
+
const transaction = (database) => state.transactions.get(database.id, urlOf(database, app.envParser), database.clientConfig);
|
|
743
|
+
const db = { get: (name) => {
|
|
744
|
+
const database = owned.find((candidate) => candidate.service.serviceName === name);
|
|
745
|
+
if (!database) throw new UnknownDatabase(name, owned.map((candidate) => candidate.service.serviceName));
|
|
746
|
+
return transaction(database);
|
|
747
|
+
} };
|
|
748
|
+
const built = /* @__PURE__ */ new Map();
|
|
749
|
+
await fn({
|
|
750
|
+
browser,
|
|
751
|
+
db,
|
|
752
|
+
factories: { get: (name) => {
|
|
753
|
+
const database = factoryDatabases.find(([candidate]) => candidate === name)?.[1];
|
|
754
|
+
if (!database) throw new UnknownFactory(name, factoryDatabases.map(([candidate]) => candidate));
|
|
755
|
+
let factory = built.get(name);
|
|
756
|
+
if (!factory) {
|
|
757
|
+
factory = transaction(database).then(options.factories[name]);
|
|
758
|
+
built.set(name, factory);
|
|
759
|
+
}
|
|
760
|
+
return factory;
|
|
761
|
+
} },
|
|
762
|
+
faker: _geekmidas_testkit_faker.faker,
|
|
763
|
+
mailbox: Object.assign((address) => {
|
|
764
|
+
if (!state.mailbox) throw new NoInbox();
|
|
765
|
+
return state.mailbox(address);
|
|
766
|
+
}, { receive: async (mail) => {
|
|
767
|
+
await receiveInTest(mail, app.inboxes, app.env, async (inbox, notification) => {
|
|
768
|
+
state.pending.push({
|
|
769
|
+
channel: inbox.topic,
|
|
770
|
+
messages: [{
|
|
771
|
+
type: _geekmidas_manifest.INBOX_EVENT,
|
|
772
|
+
payload: notification
|
|
773
|
+
}]
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
await deliver(app, state, id);
|
|
777
|
+
} }),
|
|
778
|
+
published: (channel) => [...state.published.get(channel.id) ?? []],
|
|
779
|
+
sockets: (surface) => {
|
|
780
|
+
const recorder = state.sockets.get(surface.id);
|
|
781
|
+
if (!recorder) throw new UnknownWebSocketApi(surface.id, [...state.sockets.keys()]);
|
|
782
|
+
return recorder;
|
|
783
|
+
},
|
|
784
|
+
services: { get: (name) => resolveService(app, state, name) },
|
|
785
|
+
subscriber: (subscriber) => thenDeliver(new TestSubscriberAdaptor(subscriber, state.discovery), () => deliver(app, state, id)),
|
|
786
|
+
queue: (queue) => thenDeliver(new TestQueueAdaptor(queue, state.discovery), () => deliver(app, state, id)),
|
|
787
|
+
objects: (bucket) => ({ emit: async (...events) => {
|
|
788
|
+
const watched = app.watched.find((candidate) => candidate.id === bucket.id);
|
|
789
|
+
if (!watched) throw new BucketNotWatched(bucket.id);
|
|
790
|
+
const name = bucketName(watched, app.envParser);
|
|
791
|
+
state.pending.push({
|
|
792
|
+
channel: watched,
|
|
793
|
+
messages: events.map(({ type, ...object }) => ({
|
|
794
|
+
type,
|
|
795
|
+
payload: {
|
|
796
|
+
bucket: name,
|
|
797
|
+
...object
|
|
798
|
+
}
|
|
799
|
+
}))
|
|
800
|
+
});
|
|
801
|
+
await deliver(app, state, id);
|
|
802
|
+
} })
|
|
803
|
+
});
|
|
804
|
+
} finally {
|
|
805
|
+
restore();
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
} finally {
|
|
809
|
+
contexts.delete(id);
|
|
810
|
+
await Promise.all([state.transactions.rollbackAll(), ...[...state.addresses].map((address) => app.readMail?.(address).clear())]);
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
const it = ((name, fn, timeout) => (0, vitest.test)(name, run(name, fn), timeout));
|
|
814
|
+
it.only = (name, fn, timeout) => vitest.test.only(name, run(name, fn), timeout);
|
|
815
|
+
it.skip = (name, fn, timeout) => vitest.test.skip(name, run(name, fn), timeout);
|
|
816
|
+
return it;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* A test's faker seed, from its name: the same test draws the same data on
|
|
820
|
+
* every run, and two tests draw different data.
|
|
821
|
+
*/
|
|
822
|
+
function seedOf(name) {
|
|
823
|
+
let hash = 0;
|
|
824
|
+
for (const char of name) hash = Math.imul(hash, 31) + char.charCodeAt(0) | 0;
|
|
825
|
+
return hash >>> 0;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Import what the manifest points at.
|
|
829
|
+
*
|
|
830
|
+
* The same modules the app runs, so a construct here *is* the app's construct —
|
|
831
|
+
* the one its endpoints were built from — never a copy declared again.
|
|
832
|
+
*/
|
|
833
|
+
async function load(manifest, modules) {
|
|
834
|
+
const envParser = new _geekmidas_envkit.EnvironmentParser({ ...manifest.env });
|
|
835
|
+
const imported = async ({ file, export: name }) => (modules[file] ?? await import(file))[name];
|
|
836
|
+
const constructs = await Promise.all(Object.values(manifest.constructs).map(({ source }) => imported(source)));
|
|
837
|
+
const endpoints = (await Promise.all(manifest.endpoints.map(({ source }) => imported(source)))).filter((value) => require_Endpoint.Endpoint.isEndpoint(value));
|
|
838
|
+
const subscribers = (await Promise.all((manifest.subscribers ?? []).map(async ({ source }) => ({
|
|
839
|
+
name: source.export,
|
|
840
|
+
subscriber: await imported(source)
|
|
841
|
+
})))).filter((entry) => entry.subscriber?.__IS_SUBSCRIBER__ === true);
|
|
842
|
+
const unique = (values) => [...new Set(values)];
|
|
843
|
+
const databases = unique(constructs.filter((value) => value instanceof require_kysely.KyselyDatabase));
|
|
844
|
+
const auths = unique(constructs.filter((value) => value instanceof require_auth.BetterAuth));
|
|
845
|
+
const emails = unique(constructs.filter((value) => value instanceof require_email.Email));
|
|
846
|
+
const consumables = unique(constructs.filter(require_construct_interface.isConsumable));
|
|
847
|
+
const channels = unique(constructs.filter((value) => value instanceof require_Topic.Topic || value instanceof require_Queue.Queue));
|
|
848
|
+
const watched = unique(constructs.filter((value) => isBucket(value) && subscribers.some(({ subscriber }) => subscriber.bucketName === value.id)));
|
|
849
|
+
const inboxes = unique(constructs.filter(isInboxConstruct));
|
|
850
|
+
const surfaces = unique(constructs.filter((value) => value instanceof require_websocket_api.WebSocketApi));
|
|
851
|
+
const inbox = emails.map((email) => manifest.env[(0, _geekmidas_manifest.providedKeyFor)(email.id, "email", "inboxUrl")]).find(Boolean);
|
|
852
|
+
return {
|
|
853
|
+
envParser,
|
|
854
|
+
endpoints,
|
|
855
|
+
databases,
|
|
856
|
+
auths,
|
|
857
|
+
emails,
|
|
858
|
+
channels,
|
|
859
|
+
watched,
|
|
860
|
+
inboxes,
|
|
861
|
+
surfaces,
|
|
862
|
+
env: manifest.env,
|
|
863
|
+
consumables,
|
|
864
|
+
subscribers,
|
|
865
|
+
...inbox ? { readMail: (0, _geekmidas_testkit_mailbox.createMailbox)({ inbox }) } : {}
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* A publisher that records rather than sends, under the name a topic or queue
|
|
870
|
+
* is injected by — `services.users` — which is also the one `.event(users, …)`
|
|
871
|
+
* publishes through.
|
|
872
|
+
*/
|
|
873
|
+
function recorders(channels, state) {
|
|
874
|
+
return channels.map((channel) => {
|
|
875
|
+
const publisher = { async publish(messages) {
|
|
876
|
+
const sent = messages.map(({ type, payload }) => ({
|
|
877
|
+
type,
|
|
878
|
+
payload
|
|
879
|
+
}));
|
|
880
|
+
state.published.set(channel.id, [...state.published.get(channel.id) ?? [], ...sent]);
|
|
881
|
+
state.pending.push({
|
|
882
|
+
channel,
|
|
883
|
+
messages: sent
|
|
884
|
+
});
|
|
885
|
+
} };
|
|
886
|
+
return {
|
|
887
|
+
serviceName: channel.service.serviceName,
|
|
888
|
+
register: () => publisher
|
|
889
|
+
};
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* A WebSocket surface's publisher that records rather than sends, under the
|
|
894
|
+
* name `.dependsOn([realtime])` injects it by — one per surface per test.
|
|
895
|
+
*/
|
|
896
|
+
function socketRecorders(surfaces, state) {
|
|
897
|
+
return surfaces.map((surface) => {
|
|
898
|
+
const recorder = surface.testPublisher();
|
|
899
|
+
state.sockets.set(surface.id, recorder);
|
|
900
|
+
return {
|
|
901
|
+
serviceName: surface.service.serviceName,
|
|
902
|
+
register: () => recorder
|
|
903
|
+
};
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* The databases a test is handed: the app's own. A schema tenant an auth server
|
|
908
|
+
* owns is reached through that server, as the app reaches it, and a reader is
|
|
909
|
+
* the same database through a read-only role — neither is another database to
|
|
910
|
+
* test against.
|
|
911
|
+
*/
|
|
912
|
+
function ownDatabases(app, manifest) {
|
|
913
|
+
const owners = new Set(app.auths.map((auth) => auth.databaseId));
|
|
914
|
+
return app.databases.filter((database) => !owners.has(database.id) && manifest.constructs[database.id]?.kind !== "database-reader");
|
|
915
|
+
}
|
|
916
|
+
/** Each factory's database, found by the service name it is keyed by. */
|
|
917
|
+
function databasesFor(factories, databases) {
|
|
918
|
+
return Object.keys(factories).map((name) => {
|
|
919
|
+
const database = databases.find((candidate) => candidate.service.serviceName === name);
|
|
920
|
+
if (!database) throw new UnknownFactory(name, databases.map((candidate) => candidate.service.serviceName));
|
|
921
|
+
return [name, database];
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Make a database resolve, inside a test, to that test's transaction.
|
|
926
|
+
*
|
|
927
|
+
* Everything reaches a database through its service — an endpoint through
|
|
928
|
+
* service discovery, the auth server through its tenant directly — so this is
|
|
929
|
+
* the one place a test's connection can be handed over. Outside a test it is
|
|
930
|
+
* the database it always was.
|
|
931
|
+
*/
|
|
932
|
+
/** Rounds of delivery before a chain of consumers is called a loop. */
|
|
933
|
+
const MAX_DELIVERY_ROUNDS = 25;
|
|
934
|
+
/**
|
|
935
|
+
* Deliver what this test published, in-process, as the broker would — and
|
|
936
|
+
* keep delivering what the consumers publish in turn, until nothing is left.
|
|
937
|
+
*
|
|
938
|
+
* - A queue's messages go to its one consumer, as a batch.
|
|
939
|
+
* - A topic's events go to every subscriber that named their type, and only
|
|
940
|
+
* those: fan-out, as the filter policy (SNS) or the per-subscriber queue
|
|
941
|
+
* (pg-boss) does it.
|
|
942
|
+
* - Each payload is checked against the consumer's schema first. Turning an
|
|
943
|
+
* SNS envelope or an SQS record into `{ type, payload }` is each adaptor's
|
|
944
|
+
* job and tested there; what is tested here is what the handler is handed.
|
|
945
|
+
* - Consumers run as the server side of this test, so their databases are
|
|
946
|
+
* this test's transactions and their writes roll back with it.
|
|
947
|
+
* - A consumer that throws fails the test. Deployed, the message would be
|
|
948
|
+
* retried; here a retry would only hide the bug.
|
|
949
|
+
*/
|
|
950
|
+
async function deliver(app, state, id) {
|
|
951
|
+
if (state.delivering) return;
|
|
952
|
+
state.delivering = true;
|
|
953
|
+
try {
|
|
954
|
+
for (let round = 0; state.pending.length > 0; round++) {
|
|
955
|
+
if (round === MAX_DELIVERY_ROUNDS) throw new DeliveryDidNotSettle(MAX_DELIVERY_ROUNDS, [...new Set(state.pending.map(({ channel }) => channel.id))]);
|
|
956
|
+
for (const { channel, messages } of state.pending.splice(0)) if (channel instanceof require_Queue.Queue) await toQueue(channel, messages, state, id);
|
|
957
|
+
else if (channel instanceof require_Topic.Topic) await toSubscribers(channel, messages, app, state, id);
|
|
958
|
+
else await toObjectSubscribers(channel, messages, app, state, id);
|
|
959
|
+
}
|
|
960
|
+
} finally {
|
|
961
|
+
state.delivering = false;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
async function toQueue(queue, messages, state, id) {
|
|
965
|
+
const payloads = [];
|
|
966
|
+
for (const message of messages) payloads.push(await accepted(queue.messageSchema, message, `queue '${queue.name}'`));
|
|
967
|
+
await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestQueueAdaptor(queue, state.discovery).invoke({ messages: payloads })).catch((error) => {
|
|
968
|
+
throw new DeliveryFailed(`queue '${queue.name}'`, messages, error);
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
async function toSubscribers(topic, messages, app, state, id) {
|
|
972
|
+
for (const { name, subscriber } of app.subscribers) {
|
|
973
|
+
if (subscriber.topicName !== topic.name) continue;
|
|
974
|
+
const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
|
|
975
|
+
if (named.length === 0) continue;
|
|
976
|
+
const consumer = `subscriber '${name}'`;
|
|
977
|
+
const events = [];
|
|
978
|
+
for (const message of named) {
|
|
979
|
+
const schema = topic.eventSchemas[message.type];
|
|
980
|
+
events.push({
|
|
981
|
+
type: message.type,
|
|
982
|
+
payload: await accepted(schema, message, consumer)
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events })).catch((error) => {
|
|
986
|
+
throw new DeliveryFailed(consumer, named, error);
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* A bucket's changes to each subscriber bound to it that named their type —
|
|
992
|
+
* the subscriber keeps the keys it watches, as it does deployed.
|
|
993
|
+
*/
|
|
994
|
+
async function toObjectSubscribers(bucket, messages, app, state, id) {
|
|
995
|
+
for (const { name, subscriber } of app.subscribers) {
|
|
996
|
+
if (subscriber.bucketName !== bucket.id) continue;
|
|
997
|
+
const named = messages.filter(({ type }) => (subscriber.subscribedEvents ?? []).includes(type));
|
|
998
|
+
if (named.length === 0) continue;
|
|
999
|
+
const consumer = `subscriber '${name}'`;
|
|
1000
|
+
await (0, _geekmidas_testkit_context.runAsServer)(id, () => new TestSubscriberAdaptor(subscriber, state.discovery).invoke({ events: named })).catch((error) => {
|
|
1001
|
+
throw new DeliveryFailed(consumer, named, error);
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* A client for each watched bucket that reports what it writes: the real
|
|
1007
|
+
* client — the test's MinIO — under the name the bucket is injected by, so
|
|
1008
|
+
* an upload a handler makes reaches the bucket's subscribers as the storage
|
|
1009
|
+
* would report it.
|
|
1010
|
+
*/
|
|
1011
|
+
function watchers(app, state) {
|
|
1012
|
+
return app.watched.map((bucket) => ({
|
|
1013
|
+
serviceName: bucket.service.serviceName,
|
|
1014
|
+
register: async (options) => {
|
|
1015
|
+
const client = await bucket.service.register(options);
|
|
1016
|
+
const name = bucketName(bucket, app.envParser);
|
|
1017
|
+
const report = async (message) => {
|
|
1018
|
+
state.pending.push({
|
|
1019
|
+
channel: bucket,
|
|
1020
|
+
messages: [message]
|
|
1021
|
+
});
|
|
1022
|
+
const context = (0, _geekmidas_testkit_context.currentTestContext)();
|
|
1023
|
+
if (context?.side === "client") await deliver(app, state, context.id);
|
|
1024
|
+
};
|
|
1025
|
+
const watching = Object.create(client);
|
|
1026
|
+
watching.upload = async (key, data, contentType) => {
|
|
1027
|
+
await client.upload(key, data, contentType);
|
|
1028
|
+
await report({
|
|
1029
|
+
type: "object.created",
|
|
1030
|
+
payload: {
|
|
1031
|
+
bucket: name,
|
|
1032
|
+
key,
|
|
1033
|
+
size: byteLength(data)
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
};
|
|
1037
|
+
watching.delete = async (key) => {
|
|
1038
|
+
await client.delete(key);
|
|
1039
|
+
await report({
|
|
1040
|
+
type: "object.deleted",
|
|
1041
|
+
payload: {
|
|
1042
|
+
bucket: name,
|
|
1043
|
+
key
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
};
|
|
1047
|
+
return watching;
|
|
1048
|
+
}
|
|
1049
|
+
}));
|
|
1050
|
+
}
|
|
1051
|
+
/** The bucket's name as the storage knows it — the host of its URL. */
|
|
1052
|
+
function bucketName(bucket, envParser) {
|
|
1053
|
+
const { url } = envParser.create((get) => ({ url: get((0, _geekmidas_manifest.providedKeyFor)(bucket.id, "objects", "connectionString")).string() })).parse();
|
|
1054
|
+
try {
|
|
1055
|
+
return new URL(url).hostname || bucket.id;
|
|
1056
|
+
} catch {
|
|
1057
|
+
return bucket.id;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
function byteLength(data) {
|
|
1061
|
+
return typeof data === "string" ? Buffer.byteLength(data) : data.length;
|
|
1062
|
+
}
|
|
1063
|
+
/** An `ObjectStorage`, recognised by what it declares — never by importing it. */
|
|
1064
|
+
function isBucket(value) {
|
|
1065
|
+
const declare = value?.declare;
|
|
1066
|
+
return typeof declare === "function" && declare.call(value)[0]?.kind === "objects";
|
|
1067
|
+
}
|
|
1068
|
+
/** `objects(bucket)` named a bucket no subscriber in the app is bound to. */
|
|
1069
|
+
/** `sockets(surface)` for a surface the test manifest does not declare. */
|
|
1070
|
+
var UnknownWebSocketApi = class extends Error {
|
|
1071
|
+
surface;
|
|
1072
|
+
declared;
|
|
1073
|
+
constructor(surface, declared) {
|
|
1074
|
+
super(`The test manifest declares no WebSocketApi '${surface}'` + (declared.length ? ` — it declares ${declared.map((id) => `'${id}'`).join(", ")}.` : ", and no WebSocketApi at all.") + " Export the surface from the app so `gkm test` records it.");
|
|
1075
|
+
this.surface = surface;
|
|
1076
|
+
this.declared = declared;
|
|
1077
|
+
this.name = "UnknownWebSocketApi";
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
var BucketNotWatched = class extends Error {
|
|
1081
|
+
bucket;
|
|
1082
|
+
constructor(bucket) {
|
|
1083
|
+
super(`No subscriber is bound to '${bucket}', so nothing receives what is emitted on it. Bind one — worker.objects(${bucket.charAt(0).toLowerCase()}${bucket.slice(1)}) — or check the test manifest lists it.`);
|
|
1084
|
+
this.bucket = bucket;
|
|
1085
|
+
this.name = "BucketNotWatched";
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
/** The payload, if the consumer's schema takes it — what the handler is handed. */
|
|
1089
|
+
async function accepted(schema, message, consumer) {
|
|
1090
|
+
const standard = schema?.["~standard"];
|
|
1091
|
+
if (!standard) return message.payload;
|
|
1092
|
+
const result = await standard.validate(message.payload);
|
|
1093
|
+
if (result.issues) throw new MessageRejected(consumer, message, result.issues);
|
|
1094
|
+
return result.value;
|
|
1095
|
+
}
|
|
1096
|
+
/** `fetch`, delivering what the test published once each of its requests answers. */
|
|
1097
|
+
function deliveringFetch(inner, settle) {
|
|
1098
|
+
return async (input, init) => {
|
|
1099
|
+
const context = (0, _geekmidas_testkit_context.currentTestContext)();
|
|
1100
|
+
const response = await inner(input, init);
|
|
1101
|
+
if (context?.side === "client") await settle(context.id);
|
|
1102
|
+
return response;
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
/** An adaptor whose `invoke` delivers what it published before returning. */
|
|
1106
|
+
function thenDeliver(adaptor, settle) {
|
|
1107
|
+
const invoke = adaptor.invoke.bind(adaptor);
|
|
1108
|
+
adaptor.invoke = (async (...args) => {
|
|
1109
|
+
const result = await invoke(...args);
|
|
1110
|
+
await settle();
|
|
1111
|
+
return result;
|
|
1112
|
+
});
|
|
1113
|
+
return adaptor;
|
|
1114
|
+
}
|
|
1115
|
+
function bindToTests(database) {
|
|
1116
|
+
if (bound.has(database)) return;
|
|
1117
|
+
bound.add(database);
|
|
1118
|
+
const service = database.service;
|
|
1119
|
+
const register = service.register;
|
|
1120
|
+
service.register = (options) => {
|
|
1121
|
+
const context = (0, _geekmidas_testkit_context.currentTestContext)();
|
|
1122
|
+
const state = context && contexts.get(context.id);
|
|
1123
|
+
if (!state) return register(options);
|
|
1124
|
+
return state.transactions.get(database.id, urlOf(database, options.envParser), database.clientConfig);
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
function urlOf(database, envParser) {
|
|
1128
|
+
return envParser.create((get) => ({ url: get((0, _geekmidas_manifest.providedKeyFor)(database.id, "database", "url")).string() })).parse().url;
|
|
1129
|
+
}
|
|
1130
|
+
/** Each surface's endpoints, served at its URL for the test that asked. */
|
|
1131
|
+
function surfaceHandlers(endpoints, env) {
|
|
1132
|
+
const bySurface = /* @__PURE__ */ new Map();
|
|
1133
|
+
for (const endpoint of endpoints) {
|
|
1134
|
+
const surface = endpoint.surface?.id;
|
|
1135
|
+
if (!surface) continue;
|
|
1136
|
+
bySurface.set(surface, [...bySurface.get(surface) ?? [], endpoint]);
|
|
1137
|
+
}
|
|
1138
|
+
return [...bySurface].flatMap(([surface, served]) => {
|
|
1139
|
+
const base = env[(0, _geekmidas_manifest.providedKeyFor)(surface, "rest-api", "url")];
|
|
1140
|
+
if (!base) return [];
|
|
1141
|
+
return msw.http.all(`${trim(base)}/*`, ({ request }) => serve(request, async (state) => {
|
|
1142
|
+
let app = state.surfaces.get(surface);
|
|
1143
|
+
if (!app) {
|
|
1144
|
+
app = Promise.resolve().then(() => {
|
|
1145
|
+
const hono$1 = new hono.Hono();
|
|
1146
|
+
require_HonoEndpointAdaptor.HonoEndpoint.addRoutes(served, state.discovery, hono$1);
|
|
1147
|
+
return hono$1;
|
|
1148
|
+
});
|
|
1149
|
+
state.surfaces.set(surface, app);
|
|
1150
|
+
}
|
|
1151
|
+
return (await app).fetch(request, inProcessBindings());
|
|
1152
|
+
}));
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* An external API's app fake, answering at the URL the test stage resolved for
|
|
1157
|
+
* it — so a handler that calls Polar calls the fake, and the test sets up
|
|
1158
|
+
* nothing.
|
|
1159
|
+
*
|
|
1160
|
+
* Not per test, unlike a surface: a fake stands in for somebody else's server,
|
|
1161
|
+
* which no test's transaction reaches. An image fake has no handler here — its
|
|
1162
|
+
* container answers on localhost, which is let through.
|
|
1163
|
+
*/
|
|
1164
|
+
function fakeHandler(id, fake, env) {
|
|
1165
|
+
const base = env[(0, _geekmidas_manifest.providedKeyFor)(id, "external-api", "url")];
|
|
1166
|
+
if (fake.kind !== "app" || !base) return [];
|
|
1167
|
+
return [msw.http.all(`${trim(base)}/*`, ({ request }) => fake.handler.fetch(request))];
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* A construct's client for this test, by service name — through the test's own
|
|
1171
|
+
* discovery, so a topic or queue is its recorder and a database its
|
|
1172
|
+
* transaction, exactly as the test's endpoints get them.
|
|
1173
|
+
*/
|
|
1174
|
+
async function resolveService(app, state, name) {
|
|
1175
|
+
const construct = app.consumables.find((candidate) => candidate.service.serviceName === name);
|
|
1176
|
+
if (!construct) throw new UnknownService(name, app.consumables.map((candidate) => candidate.service.serviceName));
|
|
1177
|
+
return (await state.discovery.register([construct.service]))[name];
|
|
1178
|
+
}
|
|
1179
|
+
/** An auth server, served at its URL, on the transaction of the test that asked. */
|
|
1180
|
+
function authHandler(auth, env, envParser) {
|
|
1181
|
+
const base = trim(env[(0, _geekmidas_manifest.providedKeyFor)(auth.id, "rest-api", "url")] ?? "");
|
|
1182
|
+
return msw.http.all(`${base}/*`, ({ request }) => serve(request, async (state) => {
|
|
1183
|
+
let app = state.auth.get(auth);
|
|
1184
|
+
if (!app) {
|
|
1185
|
+
app = auth.server({
|
|
1186
|
+
envParser,
|
|
1187
|
+
context: _geekmidas_services.serviceContext
|
|
1188
|
+
}).then(({ app }) => app);
|
|
1189
|
+
state.auth.set(auth, app);
|
|
1190
|
+
}
|
|
1191
|
+
return (await app).fetch(request, inProcessBindings());
|
|
1192
|
+
}));
|
|
1193
|
+
}
|
|
1194
|
+
/** Handle a request as the server side of the test it was made for. */
|
|
1195
|
+
async function serve(request, handle) {
|
|
1196
|
+
const id = (0, _geekmidas_testkit_context.testContextOf)(request);
|
|
1197
|
+
const state = id ? contexts.get(id) : void 0;
|
|
1198
|
+
if (!id || !state) throw new UnknownTestContext(request.url, id);
|
|
1199
|
+
return (0, _geekmidas_testkit_context.runAsServer)(id, () => handle(state));
|
|
1200
|
+
}
|
|
1201
|
+
function trim(url) {
|
|
1202
|
+
return url.replace(/\/$/, "");
|
|
1203
|
+
}
|
|
1204
|
+
function isLocal(url) {
|
|
1205
|
+
return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname.endsWith(".localhost");
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* The test stage's address for the app's site on every subdomain —
|
|
1209
|
+
* `https://*.test.shop.localhost:8443` — which `browser.on(slug)` puts a
|
|
1210
|
+
* tenant into, or `undefined` when the app declares none.
|
|
1211
|
+
*/
|
|
1212
|
+
function wildcardSiteUrl(manifest) {
|
|
1213
|
+
for (const [id, construct] of Object.entries(manifest.constructs)) {
|
|
1214
|
+
if (construct.kind !== "site") continue;
|
|
1215
|
+
const url = manifest.env[(0, _geekmidas_manifest.providedKeyFor)(id, construct.kind, "url")];
|
|
1216
|
+
if (url && new URL(url).hostname.startsWith(`${_geekmidas_manifest.WILDCARD_SUBDOMAIN}.`)) return url;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Sign a test's browser in the way a person does: ask the auth server for a
|
|
1221
|
+
* magic link, open the email it sent, follow the link.
|
|
1222
|
+
*
|
|
1223
|
+
* What the generated `browser.signIn(email)` calls. The address's mail is
|
|
1224
|
+
* cleared first — so the link is this request's, not one an earlier test left
|
|
1225
|
+
* — and cleared again after the test, like any address a test reads. Returns
|
|
1226
|
+
* the session the auth server then reports, as better-auth hands it back.
|
|
1227
|
+
*/
|
|
1228
|
+
async function signInWithMagicLink(browser, auth, email = freshAddress()) {
|
|
1229
|
+
const context = (0, _geekmidas_testkit_context.currentTestContext)();
|
|
1230
|
+
const state = context && contexts.get(context.id);
|
|
1231
|
+
if (!state) throw new UnknownTestContext("signIn", context?.id);
|
|
1232
|
+
if (!state.mailbox) throw new NoInbox();
|
|
1233
|
+
const inbox = state.mailbox(email);
|
|
1234
|
+
await inbox.clear();
|
|
1235
|
+
const requested = await auth.signIn.magicLink({ email });
|
|
1236
|
+
if (requested.error) throw new SignInFailed(email, `the auth server refused the magic link: ${requested.error.message ?? "no reason given"}`);
|
|
1237
|
+
const mail = await inbox.last();
|
|
1238
|
+
if (!mail.link) throw new SignInFailed(email, "its email held no link");
|
|
1239
|
+
await browser.visit(mail.link);
|
|
1240
|
+
const { data } = await auth.getSession();
|
|
1241
|
+
if (!data) throw new SignInFailed(email, "the auth server reported no session after the link was opened");
|
|
1242
|
+
return data;
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* An address nobody else signs in as — what `browser.signIn()` uses when the
|
|
1246
|
+
* test does not care who it is.
|
|
1247
|
+
*
|
|
1248
|
+
* Unique rather than only seeded: tests in other files run at the same time,
|
|
1249
|
+
* against the same Mailpit and the same unique columns, and a seeded address
|
|
1250
|
+
* repeats wherever two tests share a name. The readable half is the seeded
|
|
1251
|
+
* faker's, so a failure still names somebody.
|
|
1252
|
+
*/
|
|
1253
|
+
function freshAddress() {
|
|
1254
|
+
return `${_geekmidas_testkit_faker.faker.internet.username().toLowerCase().replace(/[^a-z0-9]/g, "")}.${(0, node_crypto.randomUUID)().slice(0, 8)}@example.test`;
|
|
1255
|
+
}
|
|
1256
|
+
/** `browser.signIn` finished without a session. */
|
|
1257
|
+
var SignInFailed = class extends Error {
|
|
1258
|
+
email;
|
|
1259
|
+
reason;
|
|
1260
|
+
constructor(email, reason) {
|
|
1261
|
+
super(`Signing ${email} in failed: ${reason}.`);
|
|
1262
|
+
this.email = email;
|
|
1263
|
+
this.reason = reason;
|
|
1264
|
+
this.name = "SignInFailed";
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
/** A request reached an in-process server without a test to belong to. */
|
|
1268
|
+
var UnknownTestContext = class extends Error {
|
|
1269
|
+
url;
|
|
1270
|
+
id;
|
|
1271
|
+
constructor(url, id) {
|
|
1272
|
+
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.`);
|
|
1273
|
+
this.url = url;
|
|
1274
|
+
this.id = id;
|
|
1275
|
+
this.name = "UnknownTestContext";
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
/** `mailbox` was used in an app that declares no Email construct. */
|
|
1279
|
+
var NoInbox = class extends Error {
|
|
1280
|
+
constructor() {
|
|
1281
|
+
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.");
|
|
1282
|
+
this.name = "NoInbox";
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
/** `db.get(name)` named no database the test is handed. */
|
|
1286
|
+
var UnknownDatabase = class extends Error {
|
|
1287
|
+
database;
|
|
1288
|
+
known;
|
|
1289
|
+
constructor(database, known) {
|
|
1290
|
+
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.");
|
|
1291
|
+
this.database = database;
|
|
1292
|
+
this.known = known;
|
|
1293
|
+
this.name = "UnknownDatabase";
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
/** A factory keyed by a service name no database the app declares has. */
|
|
1297
|
+
var UnknownFactory = class extends Error {
|
|
1298
|
+
factory;
|
|
1299
|
+
known;
|
|
1300
|
+
constructor(factory, known) {
|
|
1301
|
+
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.`);
|
|
1302
|
+
this.factory = factory;
|
|
1303
|
+
this.known = known;
|
|
1304
|
+
this.name = "UnknownFactory";
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
/** A published message the consumer's own schema refuses. */
|
|
1308
|
+
var MessageRejected = class extends Error {
|
|
1309
|
+
consumer;
|
|
1310
|
+
published;
|
|
1311
|
+
issues;
|
|
1312
|
+
constructor(consumer, published, issues) {
|
|
1313
|
+
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.`);
|
|
1314
|
+
this.consumer = consumer;
|
|
1315
|
+
this.published = published;
|
|
1316
|
+
this.issues = issues;
|
|
1317
|
+
this.name = "MessageRejected";
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
/** A consumer that threw while handling what the test published. */
|
|
1321
|
+
var DeliveryFailed = class extends Error {
|
|
1322
|
+
consumer;
|
|
1323
|
+
messages;
|
|
1324
|
+
cause;
|
|
1325
|
+
constructor(consumer, messages, cause) {
|
|
1326
|
+
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 });
|
|
1327
|
+
this.consumer = consumer;
|
|
1328
|
+
this.messages = messages;
|
|
1329
|
+
this.cause = cause;
|
|
1330
|
+
this.name = "DeliveryFailed";
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
/** Consumers that kept publishing to each other without settling. */
|
|
1334
|
+
var DeliveryDidNotSettle = class extends Error {
|
|
1335
|
+
rounds;
|
|
1336
|
+
channels;
|
|
1337
|
+
constructor(rounds, channels) {
|
|
1338
|
+
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.`);
|
|
1339
|
+
this.rounds = rounds;
|
|
1340
|
+
this.channels = channels;
|
|
1341
|
+
this.name = "DeliveryDidNotSettle";
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
/** `services.get(name)` for a name no construct of the app is served by. */
|
|
1345
|
+
var UnknownService = class extends Error {
|
|
1346
|
+
serviceName;
|
|
1347
|
+
available;
|
|
1348
|
+
constructor(serviceName, available) {
|
|
1349
|
+
super(`The app declares no construct served as '${serviceName}'. Its services are: ${available.join(", ") || "none"}.`);
|
|
1350
|
+
this.serviceName = serviceName;
|
|
1351
|
+
this.available = available;
|
|
1352
|
+
this.name = "UnknownService";
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
//#endregion
|
|
1356
|
+
//#region src/websocket/msw.ts
|
|
1357
|
+
/**
|
|
1358
|
+
* The MSW adaptor: a surface's real routes behind MSW's `ws.link()`, so code
|
|
1359
|
+
* that holds a `WebSocket` — a client, its reconnects, its decoding — runs
|
|
1360
|
+
* unchanged against them, in one process, with no server.
|
|
1361
|
+
*
|
|
1362
|
+
* MSW intercepts the client's `WebSocket` and hands each connection here.
|
|
1363
|
+
* The adaptor gives it an id, runs `connect()`, then each frame the client
|
|
1364
|
+
* sends through `message()`, and `disconnect()` when either side closes.
|
|
1365
|
+
* What reaches a socket from elsewhere — an endpoint's `services.<surface>` —
|
|
1366
|
+
* goes over an in-process `memory://` channel, as it does between a route
|
|
1367
|
+
* and the Node adaptor in one dev process, and is written to MSW's `client`.
|
|
1368
|
+
*
|
|
1369
|
+
* ```ts
|
|
1370
|
+
* const realtime = createMswWebSocketHandlers(surface, [routes], {
|
|
1371
|
+
* url: 'wss://realtime.test',
|
|
1372
|
+
* });
|
|
1373
|
+
* server.use(...realtime.handlers);
|
|
1374
|
+
*
|
|
1375
|
+
* realtime.registerContext(id, { session, services: { database: trx } });
|
|
1376
|
+
* const socket = new WebSocket(`wss://realtime.test/?${TEST_CONTEXT_PARAM}=${id}`);
|
|
1377
|
+
* await sendMessage.request({ services: { realtime: realtime.publisher }, … });
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* There is no handshake to see: a browser-style `WebSocket` sends no headers
|
|
1381
|
+
* a test can set, so the session comes from the registered context (no
|
|
1382
|
+
* context is no session). The Origin check, the heartbeat and close codes
|
|
1383
|
+
* on a real upgrade stay the Node adaptor's.
|
|
1384
|
+
*/
|
|
1385
|
+
/**
|
|
1386
|
+
* The query parameter that names a connection's test context. Read and
|
|
1387
|
+
* removed before `connect()` sees `query`, so the handler never does.
|
|
1388
|
+
*/
|
|
1389
|
+
const TEST_CONTEXT_PARAM = "__gkm_test_context";
|
|
1390
|
+
/**
|
|
1391
|
+
* The close code a refused connection gets: `4000 + status`, so a 401 is
|
|
1392
|
+
* 4401. MSW cannot answer an upgrade with a status line, as a server does.
|
|
1393
|
+
*/
|
|
1394
|
+
const REFUSED_CLOSE_BASE = 4e3;
|
|
1395
|
+
/** A connection whose query names a context no test registered. */
|
|
1396
|
+
var UnknownWebSocketTestContext = class extends Error {
|
|
1397
|
+
id;
|
|
1398
|
+
constructor(id) {
|
|
1399
|
+
super(`No test registered the WebSocket context '${id}'. Call registerContext('${id}', …) before opening the socket, and keep it until it closes.`);
|
|
1400
|
+
this.id = id;
|
|
1401
|
+
this.name = "UnknownWebSocketTestContext";
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
/** The close code a connection with an unknown context is closed with. */
|
|
1405
|
+
const UNKNOWN_CONTEXT_CLOSE = 1011;
|
|
1406
|
+
function createMswWebSocketHandlers(surface, modules, options) {
|
|
1407
|
+
const instance = `msw${(0, node_crypto.randomUUID)().slice(0, 8)}`;
|
|
1408
|
+
const channel = options.channel ?? `gkm:ws:${surface.id}:${instance}`;
|
|
1409
|
+
const transport = new require_websocket_api.MemoryTransport(channel);
|
|
1410
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
1411
|
+
const open = /* @__PURE__ */ new Map();
|
|
1412
|
+
const deliver = (delivery) => {
|
|
1413
|
+
if (delivery.kind === "broadcast") {
|
|
1414
|
+
const except = new Set(delivery.except ?? []);
|
|
1415
|
+
for (const [id, { client }] of open) if (!except.has(id)) client.send(delivery.payload);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
for (const id of delivery.ids) {
|
|
1419
|
+
const client = open.get(id)?.client;
|
|
1420
|
+
if (!client) continue;
|
|
1421
|
+
if (delivery.kind === "send") client.send(delivery.payload);
|
|
1422
|
+
else client.close(delivery.code, delivery.reason);
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
const subscribed = transport.subscribe(instance, deliver);
|
|
1426
|
+
const sink = new require_websocket_api.TransportSink(transport, {
|
|
1427
|
+
instance,
|
|
1428
|
+
deliver
|
|
1429
|
+
});
|
|
1430
|
+
const core = surface.core({
|
|
1431
|
+
envParser: options.envParser ?? surface.envParser,
|
|
1432
|
+
sink,
|
|
1433
|
+
modules
|
|
1434
|
+
});
|
|
1435
|
+
let issued = 0;
|
|
1436
|
+
async function accept(client) {
|
|
1437
|
+
const query = new URLSearchParams(client.url.searchParams);
|
|
1438
|
+
const contextId = query.get(TEST_CONTEXT_PARAM);
|
|
1439
|
+
query.delete(TEST_CONTEXT_PARAM);
|
|
1440
|
+
const context = contextId ? contexts.get(contextId) : {};
|
|
1441
|
+
issued += 1;
|
|
1442
|
+
const connectionId = `${instance}.${issued}`;
|
|
1443
|
+
let accepted = Promise.resolve(void 0);
|
|
1444
|
+
let queue = Promise.resolve();
|
|
1445
|
+
let closed = false;
|
|
1446
|
+
const call = context?.services ? { services: context.services } : {};
|
|
1447
|
+
client.addEventListener("message", (event) => {
|
|
1448
|
+
queue = queue.then(async () => {
|
|
1449
|
+
const connection = await accepted;
|
|
1450
|
+
if (!connection) return;
|
|
1451
|
+
await core.message(connection, await textOrBytes(event.data), (payload) => client.send(payload), call);
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
client.addEventListener("close", (event) => {
|
|
1455
|
+
if (closed) return;
|
|
1456
|
+
closed = true;
|
|
1457
|
+
queue = queue.then(async () => {
|
|
1458
|
+
const connection = await accepted;
|
|
1459
|
+
if (!connection) return;
|
|
1460
|
+
open.delete(connection.id);
|
|
1461
|
+
await core.disconnect(connection, {
|
|
1462
|
+
code: event.code,
|
|
1463
|
+
reason: event.reason
|
|
1464
|
+
}, call);
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
if (!context) {
|
|
1468
|
+
const error = new UnknownWebSocketTestContext(contextId);
|
|
1469
|
+
client.close(UNKNOWN_CONTEXT_CLOSE, error.message.slice(0, 123));
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
accepted = (async () => {
|
|
1473
|
+
await subscribed;
|
|
1474
|
+
const outcome = await core.connect({
|
|
1475
|
+
connectionId,
|
|
1476
|
+
headers: new Headers(),
|
|
1477
|
+
query,
|
|
1478
|
+
session: context.session ?? null
|
|
1479
|
+
}, call);
|
|
1480
|
+
if (!outcome.accepted) {
|
|
1481
|
+
client.close(REFUSED_CLOSE_BASE + outcome.status, outcome.statusText);
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
if (closed) return void 0;
|
|
1485
|
+
open.set(connectionId, {
|
|
1486
|
+
connection: outcome.connection,
|
|
1487
|
+
client
|
|
1488
|
+
});
|
|
1489
|
+
return outcome.connection;
|
|
1490
|
+
})();
|
|
1491
|
+
await accepted;
|
|
1492
|
+
}
|
|
1493
|
+
return {
|
|
1494
|
+
handlers: [msw.ws.link(options.url).addEventListener("connection", ({ client }) => {
|
|
1495
|
+
accept(client);
|
|
1496
|
+
})],
|
|
1497
|
+
registerContext: (id, context) => {
|
|
1498
|
+
contexts.set(id, context);
|
|
1499
|
+
},
|
|
1500
|
+
removeContext: (id) => {
|
|
1501
|
+
contexts.delete(id);
|
|
1502
|
+
},
|
|
1503
|
+
publisher: surface.publisher(new require_websocket_api.TransportSink(new require_websocket_api.MemoryTransport(channel))),
|
|
1504
|
+
connectionString: `memory://${channel}`,
|
|
1505
|
+
get connections() {
|
|
1506
|
+
return [...open.values()].map(({ connection }) => connection);
|
|
1507
|
+
},
|
|
1508
|
+
close: () => transport.close()
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
/** A frame as the core takes it: text, or the bytes it refuses. */
|
|
1512
|
+
async function textOrBytes(data) {
|
|
1513
|
+
if (typeof data === "string") return data;
|
|
1514
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
1515
|
+
if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1516
|
+
if (data instanceof Blob) return new Uint8Array(await data.arrayBuffer());
|
|
1517
|
+
return String(data);
|
|
1518
|
+
}
|
|
1519
|
+
//#endregion
|
|
1520
|
+
exports.DeliveryDidNotSettle = DeliveryDidNotSettle;
|
|
1521
|
+
exports.DeliveryFailed = DeliveryFailed;
|
|
1522
|
+
exports.IN_PROCESS_PEER_ADDRESS = IN_PROCESS_PEER_ADDRESS;
|
|
1523
|
+
exports.InboxNotLocal = InboxNotLocal;
|
|
1524
|
+
exports.InvalidWebSocketRequest = require_websocket_api.InvalidWebSocketRequest;
|
|
1525
|
+
exports.MessageRejected = MessageRejected;
|
|
1526
|
+
exports.NoInbox = NoInbox;
|
|
1527
|
+
exports.NoInboxForAddress = NoInboxForAddress;
|
|
1528
|
+
exports.NoTestManifest = NoTestManifest;
|
|
1529
|
+
exports.REFUSED_CLOSE_BASE = REFUSED_CLOSE_BASE;
|
|
1530
|
+
exports.ReceiveFieldsOrRaw = ReceiveFieldsOrRaw;
|
|
1531
|
+
exports.ReceiveNeedsRecipient = ReceiveNeedsRecipient;
|
|
1532
|
+
exports.SignInFailed = SignInFailed;
|
|
1533
|
+
exports.TEST_CONTEXT_HEADER = _geekmidas_testkit_context.TEST_CONTEXT_HEADER;
|
|
1534
|
+
exports.TEST_CONTEXT_PARAM = TEST_CONTEXT_PARAM;
|
|
1535
|
+
exports.TEST_MANIFEST_ENV = TEST_MANIFEST_ENV;
|
|
415
1536
|
exports.TestEndpointAdaptor = TestEndpointAdaptor;
|
|
416
1537
|
exports.TestFunctionAdaptor = TestFunctionAdaptor;
|
|
417
1538
|
exports.TestQueueAdaptor = TestQueueAdaptor;
|
|
418
1539
|
exports.TestSubscriberAdaptor = TestSubscriberAdaptor;
|
|
1540
|
+
exports.TestWebSocketPublisher = require_websocket_api.TestWebSocketPublisher;
|
|
1541
|
+
exports.UnknownDatabase = UnknownDatabase;
|
|
1542
|
+
exports.UnknownFactory = UnknownFactory;
|
|
1543
|
+
exports.UnknownService = UnknownService;
|
|
1544
|
+
exports.UnknownTestContext = UnknownTestContext;
|
|
1545
|
+
exports.UnknownWebSocketApi = UnknownWebSocketApi;
|
|
1546
|
+
exports.UnknownWebSocketTestContext = UnknownWebSocketTestContext;
|
|
419
1547
|
exports.createMswHandlers = createMswHandlers;
|
|
1548
|
+
exports.createMswWebSocketHandlers = createMswWebSocketHandlers;
|
|
1549
|
+
exports.featureTest = featureTest;
|
|
1550
|
+
exports.inProcessBindings = inProcessBindings;
|
|
1551
|
+
exports.loadTestManifest = loadTestManifest;
|
|
1552
|
+
exports.signInWithMagicLink = signInWithMagicLink;
|
|
420
1553
|
|
|
421
1554
|
//# sourceMappingURL=testing.cjs.map
|