@geekmidas/constructs 7.0.1 → 10.0.0-alpha.0
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 +71 -44
- package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts → AWSScheduledFunction-BvFvBsBN.d.cts} +10 -5
- package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts.map → AWSScheduledFunction-BvFvBsBN.d.cts.map} +1 -1
- package/dist/{AWSScheduledFunction-CTIa90EH.d.cts → AWSScheduledFunction-CVccZO-L.d.mts} +10 -5
- package/dist/{AWSScheduledFunction-CTIa90EH.d.cts.map → AWSScheduledFunction-CVccZO-L.d.mts.map} +1 -1
- package/dist/{AWSScheduledFunction-CufMMhGB.mjs → AWSScheduledFunction-Db1lttJH.mjs} +3 -3
- package/dist/{AWSScheduledFunction-CufMMhGB.mjs.map → AWSScheduledFunction-Db1lttJH.mjs.map} +1 -1
- package/dist/{AWSScheduledFunction-DbkDr8CA.cjs → AWSScheduledFunction-qu4ieRZR.cjs} +9 -9
- package/dist/{AWSScheduledFunction-DbkDr8CA.cjs.map → AWSScheduledFunction-qu4ieRZR.cjs.map} +1 -1
- package/dist/{Construct-_1wX7p_Y.d.cts → Construct-B-xc0SE9.d.mts} +27 -5
- package/dist/Construct-B-xc0SE9.d.mts.map +1 -0
- package/dist/{Construct-r0U2zBwW.mjs → Construct-HmWM6YYu.mjs} +4 -3
- package/dist/Construct-HmWM6YYu.mjs.map +1 -0
- package/dist/{Construct-DCMuYOox.d.mts → Construct-WhCXIOPV.d.cts} +29 -7
- package/dist/Construct-WhCXIOPV.d.cts.map +1 -0
- package/dist/{Construct-vXMZJgRp.cjs → Construct-roId57cU.cjs} +7 -43
- package/dist/Construct-roId57cU.cjs.map +1 -0
- package/dist/{lazyAccessors-DmTG8sQH.cjs → Endpoint-BBkV6l0k.cjs} +869 -1079
- package/dist/Endpoint-BBkV6l0k.cjs.map +1 -0
- package/dist/{lazyAccessors-DfqZR6C4.mjs → Endpoint-BGwpNEX4.mjs} +840 -1003
- package/dist/Endpoint-BGwpNEX4.mjs.map +1 -0
- package/dist/{Endpoint-CAzNbDEt.d.cts → Endpoint-BnxZqIX-.d.cts} +53 -4
- package/dist/Endpoint-BnxZqIX-.d.cts.map +1 -0
- package/dist/{Endpoint-CLPSIl6S.d.mts → Endpoint-ROcXU-eH.d.mts} +55 -6
- package/dist/Endpoint-ROcXU-eH.d.mts.map +1 -0
- package/dist/EndpointFactory-DYoGLaIT.cjs +850 -0
- package/dist/EndpointFactory-DYoGLaIT.cjs.map +1 -0
- package/dist/EndpointFactory-Di0X9AWp.mjs +808 -0
- package/dist/EndpointFactory-Di0X9AWp.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DJDT3PMx.mjs → HonoEndpointAdaptor-DFKIIG2o.mjs} +5 -4
- package/dist/HonoEndpointAdaptor-DFKIIG2o.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-CkJENANP.cjs → HonoEndpointAdaptor-wMsCyMgt.cjs} +24 -23
- package/dist/HonoEndpointAdaptor-wMsCyMgt.cjs.map +1 -0
- package/dist/{Queue-DaxjwmOQ.d.cts → Queue-D6WeziRD.d.cts} +43 -4
- package/dist/Queue-D6WeziRD.d.cts.map +1 -0
- package/dist/{Queue-HBDf0fqz.d.mts → Queue-DpUeqdC8.d.mts} +43 -4
- package/dist/Queue-DpUeqdC8.d.mts.map +1 -0
- package/dist/{Subscriber-B69ngPwl.d.cts → Subscriber-4rBJgDKI.d.mts} +9 -4
- package/dist/{Subscriber-B69ngPwl.d.cts.map → Subscriber-4rBJgDKI.d.mts.map} +1 -1
- package/dist/{Subscriber-D8Xm-86W.d.mts → Subscriber-DVQowdyj.d.cts} +11 -6
- package/dist/Subscriber-DVQowdyj.d.cts.map +1 -0
- package/dist/{Topic-C5ZMfveW.d.cts → Topic-Ohx9dvWr.d.cts} +33 -2
- package/dist/Topic-Ohx9dvWr.d.cts.map +1 -0
- package/dist/{Topic-DT10AqHk.d.mts → Topic-cmy2jOUy.d.mts} +33 -2
- package/dist/Topic-cmy2jOUy.d.mts.map +1 -0
- package/dist/adaptors/aws.cjs +39 -26
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +24 -16
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +25 -17
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +26 -14
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +9 -6
- package/dist/adaptors/hono.d.cts +7 -6
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +8 -7
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +9 -6
- package/dist/adaptors/testing.cjs +18 -14
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +7 -6
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +11 -10
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +10 -7
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth.cjs +165 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +108 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.mts +108 -0
- package/dist/auth.d.mts.map +1 -0
- package/dist/auth.mjs +164 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/cache-0ANvRQnD.mjs +51 -0
- package/dist/cache-0ANvRQnD.mjs.map +1 -0
- package/dist/cache-3WSvAulx.cjs +57 -0
- package/dist/cache-3WSvAulx.cjs.map +1 -0
- package/dist/cache-CdQ7OLpR.d.cts +47 -0
- package/dist/cache-CdQ7OLpR.d.cts.map +1 -0
- package/dist/cache-DYoJFcfd.d.mts +47 -0
- package/dist/cache-DYoJFcfd.d.mts.map +1 -0
- package/dist/cache.cjs +3 -0
- package/dist/cache.d.cts +3 -0
- package/dist/cache.d.mts +3 -0
- package/dist/cache.mjs +3 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/clone-DblgEZZa.mjs +39 -0
- package/dist/clone-DblgEZZa.mjs.map +1 -0
- package/dist/clone-Dy0cR2SZ.cjs +45 -0
- package/dist/clone-Dy0cR2SZ.cjs.map +1 -0
- package/dist/construct-interface-BfjcOD_E.cjs +117 -0
- package/dist/construct-interface-BfjcOD_E.cjs.map +1 -0
- package/dist/construct-interface-BqwRNYA2.d.mts +131 -0
- package/dist/construct-interface-BqwRNYA2.d.mts.map +1 -0
- package/dist/construct-interface-D2nNkHUN.d.cts +131 -0
- package/dist/construct-interface-D2nNkHUN.d.cts.map +1 -0
- package/dist/construct-interface-Z4CpS8tK.mjs +81 -0
- package/dist/construct-interface-Z4CpS8tK.mjs.map +1 -0
- package/dist/construct-interface.cjs +8 -0
- package/dist/construct-interface.d.cts +2 -0
- package/dist/construct-interface.d.mts +2 -0
- package/dist/construct-interface.mjs +3 -0
- package/dist/credential.cjs +96 -0
- package/dist/credential.cjs.map +1 -0
- package/dist/credential.d.cts +61 -0
- package/dist/credential.d.cts.map +1 -0
- package/dist/credential.d.mts +61 -0
- package/dist/credential.d.mts.map +1 -0
- package/dist/credential.mjs +94 -0
- package/dist/credential.mjs.map +1 -0
- package/dist/crons/index.cjs +39 -37
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +21 -8
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +29 -13
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +37 -36
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +181 -0
- package/dist/database/kysely.cjs.map +1 -0
- package/dist/database/kysely.d.cts +152 -0
- package/dist/database/kysely.d.cts.map +1 -0
- package/dist/database/kysely.d.mts +152 -0
- package/dist/database/kysely.d.mts.map +1 -0
- package/dist/database/kysely.mjs +180 -0
- package/dist/database/kysely.mjs.map +1 -0
- package/dist/email.cjs +59 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +50 -0
- package/dist/email.d.cts.map +1 -0
- package/dist/email.d.mts +50 -0
- package/dist/email.d.mts.map +1 -0
- package/dist/email.mjs +58 -0
- package/dist/email.mjs.map +1 -0
- package/dist/endpoints/index.cjs +21 -747
- package/dist/endpoints/index.d.cts +7 -343
- package/dist/endpoints/index.d.mts +7 -342
- package/dist/endpoints/index.mjs +11 -738
- package/dist/file-server.cjs +154 -0
- package/dist/file-server.cjs.map +1 -0
- package/dist/file-server.d.cts +156 -0
- package/dist/file-server.d.cts.map +1 -0
- package/dist/file-server.d.mts +156 -0
- package/dist/file-server.d.mts.map +1 -0
- package/dist/file-server.mjs +152 -0
- package/dist/file-server.mjs.map +1 -0
- package/dist/functions/index.cjs +4 -2
- package/dist/functions/index.d.cts +3 -2
- package/dist/functions/index.d.mts +3 -2
- package/dist/functions/index.mjs +4 -2
- package/dist/{functions-B-qt91O7.mjs → functions-CvT_q7Y4.mjs} +55 -51
- package/dist/functions-CvT_q7Y4.mjs.map +1 -0
- package/dist/{functions-C8i1kCMM.cjs → functions-DukjG8ov.cjs} +62 -57
- package/dist/functions-DukjG8ov.cjs.map +1 -0
- package/dist/index-7OcOWe75.d.cts +419 -0
- package/dist/index-7OcOWe75.d.cts.map +1 -0
- package/dist/index-Bt-F7u8L.d.mts +419 -0
- package/dist/index-Bt-F7u8L.d.mts.map +1 -0
- package/dist/{index-DP6fqv0I.d.mts → index-CPeqtKgq.d.mts} +48 -19
- package/dist/index-CPeqtKgq.d.mts.map +1 -0
- package/dist/{index-BGeTScmi.d.cts → index-Dadljnh_.d.cts} +36 -9
- package/dist/index-Dadljnh_.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lazyAccessors-DM6HcXQk.mjs +175 -0
- package/dist/lazyAccessors-DM6HcXQk.mjs.map +1 -0
- package/dist/lazyAccessors-DrJj8NpA.cjs +223 -0
- package/dist/lazyAccessors-DrJj8NpA.cjs.map +1 -0
- package/dist/object-storage.cjs +48 -0
- package/dist/object-storage.cjs.map +1 -0
- package/dist/object-storage.d.cts +36 -0
- package/dist/object-storage.d.cts.map +1 -0
- package/dist/object-storage.d.mts +36 -0
- package/dist/object-storage.d.mts.map +1 -0
- package/dist/object-storage.mjs +47 -0
- package/dist/object-storage.mjs.map +1 -0
- package/dist/{processAudits-CKjjivyz.cjs → processAudits-Bc8rz6Ev.cjs} +3 -3
- package/dist/{processAudits-CKjjivyz.cjs.map → processAudits-Bc8rz6Ev.cjs.map} +1 -1
- package/dist/{processAudits-ySnizdMG.mjs → processAudits-D89tICM4.mjs} +1 -1
- package/dist/{processAudits-ySnizdMG.mjs.map → processAudits-D89tICM4.mjs.map} +1 -1
- package/dist/{publisher-BrFOF847.mjs → publisher-CGEo8UKD.mjs} +1 -1
- package/dist/{publisher-BrFOF847.mjs.map → publisher-CGEo8UKD.mjs.map} +1 -1
- package/dist/{publisher-lFQleddL.cjs → publisher-CqGsXB2X.cjs} +1 -1
- package/dist/{publisher-lFQleddL.cjs.map → publisher-CqGsXB2X.cjs.map} +1 -1
- package/dist/queue/index.cjs +92 -30
- package/dist/queue/index.cjs.map +1 -1
- package/dist/queue/index.d.cts +19 -4
- package/dist/queue/index.d.cts.map +1 -1
- package/dist/queue/index.d.mts +22 -6
- package/dist/queue/index.d.mts.map +1 -1
- package/dist/queue/index.mjs +90 -29
- package/dist/queue/index.mjs.map +1 -1
- package/dist/rest-api.cjs +187 -0
- package/dist/rest-api.cjs.map +1 -0
- package/dist/rest-api.d.cts +221 -0
- package/dist/rest-api.d.cts.map +1 -0
- package/dist/rest-api.d.mts +221 -0
- package/dist/rest-api.d.mts.map +1 -0
- package/dist/rest-api.mjs +186 -0
- package/dist/rest-api.mjs.map +1 -0
- package/dist/site.cjs +48 -0
- package/dist/site.cjs.map +1 -0
- package/dist/site.d.cts +101 -0
- package/dist/site.d.cts.map +1 -0
- package/dist/site.d.mts +101 -0
- package/dist/site.d.mts.map +1 -0
- package/dist/site.mjs +47 -0
- package/dist/site.mjs.map +1 -0
- package/dist/subscribers/index.cjs +35 -27
- package/dist/subscribers/index.cjs.map +1 -1
- package/dist/subscribers/index.d.cts +20 -5
- package/dist/subscribers/index.d.cts.map +1 -1
- package/dist/subscribers/index.d.mts +23 -7
- package/dist/subscribers/index.d.mts.map +1 -1
- package/dist/subscribers/index.mjs +34 -27
- package/dist/subscribers/index.mjs.map +1 -1
- package/dist/surfaceEnv-BFXEms2f.cjs +39 -0
- package/dist/surfaceEnv-BFXEms2f.cjs.map +1 -0
- package/dist/surfaceEnv-C3Ktahea.mjs +27 -0
- package/dist/surfaceEnv-C3Ktahea.mjs.map +1 -0
- package/dist/{telemetry-3vdxGn4q.d.mts → telemetry-C3L0iS28.d.cts} +2 -2
- package/dist/{telemetry-3vdxGn4q.d.mts.map → telemetry-C3L0iS28.d.cts.map} +1 -1
- package/dist/{telemetry-Dqx-D3F7.d.cts → telemetry-D7bVFLGi.d.mts} +2 -2
- package/dist/{telemetry-Dqx-D3F7.d.cts.map → telemetry-D7bVFLGi.d.mts.map} +1 -1
- package/dist/topic/index.cjs +56 -13
- package/dist/topic/index.cjs.map +1 -1
- package/dist/topic/index.d.cts +2 -2
- package/dist/topic/index.d.cts.map +1 -1
- package/dist/topic/index.d.mts +2 -2
- package/dist/topic/index.d.mts.map +1 -1
- package/dist/topic/index.mjs +54 -12
- package/dist/topic/index.mjs.map +1 -1
- package/dist/{types-BDNGr7pv.d.mts → types-BlAkSuGI.d.cts} +1 -1
- package/dist/{types-BDNGr7pv.d.mts.map → types-BlAkSuGI.d.cts.map} +1 -1
- package/dist/{types-BdAaYDvd.d.cts → types-aKksMEWL.d.mts} +1 -1
- package/dist/{types-BdAaYDvd.d.cts.map → types-aKksMEWL.d.mts.map} +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +155 -23
- package/CHANGELOG.md +0 -366
- package/dist/Construct-DCMuYOox.d.mts.map +0 -1
- package/dist/Construct-_1wX7p_Y.d.cts.map +0 -1
- package/dist/Construct-r0U2zBwW.mjs.map +0 -1
- package/dist/Construct-vXMZJgRp.cjs.map +0 -1
- package/dist/Endpoint-CAzNbDEt.d.cts.map +0 -1
- package/dist/Endpoint-CLPSIl6S.d.mts.map +0 -1
- package/dist/HonoEndpointAdaptor-CkJENANP.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DJDT3PMx.mjs.map +0 -1
- package/dist/Queue-DaxjwmOQ.d.cts.map +0 -1
- package/dist/Queue-HBDf0fqz.d.mts.map +0 -1
- package/dist/Subscriber-D8Xm-86W.d.mts.map +0 -1
- package/dist/Topic-C5ZMfveW.d.cts.map +0 -1
- package/dist/Topic-DT10AqHk.d.mts.map +0 -1
- package/dist/endpoints/index.cjs.map +0 -1
- package/dist/endpoints/index.d.cts.map +0 -1
- package/dist/endpoints/index.d.mts.map +0 -1
- package/dist/endpoints/index.mjs.map +0 -1
- package/dist/functions-B-qt91O7.mjs.map +0 -1
- package/dist/functions-C8i1kCMM.cjs.map +0 -1
- package/dist/index-BGeTScmi.d.cts.map +0 -1
- package/dist/index-DP6fqv0I.d.mts.map +0 -1
- package/dist/lazyAccessors-DfqZR6C4.mjs.map +0 -1
- package/dist/lazyAccessors-DmTG8sQH.cjs.map +0 -1
- package/src/Construct.ts +0 -204
- package/src/__benchmarks__/build-time-optimization.bench.ts +0 -274
- package/src/__benchmarks__/endpoint.bench.ts +0 -494
- package/src/__benchmarks__/fixtures.ts +0 -241
- package/src/__benchmarks__/hono-adaptor.bench.ts +0 -533
- package/src/__benchmarks__/hono-server.bench.ts +0 -249
- package/src/__benchmarks__/response-builder.bench.ts +0 -428
- package/src/__benchmarks__/strategies/strategy-a-lazy-services.ts +0 -319
- package/src/__benchmarks__/strategies/strategy-c-middleware.ts +0 -530
- package/src/__benchmarks__/strategies/strategy-d-opt-in-events.ts +0 -567
- package/src/__tests__/Construct.environment.spec.ts +0 -704
- package/src/__tests__/publisher.setting.spec.ts +0 -508
- package/src/__tests__/publisher.spec.ts +0 -452
- package/src/adaptors/aws.ts +0 -6
- package/src/adaptors/hono.ts +0 -1
- package/src/adaptors/testing.ts +0 -11
- package/src/crons/AWSScheduledFunction.ts +0 -73
- package/src/crons/Cron.ts +0 -149
- package/src/crons/CronBuilder.ts +0 -271
- package/src/crons/__tests__/AWSScheduledFunction.spec.ts +0 -152
- package/src/crons/__tests__/Cron.spec.ts +0 -464
- package/src/crons/__tests__/CronBuilder.state-isolation.spec.ts +0 -227
- package/src/crons/index.ts +0 -12
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +0 -677
- package/src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts +0 -105
- package/src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts +0 -97
- package/src/endpoints/Authorizer.ts +0 -152
- package/src/endpoints/Endpoint.ts +0 -1287
- package/src/endpoints/EndpointBuilder.ts +0 -758
- package/src/endpoints/EndpointFactory.ts +0 -1148
- package/src/endpoints/HonoEndpointAdaptor.ts +0 -677
- package/src/endpoints/MswEndpointAdaptor.ts +0 -226
- package/src/endpoints/TestEndpointAdaptor.ts +0 -422
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.audits.spec.ts +0 -499
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.events.spec.ts +0 -560
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.spec.ts +0 -1304
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.audits.spec.ts +0 -626
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.events.spec.ts +0 -732
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.factory-publisher.spec.ts +0 -296
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.kysely-audit.integration.spec.ts +0 -951
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.responseType.spec.ts +0 -111
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.rls.spec.ts +0 -307
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.spec.ts +0 -629
- package/src/endpoints/__tests__/Authorizer.spec.ts +0 -286
- package/src/endpoints/__tests__/Endpoint.cookies.spec.ts +0 -207
- package/src/endpoints/__tests__/Endpoint.headers.spec.ts +0 -187
- package/src/endpoints/__tests__/Endpoint.manifest.spec.ts +0 -175
- package/src/endpoints/__tests__/Endpoint.spec.ts +0 -857
- package/src/endpoints/__tests__/EndpointBuilder.audit.spec.ts +0 -448
- package/src/endpoints/__tests__/EndpointBuilder.responseType.spec.ts +0 -47
- package/src/endpoints/__tests__/EndpointBuilder.spec.ts +0 -523
- package/src/endpoints/__tests__/EndpointFactory.authorizers.spec.ts +0 -492
- package/src/endpoints/__tests__/EndpointFactory.database-auditor.spec.ts +0 -509
- package/src/endpoints/__tests__/EndpointFactory.reference-audit.spec.ts +0 -190
- package/src/endpoints/__tests__/EndpointFactory.spec.ts +0 -479
- package/src/endpoints/__tests__/EndpointFactory.state-isolation.spec.ts +0 -155
- package/src/endpoints/__tests__/HonoEndpointAdaptor.audit-transactions.spec.ts +0 -703
- package/src/endpoints/__tests__/HonoEndpointAdaptor.audits.spec.ts +0 -632
- package/src/endpoints/__tests__/HonoEndpointAdaptor.events.spec.ts +0 -577
- package/src/endpoints/__tests__/HonoEndpointAdaptor.kysely-audit.integration.spec.ts +0 -1067
- package/src/endpoints/__tests__/HonoEndpointAdaptor.openapi.spec.ts +0 -317
- package/src/endpoints/__tests__/HonoEndpointAdaptor.pgboss-publisher.spec.ts +0 -289
- package/src/endpoints/__tests__/HonoEndpointAdaptor.responseType.spec.ts +0 -128
- package/src/endpoints/__tests__/HonoEndpointAdaptor.spec.ts +0 -1207
- package/src/endpoints/__tests__/MswEndpointAdaptor.spec.ts +0 -211
- package/src/endpoints/__tests__/ResponseBuilder.spec.ts +0 -235
- package/src/endpoints/__tests__/TestEndpointAdaptor.audits.spec.ts +0 -602
- package/src/endpoints/__tests__/TestEndpointAdaptor.spec.ts +0 -1044
- package/src/endpoints/__tests__/__snapshots__/HonoEndpointAdaptor.spec.ts.snap +0 -54
- package/src/endpoints/__tests__/endpoint-types.test.ts +0 -88
- package/src/endpoints/__tests__/helpers.spec.ts +0 -37
- package/src/endpoints/__tests__/lazyAccessors.spec.ts +0 -330
- package/src/endpoints/__tests__/processAudits.spec.ts +0 -631
- package/src/endpoints/audit.ts +0 -87
- package/src/endpoints/helpers.ts +0 -98
- package/src/endpoints/index.ts +0 -42
- package/src/endpoints/lazyAccessors.ts +0 -241
- package/src/endpoints/parseHonoQuery.ts +0 -16
- package/src/endpoints/parseQueryParams.ts +0 -32
- package/src/endpoints/processAudits.ts +0 -371
- package/src/endpoints/rls.ts +0 -67
- package/src/functions/AWSLambdaFunction.ts +0 -348
- package/src/functions/BaseFunctionBuilder.ts +0 -201
- package/src/functions/Function.ts +0 -238
- package/src/functions/FunctionBuilder.ts +0 -391
- package/src/functions/FunctionExecutionWrapper.ts +0 -216
- package/src/functions/TestFunctionAdaptor.ts +0 -217
- package/src/functions/__tests__/AWSLambdaFunctionAdaptor.spec.ts +0 -513
- package/src/functions/__tests__/Function.audits.spec.ts +0 -393
- package/src/functions/__tests__/Function.spec.ts +0 -477
- package/src/functions/__tests__/FunctionBuilder.state-isolation.spec.ts +0 -207
- package/src/functions/__tests__/TestFunctionAdaptor.spec.ts +0 -480
- package/src/functions/index.ts +0 -12
- package/src/index.ts +0 -23
- package/src/publisher.ts +0 -93
- package/src/queue/AWSLambdaQueueAdaptor.ts +0 -162
- package/src/queue/Queue.ts +0 -128
- package/src/queue/QueueBuilder.ts +0 -115
- package/src/queue/TestQueueAdaptor.ts +0 -63
- package/src/queue/__tests__/QueueBuilder.spec.ts +0 -137
- package/src/queue/index.ts +0 -12
- package/src/subscribers/AWSLambdaSubscriberAdaptor.ts +0 -342
- package/src/subscribers/Subscriber.ts +0 -117
- package/src/subscribers/SubscriberBuilder.ts +0 -186
- package/src/subscribers/TestSubscriberAdaptor.ts +0 -133
- package/src/subscribers/__tests__/AWSLambdaSubscriberAdaptor.spec.ts +0 -1018
- package/src/subscribers/__tests__/Subscriber.spec.ts +0 -430
- package/src/subscribers/__tests__/TestSubscriberAdaptor.spec.ts +0 -652
- package/src/subscribers/index.ts +0 -6
- package/src/telemetry.ts +0 -103
- package/src/topic/Topic.ts +0 -103
- package/src/topic/TopicBuilder.ts +0 -51
- package/src/topic/__tests__/TopicBuilder.spec.ts +0 -82
- package/src/topic/index.ts +0 -11
- package/src/types.ts +0 -13
- package/test.ts +0 -91
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -34
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { EnvironmentParser } from '@geekmidas/envkit';
|
|
2
|
-
import type { Service } from '@geekmidas/services';
|
|
3
|
-
import { ServiceDiscovery } from '@geekmidas/services';
|
|
4
|
-
import { Hono } from 'hono';
|
|
5
|
-
import { type HttpHandler, http } from 'msw';
|
|
6
|
-
import type { Endpoint } from './Endpoint';
|
|
7
|
-
import { HonoEndpoint } from './HonoEndpointAdaptor';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Header used to identify which test context a request belongs to.
|
|
11
|
-
* Each concurrent test registers its own context (services, db transaction, etc.)
|
|
12
|
-
* and the MSW handler looks it up by this header value.
|
|
13
|
-
*/
|
|
14
|
-
export const TEST_CONTEXT_HEADER = 'x-test-context-id';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Per-test context containing an isolated ServiceDiscovery instance.
|
|
18
|
-
* Registered in the context map and looked up per-request via the context ID header.
|
|
19
|
-
*/
|
|
20
|
-
export interface MswTestContext {
|
|
21
|
-
serviceDiscovery: ServiceDiscovery<any>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Options for creating MSW handlers from endpoint constructs.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { createMswHandlers, registerTestContext } from '@geekmidas/constructs/testing';
|
|
30
|
-
* import { setupServer } from 'msw/node';
|
|
31
|
-
*
|
|
32
|
-
* // Create handlers once (global)
|
|
33
|
-
* const { handlers, registerContext, removeContext } = createMswHandlers(
|
|
34
|
-
* [getUsers, createUser],
|
|
35
|
-
* { baseURL: 'http://localhost:3000' },
|
|
36
|
-
* );
|
|
37
|
-
* const server = setupServer(...handlers);
|
|
38
|
-
*
|
|
39
|
-
* // Per test: register an isolated context with its own services/transaction
|
|
40
|
-
* it('should list users', async ({ db }) => {
|
|
41
|
-
* const contextId = crypto.randomUUID();
|
|
42
|
-
* registerContext(contextId, {
|
|
43
|
-
* services: { database: db, auth: mockAuth },
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* const api = createApi({
|
|
47
|
-
* baseURL: 'http://localhost:3000',
|
|
48
|
-
* headers: { [TEST_CONTEXT_HEADER]: contextId },
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* const result = await api('GET /users');
|
|
52
|
-
* expect(result).toBeDefined();
|
|
53
|
-
*
|
|
54
|
-
* removeContext(contextId);
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export interface CreateMswHandlersOptions {
|
|
59
|
-
/** Base URL the client fetches from (e.g., 'http://localhost:3000') */
|
|
60
|
-
baseURL: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Options for registering a per-test context.
|
|
65
|
-
* Follows the same pattern as TestRequestAdaptor — services, database,
|
|
66
|
-
* publisher, and auditorStorage are provided explicitly.
|
|
67
|
-
*/
|
|
68
|
-
export interface RegisterContextOptions {
|
|
69
|
-
/** Service instances keyed by serviceName */
|
|
70
|
-
services?: Record<string, unknown>;
|
|
71
|
-
/** Database instance — required when endpoints use .database() */
|
|
72
|
-
database?: unknown;
|
|
73
|
-
/** Event publisher service definition */
|
|
74
|
-
publisher?: Service;
|
|
75
|
-
/** Audit storage instance — required when endpoints use .auditor() */
|
|
76
|
-
auditorStorage?: unknown;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const MSW_HTTP_METHODS = [
|
|
80
|
-
'get',
|
|
81
|
-
'post',
|
|
82
|
-
'put',
|
|
83
|
-
'patch',
|
|
84
|
-
'delete',
|
|
85
|
-
'options',
|
|
86
|
-
] as const;
|
|
87
|
-
|
|
88
|
-
type MswHttpMethod = (typeof MSW_HTTP_METHODS)[number];
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Result of creating MSW handlers from endpoint constructs.
|
|
92
|
-
*/
|
|
93
|
-
export interface CreateMswHandlersResult {
|
|
94
|
-
/** MSW handlers to pass to setupServer() */
|
|
95
|
-
handlers: HttpHandler[];
|
|
96
|
-
/** Register an isolated context for a test */
|
|
97
|
-
registerContext: (id: string, options: RegisterContextOptions) => void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Creates MSW HTTP handlers from endpoint constructs.
|
|
102
|
-
*
|
|
103
|
-
* Mounts endpoints on a Hono app and creates MSW handlers that intercept
|
|
104
|
-
* fetch requests and route them through `app.request()` — giving frontend
|
|
105
|
-
* tests full endpoint behavior (validation, auth, sessions) without HTTP.
|
|
106
|
-
*
|
|
107
|
-
* Each test registers its own isolated context via `registerContext()`,
|
|
108
|
-
* which is resolved per-request using the `x-test-context-id` header.
|
|
109
|
-
* This allows concurrent tests with their own transactions and services.
|
|
110
|
-
*
|
|
111
|
-
* @param endpoints - Array of endpoint constructs to create handlers for
|
|
112
|
-
* @param options - Configuration including baseURL
|
|
113
|
-
* @returns MSW handlers, the Hono app, and context management functions
|
|
114
|
-
*/
|
|
115
|
-
export function createMswHandlers(
|
|
116
|
-
endpoints: Endpoint<any, any, any, any, any, any>[],
|
|
117
|
-
options: CreateMswHandlersOptions,
|
|
118
|
-
): CreateMswHandlersResult {
|
|
119
|
-
const { baseURL } = options;
|
|
120
|
-
const contexts = new Map<string, MswTestContext>();
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Register an isolated context for a test.
|
|
124
|
-
* Creates a fresh ServiceDiscovery and pre-registers all provided services.
|
|
125
|
-
*/
|
|
126
|
-
function registerContext(id: string, ctxOptions: RegisterContextOptions) {
|
|
127
|
-
const envParser = new EnvironmentParser({});
|
|
128
|
-
const serviceDiscovery = new ServiceDiscovery(envParser);
|
|
129
|
-
|
|
130
|
-
const serviceDefs: Service[] = [];
|
|
131
|
-
|
|
132
|
-
// Register explicit services
|
|
133
|
-
if (ctxOptions.services) {
|
|
134
|
-
for (const [name, instance] of Object.entries(ctxOptions.services)) {
|
|
135
|
-
serviceDefs.push({
|
|
136
|
-
serviceName: name,
|
|
137
|
-
register: () => instance,
|
|
138
|
-
} as Service);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Register database service from endpoint metadata
|
|
143
|
-
if (ctxOptions.database !== undefined) {
|
|
144
|
-
for (const endpoint of endpoints) {
|
|
145
|
-
if (endpoint.databaseService) {
|
|
146
|
-
serviceDefs.push({
|
|
147
|
-
serviceName: endpoint.databaseService.serviceName,
|
|
148
|
-
register: () => ctxOptions.database,
|
|
149
|
-
} as Service);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Register publisher service
|
|
156
|
-
if (ctxOptions.publisher) {
|
|
157
|
-
serviceDefs.push(ctxOptions.publisher);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Register auditor storage service from endpoint metadata
|
|
161
|
-
if (ctxOptions.auditorStorage !== undefined) {
|
|
162
|
-
for (const endpoint of endpoints) {
|
|
163
|
-
if (endpoint.auditorStorageService) {
|
|
164
|
-
serviceDefs.push({
|
|
165
|
-
serviceName: endpoint.auditorStorageService.serviceName,
|
|
166
|
-
register: () => ctxOptions.auditorStorage,
|
|
167
|
-
} as Service);
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (serviceDefs.length > 0) {
|
|
174
|
-
serviceDiscovery.register(serviceDefs);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
contexts.set(id, { serviceDiscovery });
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Create a Hono app per-request that uses the correct ServiceDiscovery.
|
|
181
|
-
// We use a wrapper app that resolves the context from the header,
|
|
182
|
-
// then delegates to a context-specific Hono app.
|
|
183
|
-
const handlers: HttpHandler[] = [];
|
|
184
|
-
|
|
185
|
-
for (const endpoint of endpoints) {
|
|
186
|
-
const method = endpoint.method.toLowerCase() as MswHttpMethod;
|
|
187
|
-
if (!MSW_HTTP_METHODS.includes(method)) continue;
|
|
188
|
-
|
|
189
|
-
const mswUrl = `${baseURL}${endpoint.route}`;
|
|
190
|
-
const mswMethod = http[method];
|
|
191
|
-
|
|
192
|
-
handlers.push(
|
|
193
|
-
mswMethod(mswUrl, async ({ request }) => {
|
|
194
|
-
const contextId = request.headers.get(TEST_CONTEXT_HEADER);
|
|
195
|
-
const ctx = contextId ? contexts.get(contextId) : undefined;
|
|
196
|
-
|
|
197
|
-
if (!ctx) {
|
|
198
|
-
return new Response(
|
|
199
|
-
JSON.stringify({
|
|
200
|
-
error: 'Missing or unknown test context ID',
|
|
201
|
-
hint: `Set the '${TEST_CONTEXT_HEADER}' header to a registered context ID`,
|
|
202
|
-
}),
|
|
203
|
-
{ status: 500, headers: { 'content-type': 'application/json' } },
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Build a fresh Hono app with this context's ServiceDiscovery
|
|
208
|
-
const app = new Hono();
|
|
209
|
-
HonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery as any, app);
|
|
210
|
-
|
|
211
|
-
const response = await app.request(request);
|
|
212
|
-
|
|
213
|
-
return new Response(response.body, {
|
|
214
|
-
status: response.status,
|
|
215
|
-
statusText: response.statusText,
|
|
216
|
-
headers: response.headers,
|
|
217
|
-
});
|
|
218
|
-
}),
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
handlers,
|
|
224
|
-
registerContext,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AuditActor,
|
|
3
|
-
AuditableAction,
|
|
4
|
-
AuditStorage,
|
|
5
|
-
} from '@geekmidas/audit';
|
|
6
|
-
import { DefaultAuditor } from '@geekmidas/audit';
|
|
7
|
-
import { EnvironmentParser } from '@geekmidas/envkit';
|
|
8
|
-
import { ForbiddenError } from '@geekmidas/errors';
|
|
9
|
-
import type { EventPublisher } from '@geekmidas/events';
|
|
10
|
-
import type { Logger } from '@geekmidas/logger';
|
|
11
|
-
import type {
|
|
12
|
-
InferComposableStandardSchema,
|
|
13
|
-
InferStandardSchema,
|
|
14
|
-
} from '@geekmidas/schema';
|
|
15
|
-
import {
|
|
16
|
-
runWithRequestContext,
|
|
17
|
-
type Service,
|
|
18
|
-
ServiceDiscovery,
|
|
19
|
-
type ServiceRecord,
|
|
20
|
-
} from '@geekmidas/services';
|
|
21
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
22
|
-
import { publishConstructEvents } from '../publisher';
|
|
23
|
-
import type { HttpMethod } from '../types';
|
|
24
|
-
import type { MappedAudit } from './audit';
|
|
25
|
-
import {
|
|
26
|
-
type CookieOptions,
|
|
27
|
-
Endpoint,
|
|
28
|
-
type EndpointSchemas,
|
|
29
|
-
ResponseBuilder,
|
|
30
|
-
} from './Endpoint';
|
|
31
|
-
import {
|
|
32
|
-
createCookieHeaderAccessor,
|
|
33
|
-
createObjectHeaders,
|
|
34
|
-
} from './lazyAccessors';
|
|
35
|
-
import {
|
|
36
|
-
type AuditExecutionContext,
|
|
37
|
-
executeWithAuditTransaction,
|
|
38
|
-
} from './processAudits';
|
|
39
|
-
|
|
40
|
-
export type TestHttpResponse<TBody = any> = {
|
|
41
|
-
body: TBody;
|
|
42
|
-
status: number;
|
|
43
|
-
headers: Record<string, string | string[]>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Serializes a cookie into a Set-Cookie header string
|
|
48
|
-
*/
|
|
49
|
-
function serializeCookie(
|
|
50
|
-
name: string,
|
|
51
|
-
value: string,
|
|
52
|
-
options?: CookieOptions,
|
|
53
|
-
): string {
|
|
54
|
-
let cookieString = `${name}=${value}`;
|
|
55
|
-
|
|
56
|
-
if (options) {
|
|
57
|
-
if (options.maxAge !== undefined) {
|
|
58
|
-
cookieString += `; Max-Age=${options.maxAge}`;
|
|
59
|
-
}
|
|
60
|
-
if (options.expires) {
|
|
61
|
-
cookieString += `; Expires=${options.expires.toUTCString()}`;
|
|
62
|
-
}
|
|
63
|
-
if (options.domain) {
|
|
64
|
-
cookieString += `; Domain=${options.domain}`;
|
|
65
|
-
}
|
|
66
|
-
if (options.path) {
|
|
67
|
-
cookieString += `; Path=${options.path}`;
|
|
68
|
-
}
|
|
69
|
-
if (options.httpOnly) {
|
|
70
|
-
cookieString += '; HttpOnly';
|
|
71
|
-
}
|
|
72
|
-
if (options.secure) {
|
|
73
|
-
cookieString += '; Secure';
|
|
74
|
-
}
|
|
75
|
-
if (options.sameSite) {
|
|
76
|
-
cookieString += `; SameSite=${options.sameSite}`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return cookieString;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class TestEndpointAdaptor<
|
|
84
|
-
TRoute extends string,
|
|
85
|
-
TMethod extends HttpMethod,
|
|
86
|
-
TInput extends EndpointSchemas = {},
|
|
87
|
-
TOutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
88
|
-
TServices extends Service[] = [],
|
|
89
|
-
TLogger extends Logger = Logger,
|
|
90
|
-
TSession = unknown,
|
|
91
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
92
|
-
TEventPublisherServiceName extends string = string,
|
|
93
|
-
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
94
|
-
TAuditStorageServiceName extends string = string,
|
|
95
|
-
TAuditAction extends AuditableAction<string, unknown> = AuditableAction<
|
|
96
|
-
string,
|
|
97
|
-
unknown
|
|
98
|
-
>,
|
|
99
|
-
TDatabase = undefined,
|
|
100
|
-
TDatabaseServiceName extends string = string,
|
|
101
|
-
> {
|
|
102
|
-
static getDefaultServiceDiscover<
|
|
103
|
-
TRoute extends string,
|
|
104
|
-
TMethod extends HttpMethod,
|
|
105
|
-
TInput extends EndpointSchemas = {},
|
|
106
|
-
TOutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
107
|
-
TServices extends Service[] = [],
|
|
108
|
-
TLogger extends Logger = Logger,
|
|
109
|
-
TSession = unknown,
|
|
110
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
111
|
-
TEventPublisherServiceName extends string = string,
|
|
112
|
-
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
113
|
-
TAuditStorageServiceName extends string = string,
|
|
114
|
-
TAuditAction extends AuditableAction<string, unknown> = AuditableAction<
|
|
115
|
-
string,
|
|
116
|
-
unknown
|
|
117
|
-
>,
|
|
118
|
-
TDatabase = undefined,
|
|
119
|
-
TDatabaseServiceName extends string = string,
|
|
120
|
-
>(
|
|
121
|
-
_endpoint: Endpoint<
|
|
122
|
-
TRoute,
|
|
123
|
-
TMethod,
|
|
124
|
-
TInput,
|
|
125
|
-
TOutSchema,
|
|
126
|
-
TServices,
|
|
127
|
-
TLogger,
|
|
128
|
-
TSession,
|
|
129
|
-
TEventPublisher,
|
|
130
|
-
TEventPublisherServiceName,
|
|
131
|
-
TAuditStorage,
|
|
132
|
-
TAuditStorageServiceName,
|
|
133
|
-
TAuditAction,
|
|
134
|
-
TDatabase,
|
|
135
|
-
TDatabaseServiceName
|
|
136
|
-
>,
|
|
137
|
-
) {
|
|
138
|
-
return ServiceDiscovery.getInstance(new EnvironmentParser({}));
|
|
139
|
-
}
|
|
140
|
-
constructor(
|
|
141
|
-
private readonly endpoint: Endpoint<
|
|
142
|
-
TRoute,
|
|
143
|
-
TMethod,
|
|
144
|
-
TInput,
|
|
145
|
-
TOutSchema,
|
|
146
|
-
TServices,
|
|
147
|
-
TLogger,
|
|
148
|
-
TSession,
|
|
149
|
-
TEventPublisher,
|
|
150
|
-
TEventPublisherServiceName,
|
|
151
|
-
TAuditStorage,
|
|
152
|
-
TAuditStorageServiceName,
|
|
153
|
-
TAuditAction,
|
|
154
|
-
TDatabase,
|
|
155
|
-
TDatabaseServiceName
|
|
156
|
-
>,
|
|
157
|
-
private serviceDiscovery: ServiceDiscovery<any> = TestEndpointAdaptor.getDefaultServiceDiscover(
|
|
158
|
-
endpoint,
|
|
159
|
-
),
|
|
160
|
-
) {}
|
|
161
|
-
|
|
162
|
-
async fullRequest(
|
|
163
|
-
ctx: TestRequestAdaptor<
|
|
164
|
-
TInput,
|
|
165
|
-
TServices,
|
|
166
|
-
TEventPublisher,
|
|
167
|
-
TEventPublisherServiceName,
|
|
168
|
-
TAuditStorage,
|
|
169
|
-
TAuditStorageServiceName,
|
|
170
|
-
TDatabase,
|
|
171
|
-
TDatabaseServiceName
|
|
172
|
-
>,
|
|
173
|
-
): Promise<TestHttpResponse<InferStandardSchema<TOutSchema>>> {
|
|
174
|
-
const body = await this.endpoint.parseInput((ctx as any).body, 'body');
|
|
175
|
-
const query = await this.endpoint.parseInput((ctx as any).query, 'query');
|
|
176
|
-
const params = await this.endpoint.parseInput(
|
|
177
|
-
(ctx as any).params,
|
|
178
|
-
'params',
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
// Lazy accessors - defer parsing until needed
|
|
182
|
-
const header = createObjectHeaders(ctx.headers);
|
|
183
|
-
const cookie = createCookieHeaderAccessor(ctx.headers.cookie);
|
|
184
|
-
|
|
185
|
-
// Request context setup
|
|
186
|
-
const startTime = Date.now();
|
|
187
|
-
const requestId =
|
|
188
|
-
(ctx as any).requestId ??
|
|
189
|
-
ctx.headers['x-request-id'] ??
|
|
190
|
-
crypto.randomUUID();
|
|
191
|
-
|
|
192
|
-
const logger = this.endpoint.logger.child({
|
|
193
|
-
requestId,
|
|
194
|
-
route: this.endpoint.route,
|
|
195
|
-
host: ctx.headers.host,
|
|
196
|
-
method: this.endpoint.method,
|
|
197
|
-
}) as TLogger;
|
|
198
|
-
|
|
199
|
-
// Get database from context for session extraction
|
|
200
|
-
const rawDb = (ctx as any).database as TDatabase;
|
|
201
|
-
|
|
202
|
-
// Wrap handler execution in request context
|
|
203
|
-
return runWithRequestContext({ logger, requestId, startTime }, async () => {
|
|
204
|
-
const session = await this.endpoint.getSession({
|
|
205
|
-
logger,
|
|
206
|
-
services: ctx.services,
|
|
207
|
-
header,
|
|
208
|
-
cookie,
|
|
209
|
-
...(rawDb !== undefined && { db: rawDb }),
|
|
210
|
-
} as any);
|
|
211
|
-
|
|
212
|
-
// Check authorization
|
|
213
|
-
const isAuthorized = await this.endpoint.authorize({
|
|
214
|
-
header,
|
|
215
|
-
cookie,
|
|
216
|
-
services: ctx.services,
|
|
217
|
-
logger,
|
|
218
|
-
session,
|
|
219
|
-
...(rawDb !== undefined && { db: rawDb }),
|
|
220
|
-
body,
|
|
221
|
-
query,
|
|
222
|
-
params,
|
|
223
|
-
} as any);
|
|
224
|
-
|
|
225
|
-
if (!isAuthorized) {
|
|
226
|
-
logger.warn('Forbidden access attempt');
|
|
227
|
-
throw new ForbiddenError(
|
|
228
|
-
'Forbidden access to the endpoint',
|
|
229
|
-
'You do not have permission to access this resource.',
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Create audit context if audit storage is provided
|
|
234
|
-
// The auditorStorage instance is required when endpoint uses .auditor()
|
|
235
|
-
const auditorStorage = (ctx as any).auditorStorage as TAuditStorage;
|
|
236
|
-
let auditContext: AuditExecutionContext<TAuditAction> | undefined;
|
|
237
|
-
|
|
238
|
-
if (auditorStorage) {
|
|
239
|
-
// Extract actor if configured
|
|
240
|
-
let actor: AuditActor = { id: 'system', type: 'system' };
|
|
241
|
-
if (this.endpoint.actorExtractor) {
|
|
242
|
-
try {
|
|
243
|
-
actor = await this.endpoint.actorExtractor({
|
|
244
|
-
services: ctx.services as any,
|
|
245
|
-
session,
|
|
246
|
-
header,
|
|
247
|
-
cookie,
|
|
248
|
-
logger,
|
|
249
|
-
});
|
|
250
|
-
} catch (error) {
|
|
251
|
-
logger.error(error as Error, 'Failed to extract actor for audits');
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const auditor = new DefaultAuditor<TAuditAction>({
|
|
256
|
-
actor,
|
|
257
|
-
storage: auditorStorage as AuditStorage,
|
|
258
|
-
metadata: {
|
|
259
|
-
endpoint: this.endpoint.route,
|
|
260
|
-
method: this.endpoint.method,
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
auditContext = { auditor, storage: auditorStorage as AuditStorage };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Warn if declarative audits are configured but no audit storage
|
|
268
|
-
const audits = this.endpoint.audits as MappedAudit<
|
|
269
|
-
TAuditAction,
|
|
270
|
-
TOutSchema
|
|
271
|
-
>[];
|
|
272
|
-
if (!auditContext && audits?.length) {
|
|
273
|
-
logger.warn('No auditor storage service available');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Execute handler with automatic audit transaction support
|
|
277
|
-
const result = await executeWithAuditTransaction(
|
|
278
|
-
auditContext,
|
|
279
|
-
async (auditor) => {
|
|
280
|
-
// Use audit transaction as db if available (when storage has same database)
|
|
281
|
-
// For testing, the tester controls whether to use transactional auditing
|
|
282
|
-
const trx = auditor?.getTransaction?.();
|
|
283
|
-
const db = trx ?? rawDb;
|
|
284
|
-
|
|
285
|
-
const responseBuilder = new ResponseBuilder();
|
|
286
|
-
const response = await this.endpoint.handler(
|
|
287
|
-
{
|
|
288
|
-
body,
|
|
289
|
-
query,
|
|
290
|
-
params,
|
|
291
|
-
session,
|
|
292
|
-
services: ctx.services,
|
|
293
|
-
logger,
|
|
294
|
-
header,
|
|
295
|
-
cookie,
|
|
296
|
-
auditor,
|
|
297
|
-
db,
|
|
298
|
-
} as any,
|
|
299
|
-
responseBuilder,
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
// Check if response has metadata
|
|
303
|
-
let data = response;
|
|
304
|
-
let metadata = responseBuilder.getMetadata();
|
|
305
|
-
|
|
306
|
-
if (Endpoint.hasMetadata(response)) {
|
|
307
|
-
data = response.data;
|
|
308
|
-
metadata = response.metadata;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const output = await this.endpoint.parseOutput(data);
|
|
312
|
-
|
|
313
|
-
return { output, metadata, responseBuilder };
|
|
314
|
-
},
|
|
315
|
-
// Process declarative audits after handler (inside transaction)
|
|
316
|
-
async (result, auditor) => {
|
|
317
|
-
if (!audits?.length) return;
|
|
318
|
-
|
|
319
|
-
for (const audit of audits) {
|
|
320
|
-
if (audit.when && !audit.when(result.output as any)) {
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
const payload = audit.payload(result.output as any);
|
|
324
|
-
const entityId = audit.entityId?.(result.output as any);
|
|
325
|
-
auditor.audit(audit.type as any, payload as any, {
|
|
326
|
-
table: audit.table,
|
|
327
|
-
entityId,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
// Pass rawDb so storage can reuse existing transactions
|
|
332
|
-
{ db: rawDb },
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
const { output, metadata } = result;
|
|
336
|
-
|
|
337
|
-
ctx.publisher && (await this.serviceDiscovery.register([ctx.publisher]));
|
|
338
|
-
await publishConstructEvents(
|
|
339
|
-
this.endpoint,
|
|
340
|
-
output,
|
|
341
|
-
this.serviceDiscovery,
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
// Convert cookies to Set-Cookie headers
|
|
345
|
-
const headers: Record<string, string | string[]> = {
|
|
346
|
-
...(metadata.headers || {}),
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
if (metadata.cookies && metadata.cookies.size > 0) {
|
|
350
|
-
const setCookieValues: string[] = [];
|
|
351
|
-
for (const [name, cookie] of metadata.cookies.entries()) {
|
|
352
|
-
setCookieValues.push(
|
|
353
|
-
serializeCookie(name, cookie.value, cookie.options),
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
headers['set-cookie'] = setCookieValues;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// Return HTTP response format
|
|
360
|
-
return {
|
|
361
|
-
body: output,
|
|
362
|
-
status: metadata.status || 200,
|
|
363
|
-
headers,
|
|
364
|
-
};
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
async request(
|
|
369
|
-
ctx: TestRequestAdaptor<
|
|
370
|
-
TInput,
|
|
371
|
-
TServices,
|
|
372
|
-
TEventPublisher,
|
|
373
|
-
TEventPublisherServiceName,
|
|
374
|
-
TAuditStorage,
|
|
375
|
-
TAuditStorageServiceName,
|
|
376
|
-
TDatabase,
|
|
377
|
-
TDatabaseServiceName
|
|
378
|
-
>,
|
|
379
|
-
): Promise<InferStandardSchema<TOutSchema>> {
|
|
380
|
-
const response = await this.fullRequest(ctx);
|
|
381
|
-
return response.body;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Conditional audit storage requirement - required when TAuditStorage is configured
|
|
387
|
-
*/
|
|
388
|
-
type AuditStorageRequirement<
|
|
389
|
-
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
390
|
-
> = TAuditStorage extends undefined
|
|
391
|
-
? {}
|
|
392
|
-
: {
|
|
393
|
-
/** Audit storage instance - required when endpoint uses .auditor() */
|
|
394
|
-
auditorStorage: TAuditStorage;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Conditional database requirement - required when TDatabase is configured
|
|
399
|
-
*/
|
|
400
|
-
type DatabaseRequirement<TDatabase = undefined> = TDatabase extends undefined
|
|
401
|
-
? {}
|
|
402
|
-
: {
|
|
403
|
-
/** Database instance - required when endpoint uses .database() */
|
|
404
|
-
database: TDatabase;
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
export type TestRequestAdaptor<
|
|
408
|
-
TInput extends EndpointSchemas = {},
|
|
409
|
-
TServices extends Service[] = [],
|
|
410
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
411
|
-
TEventPublisherServiceName extends string = string,
|
|
412
|
-
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
413
|
-
_TAuditStorageServiceName extends string = string,
|
|
414
|
-
TDatabase = undefined,
|
|
415
|
-
_TDatabaseServiceName extends string = string,
|
|
416
|
-
> = {
|
|
417
|
-
services: ServiceRecord<TServices>;
|
|
418
|
-
headers: Record<string, string>;
|
|
419
|
-
publisher?: Service<TEventPublisherServiceName, TEventPublisher>;
|
|
420
|
-
} & InferComposableStandardSchema<TInput> &
|
|
421
|
-
AuditStorageRequirement<TAuditStorage> &
|
|
422
|
-
DatabaseRequirement<TDatabase>;
|