@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,342 +0,0 @@
|
|
|
1
|
-
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
2
|
-
import { wrapError } from '@geekmidas/errors';
|
|
3
|
-
import type { EventPublisher } from '@geekmidas/events';
|
|
4
|
-
import type { Logger } from '@geekmidas/logger';
|
|
5
|
-
import type { InferStandardSchema } from '@geekmidas/schema';
|
|
6
|
-
import type { Service, ServiceRecord } from '@geekmidas/services';
|
|
7
|
-
import { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';
|
|
8
|
-
import middy, { type MiddlewareObj } from '@middy/core';
|
|
9
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
10
|
-
import type {
|
|
11
|
-
Context,
|
|
12
|
-
Handler,
|
|
13
|
-
SNSEvent,
|
|
14
|
-
SNSEventRecord,
|
|
15
|
-
SQSEvent,
|
|
16
|
-
SQSRecord,
|
|
17
|
-
} from 'aws-lambda';
|
|
18
|
-
import type { Subscriber } from './Subscriber';
|
|
19
|
-
|
|
20
|
-
export type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<
|
|
21
|
-
TEvent,
|
|
22
|
-
TResult
|
|
23
|
-
>;
|
|
24
|
-
|
|
25
|
-
type SubscriberEvent<TServices extends Service[], TLogger extends Logger> = {
|
|
26
|
-
events: any[];
|
|
27
|
-
services: ServiceRecord<TServices>;
|
|
28
|
-
logger: TLogger;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type Middleware<
|
|
32
|
-
TServices extends Service[],
|
|
33
|
-
TLogger extends Logger,
|
|
34
|
-
TOutSchema extends StandardSchemaV1 | undefined,
|
|
35
|
-
> = MiddlewareObj<
|
|
36
|
-
SubscriberEvent<TServices, TLogger>,
|
|
37
|
-
InferStandardSchema<TOutSchema>,
|
|
38
|
-
Error,
|
|
39
|
-
Context
|
|
40
|
-
>;
|
|
41
|
-
|
|
42
|
-
export class AWSLambdaSubscriber<
|
|
43
|
-
TServices extends Service[] = [],
|
|
44
|
-
TLogger extends Logger = Logger,
|
|
45
|
-
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
46
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
47
|
-
TEventPublisherServiceName extends string = string,
|
|
48
|
-
TSubscribedEvents extends any[] = [],
|
|
49
|
-
> {
|
|
50
|
-
private _logger!: TLogger;
|
|
51
|
-
private _services!: ServiceRecord<TServices>;
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
private envParser: EnvironmentParser<{}>,
|
|
55
|
-
readonly subscriber: Subscriber<
|
|
56
|
-
TServices,
|
|
57
|
-
TLogger,
|
|
58
|
-
OutSchema,
|
|
59
|
-
TEventPublisher,
|
|
60
|
-
TEventPublisherServiceName,
|
|
61
|
-
TSubscribedEvents
|
|
62
|
-
>,
|
|
63
|
-
) {
|
|
64
|
-
this._logger = subscriber.logger;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get logger(): TLogger {
|
|
68
|
-
return this._logger;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private async getServices(): Promise<ServiceRecord<TServices>> {
|
|
72
|
-
if (this._services) {
|
|
73
|
-
return this._services;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const serviceDiscovery = ServiceDiscovery.getInstance(this.envParser);
|
|
77
|
-
|
|
78
|
-
if (this.subscriber.services.length > 0) {
|
|
79
|
-
const registered = await serviceDiscovery.register(
|
|
80
|
-
this.subscriber.services,
|
|
81
|
-
);
|
|
82
|
-
this._services = registered as ServiceRecord<TServices>;
|
|
83
|
-
} else {
|
|
84
|
-
this._services = {} as ServiceRecord<TServices>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return this._services;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private error(): Middleware<TServices, TLogger, OutSchema> {
|
|
91
|
-
return {
|
|
92
|
-
onError: (req) => {
|
|
93
|
-
const logger = req.event?.logger || this.subscriber.logger;
|
|
94
|
-
logger.error(req.error || {}, 'Error processing subscriber');
|
|
95
|
-
|
|
96
|
-
// Re-throw the wrapped error to let Lambda handle it
|
|
97
|
-
throw wrapError(req.error);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private loggerMiddleware(): Middleware<TServices, TLogger, OutSchema> {
|
|
103
|
-
return {
|
|
104
|
-
before: (req) => {
|
|
105
|
-
this._logger = this.subscriber.logger.child({
|
|
106
|
-
subscriber: {
|
|
107
|
-
name: req.context.functionName,
|
|
108
|
-
version: req.context.functionVersion,
|
|
109
|
-
memory: req.context.memoryLimitInMB,
|
|
110
|
-
},
|
|
111
|
-
req: {
|
|
112
|
-
id: req.context.awsRequestId,
|
|
113
|
-
},
|
|
114
|
-
}) as TLogger;
|
|
115
|
-
|
|
116
|
-
req.event.logger = this._logger;
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private services(): Middleware<TServices, TLogger, OutSchema> {
|
|
122
|
-
return {
|
|
123
|
-
before: async (req) => {
|
|
124
|
-
req.event.services = await this.getServices();
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private parseEvents(): Middleware<TServices, TLogger, OutSchema> {
|
|
130
|
-
return {
|
|
131
|
-
before: async (req) => {
|
|
132
|
-
const { logger, ...e } = req.event;
|
|
133
|
-
const rawEvent = e as any as SQSEvent | SNSEvent;
|
|
134
|
-
|
|
135
|
-
logger.info({
|
|
136
|
-
rawEvent,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// Parse events based on the event type
|
|
140
|
-
const events: any[] = [];
|
|
141
|
-
|
|
142
|
-
if ('Records' in rawEvent) {
|
|
143
|
-
if (this.isSQSEvent(rawEvent)) {
|
|
144
|
-
// SQS Event
|
|
145
|
-
for (const record of rawEvent.Records) {
|
|
146
|
-
try {
|
|
147
|
-
const event = this.parseSQSRecord(record);
|
|
148
|
-
if (this.shouldIncludeEvent(event)) {
|
|
149
|
-
events.push(event);
|
|
150
|
-
}
|
|
151
|
-
} catch (error) {
|
|
152
|
-
this.logger.error(
|
|
153
|
-
{ error, record },
|
|
154
|
-
'Failed to parse SQS record',
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} else if (this.isSNSEvent(rawEvent)) {
|
|
159
|
-
// SNS Event
|
|
160
|
-
for (const record of rawEvent.Records) {
|
|
161
|
-
try {
|
|
162
|
-
const event = this.parseSNSRecord(record);
|
|
163
|
-
if (this.shouldIncludeEvent(event)) {
|
|
164
|
-
events.push(event);
|
|
165
|
-
}
|
|
166
|
-
} catch (error) {
|
|
167
|
-
this.logger.error(
|
|
168
|
-
{ error, record },
|
|
169
|
-
'Failed to parse SNS record',
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
(req.event as any).events = events;
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private isSQSEvent(event: SQSEvent | SNSEvent): event is SQSEvent {
|
|
182
|
-
const firstRecord = event.Records[0];
|
|
183
|
-
return (
|
|
184
|
-
'Records' in event &&
|
|
185
|
-
event.Records.length > 0 &&
|
|
186
|
-
firstRecord !== undefined &&
|
|
187
|
-
'eventSource' in firstRecord &&
|
|
188
|
-
firstRecord.eventSource === 'aws:sqs'
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private isSNSEvent(event: SQSEvent | SNSEvent): event is SNSEvent {
|
|
193
|
-
const firstRecord = event.Records[0];
|
|
194
|
-
return (
|
|
195
|
-
'Records' in event &&
|
|
196
|
-
event.Records.length > 0 &&
|
|
197
|
-
firstRecord !== undefined &&
|
|
198
|
-
'EventSource' in firstRecord &&
|
|
199
|
-
firstRecord.EventSource === 'aws:sns'
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private parseSNSRecord(record: SNSEventRecord): any {
|
|
204
|
-
const message = this.safeJsonParse(record.Sns.Message);
|
|
205
|
-
const messageType = record.Sns.MessageAttributes?.type?.Value;
|
|
206
|
-
|
|
207
|
-
// Not JSON — wrap raw string with type from MessageAttributes if available
|
|
208
|
-
if (message === null) {
|
|
209
|
-
return messageType
|
|
210
|
-
? { type: messageType, payload: record.Sns.Message }
|
|
211
|
-
: record.Sns.Message;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Resolve type from MessageAttributes (preferred) or message body
|
|
215
|
-
const resolvedType = messageType ?? message.type;
|
|
216
|
-
|
|
217
|
-
if (message.type) {
|
|
218
|
-
return message; // Full event format: { type, payload }
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Payload-only format: type is in MessageAttributes
|
|
222
|
-
return resolvedType ? { type: resolvedType, payload: message } : message;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private parseSQSRecord(record: SQSRecord): any {
|
|
226
|
-
const body = this.safeJsonParse(record.body);
|
|
227
|
-
|
|
228
|
-
// Not JSON — return raw body as-is
|
|
229
|
-
if (body === null) {
|
|
230
|
-
return record.body;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Check if this is an SNS message wrapped in SQS
|
|
234
|
-
if (body.Type === 'Notification' && body.Message) {
|
|
235
|
-
const snsMessage = this.safeJsonParse(body.Message);
|
|
236
|
-
const messageType = body.MessageAttributes?.type?.Value;
|
|
237
|
-
|
|
238
|
-
// SNS Message not JSON — wrap with type from MessageAttributes if available
|
|
239
|
-
if (snsMessage === null) {
|
|
240
|
-
return messageType
|
|
241
|
-
? { type: messageType, payload: body.Message }
|
|
242
|
-
: body.Message;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (snsMessage.type) {
|
|
246
|
-
return snsMessage; // Full event format: { type, payload }
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Payload-only format: type is in MessageAttributes
|
|
250
|
-
const resolvedType = messageType ?? snsMessage.type;
|
|
251
|
-
return resolvedType
|
|
252
|
-
? { type: resolvedType, payload: snsMessage }
|
|
253
|
-
: snsMessage;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Direct SQS message
|
|
257
|
-
return body;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
private safeJsonParse(value: string): any | null {
|
|
261
|
-
try {
|
|
262
|
-
return JSON.parse(value);
|
|
263
|
-
} catch {
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
private shouldIncludeEvent(event: any): boolean {
|
|
269
|
-
// No event type (raw string/non-object) — always include
|
|
270
|
-
if (typeof event !== 'object' || !event?.type) {
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// No filter configured — accept all
|
|
275
|
-
if (!this.subscriber.subscribedEvents) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return this.subscriber.subscribedEvents.includes(event.type as any);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
private async _handler(event: SubscriberEvent<TServices, TLogger>) {
|
|
283
|
-
// If no events after filtering, return early
|
|
284
|
-
if (event.events.length === 0) {
|
|
285
|
-
this.logger.info('No subscribed events to process');
|
|
286
|
-
return {
|
|
287
|
-
batchItemFailures: [],
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Execute the subscriber with the parsed context
|
|
292
|
-
const result = await this.subscriber.handler({
|
|
293
|
-
events: event.events,
|
|
294
|
-
services: event.services,
|
|
295
|
-
logger: event.logger,
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// Parse output if schema is provided
|
|
299
|
-
if (this.subscriber.outputSchema && result) {
|
|
300
|
-
const validationResult =
|
|
301
|
-
await this.subscriber.outputSchema['~standard'].validate(result);
|
|
302
|
-
|
|
303
|
-
if (validationResult.issues) {
|
|
304
|
-
this.logger.error(
|
|
305
|
-
{ issues: validationResult.issues },
|
|
306
|
-
'Subscriber output validation failed',
|
|
307
|
-
);
|
|
308
|
-
throw new Error('Subscriber output validation failed');
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return validationResult.value;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return result;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
get handler(): AWSLambdaHandler {
|
|
318
|
-
const handler = this._handler.bind(this);
|
|
319
|
-
|
|
320
|
-
// Apply middleware in order
|
|
321
|
-
const chain = middy(handler)
|
|
322
|
-
.use(this.loggerMiddleware())
|
|
323
|
-
.use(this.parseEvents())
|
|
324
|
-
.use(this.error())
|
|
325
|
-
.use(this.services());
|
|
326
|
-
|
|
327
|
-
// Wrap entire Middy chain in request context for service access
|
|
328
|
-
const wrappedHandler = async (event: unknown, context: Context) => {
|
|
329
|
-
const startTime = Date.now();
|
|
330
|
-
const requestId = context.awsRequestId;
|
|
331
|
-
const logger = this.subscriber.logger.child({
|
|
332
|
-
requestId,
|
|
333
|
-
}) as TLogger;
|
|
334
|
-
|
|
335
|
-
return runWithRequestContext({ logger, requestId, startTime }, () =>
|
|
336
|
-
chain(event as Parameters<typeof chain>[0], context),
|
|
337
|
-
);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
return wrappedHandler as unknown as AWSLambdaHandler;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EventPublisher,
|
|
3
|
-
ExtractPublisherMessage,
|
|
4
|
-
} from '@geekmidas/events';
|
|
5
|
-
import type { Logger } from '@geekmidas/logger';
|
|
6
|
-
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
7
|
-
import type { InferStandardSchema } from '@geekmidas/schema';
|
|
8
|
-
import type { Service, ServiceRecord } from '@geekmidas/services';
|
|
9
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
10
|
-
import { Construct, ConstructType } from '../Construct';
|
|
11
|
-
|
|
12
|
-
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
13
|
-
|
|
14
|
-
// Helper type to extract payload types for subscribed events
|
|
15
|
-
type ExtractEventPayloads<
|
|
16
|
-
TPublisher extends EventPublisher<any> | undefined,
|
|
17
|
-
TEventTypes extends any[],
|
|
18
|
-
> = TPublisher extends EventPublisher<any>
|
|
19
|
-
? Extract<ExtractPublisherMessage<TPublisher>, { type: TEventTypes[number] }>
|
|
20
|
-
: never;
|
|
21
|
-
|
|
22
|
-
export class Subscriber<
|
|
23
|
-
TServices extends Service[] = [],
|
|
24
|
-
TLogger extends Logger = Logger,
|
|
25
|
-
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
26
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
27
|
-
TEventPublisherServiceName extends string = string,
|
|
28
|
-
TSubscribedEvents extends
|
|
29
|
-
ExtractPublisherMessage<TEventPublisher>['type'][] = ExtractPublisherMessage<TEventPublisher>['type'][],
|
|
30
|
-
> extends Construct<
|
|
31
|
-
TLogger,
|
|
32
|
-
TEventPublisherServiceName,
|
|
33
|
-
TEventPublisher,
|
|
34
|
-
OutSchema,
|
|
35
|
-
TServices
|
|
36
|
-
> {
|
|
37
|
-
__IS_SUBSCRIBER__ = true;
|
|
38
|
-
|
|
39
|
-
static isSubscriber(
|
|
40
|
-
obj: any,
|
|
41
|
-
): obj is Subscriber<any, any, any, any, any, any> {
|
|
42
|
-
return Boolean(
|
|
43
|
-
obj &&
|
|
44
|
-
obj.__IS_SUBSCRIBER__ === true &&
|
|
45
|
-
obj.type === ConstructType.Subscriber,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
public readonly handler: SubscriberHandler<
|
|
51
|
-
TEventPublisher,
|
|
52
|
-
TSubscribedEvents,
|
|
53
|
-
TServices,
|
|
54
|
-
TLogger,
|
|
55
|
-
OutSchema
|
|
56
|
-
>,
|
|
57
|
-
public override readonly timeout: number = 30000,
|
|
58
|
-
protected _subscribedEvents?: TSubscribedEvents,
|
|
59
|
-
public override readonly outputSchema?: OutSchema,
|
|
60
|
-
public override readonly services: TServices = [] as unknown as TServices,
|
|
61
|
-
public override readonly logger: TLogger = DEFAULT_LOGGER as TLogger,
|
|
62
|
-
public override readonly publisherService?: Service<
|
|
63
|
-
TEventPublisherServiceName,
|
|
64
|
-
TEventPublisher
|
|
65
|
-
>,
|
|
66
|
-
/**
|
|
67
|
-
* The name of the {@link Topic} this subscriber binds to (via
|
|
68
|
-
* `s.topic(topic)`), recorded for the manifest so infra wires the SNS
|
|
69
|
-
* subscription. Undefined when the subscriber's events are typed from a
|
|
70
|
-
* (hand-written) publisher instead.
|
|
71
|
-
*/
|
|
72
|
-
public readonly topicName?: string,
|
|
73
|
-
) {
|
|
74
|
-
super(
|
|
75
|
-
ConstructType.Subscriber,
|
|
76
|
-
logger,
|
|
77
|
-
services,
|
|
78
|
-
[],
|
|
79
|
-
publisherService,
|
|
80
|
-
outputSchema,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get subscribedEvents(): TSubscribedEvents | undefined {
|
|
85
|
-
return this._subscribedEvents;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Handler type for subscribers that receives an array of events
|
|
90
|
-
export type SubscriberHandler<
|
|
91
|
-
TEventPublisher extends EventPublisher<any> | undefined,
|
|
92
|
-
TSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][],
|
|
93
|
-
TServices extends Service[] = [],
|
|
94
|
-
TLogger extends Logger = Logger,
|
|
95
|
-
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
96
|
-
> = (
|
|
97
|
-
ctx: SubscriberContext<
|
|
98
|
-
TEventPublisher,
|
|
99
|
-
TSubscribedEvents,
|
|
100
|
-
TServices,
|
|
101
|
-
TLogger
|
|
102
|
-
>,
|
|
103
|
-
) => OutSchema extends StandardSchemaV1
|
|
104
|
-
? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>
|
|
105
|
-
: any | Promise<any>;
|
|
106
|
-
|
|
107
|
-
// Context type for subscriber handlers
|
|
108
|
-
export type SubscriberContext<
|
|
109
|
-
TEventPublisher extends EventPublisher<any> | undefined,
|
|
110
|
-
TSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][],
|
|
111
|
-
TServices extends Service[] = [],
|
|
112
|
-
TLogger extends Logger = Logger,
|
|
113
|
-
> = {
|
|
114
|
-
events: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[];
|
|
115
|
-
services: ServiceRecord<TServices>;
|
|
116
|
-
logger: TLogger;
|
|
117
|
-
};
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EventPublisher,
|
|
3
|
-
ExtractPublisherMessage,
|
|
4
|
-
} from '@geekmidas/events';
|
|
5
|
-
import type { Logger } from '@geekmidas/logger';
|
|
6
|
-
import { DEFAULT_LOGGER } from '@geekmidas/logger/console';
|
|
7
|
-
import type { Service } from '@geekmidas/services';
|
|
8
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
9
|
-
import type { Topic, TopicEvents, TopicMessage } from '../topic/Topic';
|
|
10
|
-
import { Subscriber, type SubscriberHandler } from './Subscriber';
|
|
11
|
-
|
|
12
|
-
export class SubscriberBuilder<
|
|
13
|
-
TServices extends Service[] = [],
|
|
14
|
-
TLogger extends Logger = Logger,
|
|
15
|
-
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
16
|
-
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
17
|
-
TEventPublisherServiceName extends string = string,
|
|
18
|
-
TSubscribedEvents extends any[] = [],
|
|
19
|
-
> {
|
|
20
|
-
private _subscribedEvents: TSubscribedEvents = [] as any;
|
|
21
|
-
private _timeout?: number;
|
|
22
|
-
private outputSchema?: OutSchema;
|
|
23
|
-
private _services: TServices = [] as Service[] as TServices;
|
|
24
|
-
private _logger: TLogger = DEFAULT_LOGGER;
|
|
25
|
-
private _publisher?: Service<TEventPublisherServiceName, TEventPublisher>;
|
|
26
|
-
private _topicName?: string;
|
|
27
|
-
|
|
28
|
-
constructor() {
|
|
29
|
-
this._timeout = 30000; // Default timeout
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Bind this subscriber to a {@link Topic} — the preferred way to type and wire
|
|
34
|
-
* a fan-out consumer. It supplies the subscribable event types (and their
|
|
35
|
-
* payloads) from the topic's contract and records the binding for the manifest,
|
|
36
|
-
* so infra wires the SNS subscription.
|
|
37
|
-
*
|
|
38
|
-
* Prefer this over typing via a hand-written publisher service: a consumer does
|
|
39
|
-
* not publish, so binding a topic does *not* require the topic's publisher
|
|
40
|
-
* connection string (least privilege). Use `.publisher(...)` only when the
|
|
41
|
-
* subscriber actually publishes follow-up events.
|
|
42
|
-
*/
|
|
43
|
-
topic<TName extends string, TEvents extends TopicEvents>(
|
|
44
|
-
topic: Topic<TName, TEvents>,
|
|
45
|
-
): SubscriberBuilder<
|
|
46
|
-
TServices,
|
|
47
|
-
TLogger,
|
|
48
|
-
OutSchema,
|
|
49
|
-
EventPublisher<TopicMessage<TEvents>>,
|
|
50
|
-
TEventPublisherServiceName,
|
|
51
|
-
TSubscribedEvents
|
|
52
|
-
> {
|
|
53
|
-
this._topicName = topic.name;
|
|
54
|
-
return this as unknown as SubscriberBuilder<
|
|
55
|
-
TServices,
|
|
56
|
-
TLogger,
|
|
57
|
-
OutSchema,
|
|
58
|
-
EventPublisher<TopicMessage<TEvents>>,
|
|
59
|
-
TEventPublisherServiceName,
|
|
60
|
-
TSubscribedEvents
|
|
61
|
-
>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
timeout(timeout: number): this {
|
|
65
|
-
this._timeout = timeout;
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
output<T extends StandardSchemaV1>(
|
|
70
|
-
schema: T,
|
|
71
|
-
): SubscriberBuilder<
|
|
72
|
-
TServices,
|
|
73
|
-
TLogger,
|
|
74
|
-
T,
|
|
75
|
-
TEventPublisher,
|
|
76
|
-
TEventPublisherServiceName,
|
|
77
|
-
TSubscribedEvents
|
|
78
|
-
> {
|
|
79
|
-
this.outputSchema = schema as unknown as OutSchema;
|
|
80
|
-
return this as any;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
services<T extends Service[]>(
|
|
84
|
-
services: T,
|
|
85
|
-
): SubscriberBuilder<
|
|
86
|
-
[...TServices, ...T],
|
|
87
|
-
TLogger,
|
|
88
|
-
OutSchema,
|
|
89
|
-
TEventPublisher,
|
|
90
|
-
TEventPublisherServiceName,
|
|
91
|
-
TSubscribedEvents
|
|
92
|
-
> {
|
|
93
|
-
this._services = [...this._services, ...services] as any;
|
|
94
|
-
return this as any;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
logger<T extends Logger>(
|
|
98
|
-
logger: T,
|
|
99
|
-
): SubscriberBuilder<
|
|
100
|
-
TServices,
|
|
101
|
-
T,
|
|
102
|
-
OutSchema,
|
|
103
|
-
TEventPublisher,
|
|
104
|
-
TEventPublisherServiceName,
|
|
105
|
-
TSubscribedEvents
|
|
106
|
-
> {
|
|
107
|
-
this._logger = logger as unknown as TLogger;
|
|
108
|
-
return this as any;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
publisher<T extends EventPublisher<any>, TName extends string>(
|
|
112
|
-
publisher: Service<TName, T>,
|
|
113
|
-
): SubscriberBuilder<
|
|
114
|
-
TServices,
|
|
115
|
-
TLogger,
|
|
116
|
-
OutSchema,
|
|
117
|
-
T,
|
|
118
|
-
TName,
|
|
119
|
-
TSubscribedEvents
|
|
120
|
-
> {
|
|
121
|
-
this._publisher = publisher as any;
|
|
122
|
-
return this as any;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
subscribe<
|
|
126
|
-
TEvent extends TEventPublisher extends EventPublisher<any>
|
|
127
|
-
?
|
|
128
|
-
| ExtractPublisherMessage<TEventPublisher>['type']
|
|
129
|
-
| ExtractPublisherMessage<TEventPublisher>['type'][]
|
|
130
|
-
: never,
|
|
131
|
-
>(
|
|
132
|
-
event: TEvent,
|
|
133
|
-
): SubscriberBuilder<
|
|
134
|
-
TServices,
|
|
135
|
-
TLogger,
|
|
136
|
-
OutSchema,
|
|
137
|
-
TEventPublisher,
|
|
138
|
-
TEventPublisherServiceName,
|
|
139
|
-
TEvent extends any[]
|
|
140
|
-
? [...TSubscribedEvents, ...TEvent]
|
|
141
|
-
: [...TSubscribedEvents, TEvent]
|
|
142
|
-
> {
|
|
143
|
-
const eventsToAdd = Array.isArray(event) ? event : [event];
|
|
144
|
-
this._subscribedEvents = [...this._subscribedEvents, ...eventsToAdd] as any;
|
|
145
|
-
return this as any;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
handle(
|
|
149
|
-
fn: SubscriberHandler<
|
|
150
|
-
TEventPublisher,
|
|
151
|
-
TSubscribedEvents,
|
|
152
|
-
TServices,
|
|
153
|
-
TLogger,
|
|
154
|
-
OutSchema
|
|
155
|
-
>,
|
|
156
|
-
): Subscriber<
|
|
157
|
-
TServices,
|
|
158
|
-
TLogger,
|
|
159
|
-
OutSchema,
|
|
160
|
-
TEventPublisher,
|
|
161
|
-
TEventPublisherServiceName,
|
|
162
|
-
TSubscribedEvents
|
|
163
|
-
> {
|
|
164
|
-
const subscriber = new Subscriber(
|
|
165
|
-
fn,
|
|
166
|
-
this._timeout,
|
|
167
|
-
this._subscribedEvents,
|
|
168
|
-
this.outputSchema,
|
|
169
|
-
this._services,
|
|
170
|
-
this._logger,
|
|
171
|
-
this._publisher,
|
|
172
|
-
this._topicName,
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// Reset builder state after creating the subscriber to prevent pollution
|
|
176
|
-
this._services = [] as Service[] as TServices;
|
|
177
|
-
this._logger = DEFAULT_LOGGER;
|
|
178
|
-
this._publisher = undefined;
|
|
179
|
-
this._topicName = undefined;
|
|
180
|
-
this._subscribedEvents = [] as any;
|
|
181
|
-
this._timeout = 30000; // Reset to default
|
|
182
|
-
this.outputSchema = undefined;
|
|
183
|
-
|
|
184
|
-
return subscriber;
|
|
185
|
-
}
|
|
186
|
-
}
|