@geekmidas/constructs 0.0.1
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 +614 -0
- package/dist/AWSLambdaFunction-CpHFE2m6.d.mts +27 -0
- package/dist/AWSLambdaFunction-CwagvPG3.d.cts +27 -0
- package/dist/AWSLambdaFunction-DWIZYsCy.mjs +79 -0
- package/dist/AWSLambdaFunction-DWIZYsCy.mjs.map +1 -0
- package/dist/AWSLambdaFunction-qA5LqPsv.cjs +85 -0
- package/dist/AWSLambdaFunction-qA5LqPsv.cjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-C1wQuucQ.d.mts +32 -0
- package/dist/AWSLambdaSubscriberAdaptor-CmPZ10JF.cjs +138 -0
- package/dist/AWSLambdaSubscriberAdaptor-CmPZ10JF.cjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-G8y3YkWj.mjs +132 -0
- package/dist/AWSLambdaSubscriberAdaptor-G8y3YkWj.mjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-QKVxR6qh.d.cts +32 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-BoBh7vvD.d.mts +61 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-Cx1oqcqh.mjs +124 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-Cx1oqcqh.mjs.map +1 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-DtzgQ9Vb.d.cts +61 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-i74DEUbc.cjs +130 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-i74DEUbc.cjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-CLmBDYsl.mjs +42 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-CLmBDYsl.mjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-EhMd1YqV.d.mts +21 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-GkMAUPL5.cjs +47 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-GkMAUPL5.cjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-Gw-j61qM.d.cts +21 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-3RqegmJC.mjs +41 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-3RqegmJC.mjs.map +1 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-LUlpwmUW.d.cts +21 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-YlFoFSS9.cjs +46 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-YlFoFSS9.cjs.map +1 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-zfd1gqXA.d.mts +21 -0
- package/dist/BaseFunctionBuilder-5QCHkchp.d.cts +31 -0
- package/dist/BaseFunctionBuilder-BFPVGnKi.d.mts +31 -0
- package/dist/BaseFunctionBuilder-BPE9JBbT.mjs +56 -0
- package/dist/BaseFunctionBuilder-BPE9JBbT.mjs.map +1 -0
- package/dist/BaseFunctionBuilder-DtO4Nwxm.cjs +62 -0
- package/dist/BaseFunctionBuilder-DtO4Nwxm.cjs.map +1 -0
- package/dist/Construct-BSEs6uwW.cjs +75 -0
- package/dist/Construct-BSEs6uwW.cjs.map +1 -0
- package/dist/Construct-BbKCIPQm.mjs +63 -0
- package/dist/Construct-BbKCIPQm.mjs.map +1 -0
- package/dist/Construct-Bm-PSO2V.d.cts +42 -0
- package/dist/Construct-DIguIyw4.d.mts +42 -0
- package/dist/Construct.cjs +4 -0
- package/dist/Construct.d.cts +2 -0
- package/dist/Construct.d.mts +2 -0
- package/dist/Construct.mjs +3 -0
- package/dist/Cron-Bgs6EQOb.mjs +20 -0
- package/dist/Cron-Bgs6EQOb.mjs.map +1 -0
- package/dist/Cron-DQiCj3ef.cjs +25 -0
- package/dist/Cron-DQiCj3ef.cjs.map +1 -0
- package/dist/Cron-FpAw03k6.d.mts +25 -0
- package/dist/Cron-ztnK6zgU.d.cts +25 -0
- package/dist/CronBuilder-B2clNQSP.d.mts +24 -0
- package/dist/CronBuilder-Cje9K8lZ.d.cts +24 -0
- package/dist/CronBuilder-DIBqJkh_.cjs +60 -0
- package/dist/CronBuilder-DIBqJkh_.cjs.map +1 -0
- package/dist/CronBuilder-DecAvvcn.mjs +54 -0
- package/dist/CronBuilder-DecAvvcn.mjs.map +1 -0
- package/dist/Endpoint-BaHC9y4Z.cjs +291 -0
- package/dist/Endpoint-BaHC9y4Z.cjs.map +1 -0
- package/dist/Endpoint-C7z9YJHK.d.cts +405 -0
- package/dist/Endpoint-DCn53Vd8.d.mts +405 -0
- package/dist/Endpoint-ierdM62O.mjs +279 -0
- package/dist/Endpoint-ierdM62O.mjs.map +1 -0
- package/dist/EndpointBuilder-BHFSpbPR.cjs +107 -0
- package/dist/EndpointBuilder-BHFSpbPR.cjs.map +1 -0
- package/dist/EndpointBuilder-BLUsoK3l.mjs +101 -0
- package/dist/EndpointBuilder-BLUsoK3l.mjs.map +1 -0
- package/dist/EndpointBuilder-Bfnb2oJr.d.mts +49 -0
- package/dist/EndpointBuilder-CP9RGwZH.d.cts +49 -0
- package/dist/EndpointFactory-BYdDVCNj.mjs +127 -0
- package/dist/EndpointFactory-BYdDVCNj.mjs.map +1 -0
- package/dist/EndpointFactory-CNtMXgIh.d.mts +52 -0
- package/dist/EndpointFactory-CXX4E6Gx.cjs +139 -0
- package/dist/EndpointFactory-CXX4E6Gx.cjs.map +1 -0
- package/dist/EndpointFactory-D2zgWbXZ.d.cts +52 -0
- package/dist/Function-BP58p9Mp.d.cts +59 -0
- package/dist/Function-BsBxc2wA.d.mts +59 -0
- package/dist/Function-C5mW-38v.mjs +72 -0
- package/dist/Function-C5mW-38v.mjs.map +1 -0
- package/dist/Function-CbO2NZx-.cjs +84 -0
- package/dist/Function-CbO2NZx-.cjs.map +1 -0
- package/dist/FunctionBuilder-BS1KgxA_.d.cts +24 -0
- package/dist/FunctionBuilder-C-PfPN3r.d.mts +24 -0
- package/dist/FunctionBuilder-CosgPmMl.mjs +53 -0
- package/dist/FunctionBuilder-CosgPmMl.mjs.map +1 -0
- package/dist/FunctionBuilder-DuOeWCAl.cjs +59 -0
- package/dist/FunctionBuilder-DuOeWCAl.cjs.map +1 -0
- package/dist/FunctionExecutionWrapper-Bx-Dl-2a.d.cts +24 -0
- package/dist/FunctionExecutionWrapper-CElXEjPe.cjs +42 -0
- package/dist/FunctionExecutionWrapper-CElXEjPe.cjs.map +1 -0
- package/dist/FunctionExecutionWrapper-DvglBBjE.d.mts +24 -0
- package/dist/FunctionExecutionWrapper-XGrSAAPD.mjs +36 -0
- package/dist/FunctionExecutionWrapper-XGrSAAPD.mjs.map +1 -0
- package/dist/HonoEndpointAdaptor-B0IO1zj2.d.mts +41 -0
- package/dist/HonoEndpointAdaptor-B4snrp7v.cjs +154 -0
- package/dist/HonoEndpointAdaptor-B4snrp7v.cjs.map +1 -0
- package/dist/HonoEndpointAdaptor-B6lW9Q1k.d.cts +41 -0
- package/dist/HonoEndpointAdaptor-D-M4-6Tf.mjs +148 -0
- package/dist/HonoEndpointAdaptor-D-M4-6Tf.mjs.map +1 -0
- package/dist/Subscriber-BoFm12i_.d.cts +33 -0
- package/dist/Subscriber-BwuCaC9G.mjs +28 -0
- package/dist/Subscriber-BwuCaC9G.mjs.map +1 -0
- package/dist/Subscriber-THGsj7Iy.d.mts +33 -0
- package/dist/Subscriber-iMRFG7ba.cjs +34 -0
- package/dist/Subscriber-iMRFG7ba.cjs.map +1 -0
- package/dist/SubscriberBuilder-CiPxgnKT.d.mts +26 -0
- package/dist/SubscriberBuilder-Dhz0C_t-.mjs +54 -0
- package/dist/SubscriberBuilder-Dhz0C_t-.mjs.map +1 -0
- package/dist/SubscriberBuilder-DuIgxuzc.d.cts +26 -0
- package/dist/SubscriberBuilder-wthr-FL9.cjs +60 -0
- package/dist/SubscriberBuilder-wthr-FL9.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +19 -0
- package/dist/adaptors/aws.d.cts +15 -0
- package/dist/adaptors/aws.d.mts +15 -0
- package/dist/adaptors/aws.mjs +16 -0
- package/dist/adaptors/hono.cjs +12 -0
- package/dist/adaptors/hono.d.cts +9 -0
- package/dist/adaptors/hono.d.mts +9 -0
- package/dist/adaptors/hono.mjs +12 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/crons/Cron.cjs +8 -0
- package/dist/crons/Cron.d.cts +7 -0
- package/dist/crons/Cron.d.mts +7 -0
- package/dist/crons/Cron.mjs +8 -0
- package/dist/crons/CronBuilder.cjs +9 -0
- package/dist/crons/CronBuilder.d.cts +8 -0
- package/dist/crons/CronBuilder.d.mts +8 -0
- package/dist/crons/CronBuilder.mjs +9 -0
- package/dist/crons/index.cjs +16 -0
- package/dist/crons/index.cjs.map +1 -0
- package/dist/crons/index.d.cts +16 -0
- package/dist/crons/index.d.mts +16 -0
- package/dist/crons/index.mjs +14 -0
- package/dist/crons/index.mjs.map +1 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.cjs +10 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.cts +9 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.mts +9 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.mjs +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.cjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.cts +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.mts +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.mjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.cjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.cts +10 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.mts +10 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.mjs +12 -0
- package/dist/endpoints/Endpoint.cjs +9 -0
- package/dist/endpoints/Endpoint.d.cts +8 -0
- package/dist/endpoints/Endpoint.d.mts +8 -0
- package/dist/endpoints/Endpoint.mjs +8 -0
- package/dist/endpoints/EndpointBuilder.cjs +9 -0
- package/dist/endpoints/EndpointBuilder.d.cts +9 -0
- package/dist/endpoints/EndpointBuilder.d.mts +9 -0
- package/dist/endpoints/EndpointBuilder.mjs +9 -0
- package/dist/endpoints/EndpointFactory.cjs +11 -0
- package/dist/endpoints/EndpointFactory.d.cts +10 -0
- package/dist/endpoints/EndpointFactory.d.mts +10 -0
- package/dist/endpoints/EndpointFactory.mjs +10 -0
- package/dist/endpoints/HonoEndpointAdaptor.cjs +12 -0
- package/dist/endpoints/HonoEndpointAdaptor.d.cts +9 -0
- package/dist/endpoints/HonoEndpointAdaptor.d.mts +9 -0
- package/dist/endpoints/HonoEndpointAdaptor.mjs +12 -0
- package/dist/endpoints/TestEndpointAdaptor.cjs +54 -0
- package/dist/endpoints/TestEndpointAdaptor.cjs.map +1 -0
- package/dist/endpoints/TestEndpointAdaptor.d.cts +29 -0
- package/dist/endpoints/TestEndpointAdaptor.d.mts +29 -0
- package/dist/endpoints/TestEndpointAdaptor.mjs +53 -0
- package/dist/endpoints/TestEndpointAdaptor.mjs.map +1 -0
- package/dist/endpoints/helpers.cjs +10 -0
- package/dist/endpoints/helpers.d.cts +58 -0
- package/dist/endpoints/helpers.d.mts +58 -0
- package/dist/endpoints/helpers.mjs +9 -0
- package/dist/endpoints/index.cjs +16 -0
- package/dist/endpoints/index.cjs.map +1 -0
- package/dist/endpoints/index.d.cts +16 -0
- package/dist/endpoints/index.d.mts +16 -0
- package/dist/endpoints/index.mjs +15 -0
- package/dist/endpoints/index.mjs.map +1 -0
- package/dist/endpoints/parseHonoQuery.cjs +3 -0
- package/dist/endpoints/parseHonoQuery.d.cts +12 -0
- package/dist/endpoints/parseHonoQuery.d.mts +12 -0
- package/dist/endpoints/parseHonoQuery.mjs +3 -0
- package/dist/endpoints/parseQueryParams.cjs +3 -0
- package/dist/endpoints/parseQueryParams.d.cts +13 -0
- package/dist/endpoints/parseQueryParams.d.mts +13 -0
- package/dist/endpoints/parseQueryParams.mjs +3 -0
- package/dist/functions/AWSLambdaFunction.cjs +9 -0
- package/dist/functions/AWSLambdaFunction.d.cts +5 -0
- package/dist/functions/AWSLambdaFunction.d.mts +5 -0
- package/dist/functions/AWSLambdaFunction.mjs +9 -0
- package/dist/functions/BaseFunctionBuilder.cjs +4 -0
- package/dist/functions/BaseFunctionBuilder.d.cts +3 -0
- package/dist/functions/BaseFunctionBuilder.d.mts +3 -0
- package/dist/functions/BaseFunctionBuilder.mjs +4 -0
- package/dist/functions/Function.cjs +5 -0
- package/dist/functions/Function.d.cts +3 -0
- package/dist/functions/Function.d.mts +3 -0
- package/dist/functions/Function.mjs +4 -0
- package/dist/functions/FunctionBuilder.cjs +6 -0
- package/dist/functions/FunctionBuilder.d.cts +5 -0
- package/dist/functions/FunctionBuilder.d.mts +5 -0
- package/dist/functions/FunctionBuilder.mjs +6 -0
- package/dist/functions/FunctionExecutionWrapper.cjs +8 -0
- package/dist/functions/FunctionExecutionWrapper.d.cts +4 -0
- package/dist/functions/FunctionExecutionWrapper.d.mts +4 -0
- package/dist/functions/FunctionExecutionWrapper.mjs +8 -0
- package/dist/functions/TestFunctionAdaptor.cjs +38 -0
- package/dist/functions/TestFunctionAdaptor.cjs.map +1 -0
- package/dist/functions/TestFunctionAdaptor.d.cts +26 -0
- package/dist/functions/TestFunctionAdaptor.d.mts +26 -0
- package/dist/functions/TestFunctionAdaptor.mjs +37 -0
- package/dist/functions/TestFunctionAdaptor.mjs.map +1 -0
- package/dist/functions/index.cjs +10 -0
- package/dist/functions/index.d.cts +6 -0
- package/dist/functions/index.d.mts +6 -0
- package/dist/functions/index.mjs +7 -0
- package/dist/functions-DVDb5wEA.cjs +13 -0
- package/dist/functions-DVDb5wEA.cjs.map +1 -0
- package/dist/functions-mM-jcphA.mjs +8 -0
- package/dist/functions-mM-jcphA.mjs.map +1 -0
- package/dist/helpers-BeGM4pP_.cjs +95 -0
- package/dist/helpers-BeGM4pP_.cjs.map +1 -0
- package/dist/helpers-DbpO95aE.mjs +83 -0
- package/dist/helpers-DbpO95aE.mjs.map +1 -0
- package/dist/index-CuGR4L7O.d.mts +9 -0
- package/dist/index-Fg3N3EKD.d.cts +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +3 -0
- package/dist/parseHonoQuery-DopC24vB.cjs +37 -0
- package/dist/parseHonoQuery-DopC24vB.cjs.map +1 -0
- package/dist/parseHonoQuery-znDKBhdE.mjs +31 -0
- package/dist/parseHonoQuery-znDKBhdE.mjs.map +1 -0
- package/dist/parseQueryParams-BJaRh3OB.mjs +32 -0
- package/dist/parseQueryParams-BJaRh3OB.mjs.map +1 -0
- package/dist/parseQueryParams-BzPop4I1.cjs +38 -0
- package/dist/parseQueryParams-BzPop4I1.cjs.map +1 -0
- package/dist/publisher-Bw4770Hi.mjs +41 -0
- package/dist/publisher-Bw4770Hi.mjs.map +1 -0
- package/dist/publisher-lFQleddL.cjs +53 -0
- package/dist/publisher-lFQleddL.cjs.map +1 -0
- package/dist/publisher.cjs +4 -0
- package/dist/publisher.d.cts +13 -0
- package/dist/publisher.d.mts +13 -0
- package/dist/publisher.mjs +3 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.cjs +3 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.d.cts +4 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.d.mts +4 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.mjs +3 -0
- package/dist/subscribers/Subscriber.cjs +4 -0
- package/dist/subscribers/Subscriber.d.cts +3 -0
- package/dist/subscribers/Subscriber.d.mts +3 -0
- package/dist/subscribers/Subscriber.mjs +4 -0
- package/dist/subscribers/SubscriberBuilder.cjs +5 -0
- package/dist/subscribers/SubscriberBuilder.d.cts +4 -0
- package/dist/subscribers/SubscriberBuilder.d.mts +4 -0
- package/dist/subscribers/SubscriberBuilder.mjs +5 -0
- package/dist/subscribers/index.cjs +12 -0
- package/dist/subscribers/index.cjs.map +1 -0
- package/dist/subscribers/index.d.cts +10 -0
- package/dist/subscribers/index.d.mts +10 -0
- package/dist/subscribers/index.mjs +10 -0
- package/dist/subscribers/index.mjs.map +1 -0
- package/dist/types-Bp9ysFXd.d.cts +7 -0
- package/dist/types-DBKNYvsW.d.mts +7 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +0 -0
- package/package.json +91 -0
- package/src/Construct.ts +98 -0
- package/src/__tests__/Construct.environment.spec.ts +360 -0
- package/src/__tests__/publisher.setting.spec.ts +511 -0
- package/src/__tests__/publisher.spec.ts +454 -0
- package/src/adaptors/aws.ts +4 -0
- package/src/adaptors/hono.ts +1 -0
- package/src/crons/Cron.ts +137 -0
- package/src/crons/CronBuilder.ts +192 -0
- package/src/crons/__tests__/Cron.spec.ts +464 -0
- package/src/crons/index.ts +11 -0
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +315 -0
- package/src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts +101 -0
- package/src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts +95 -0
- package/src/endpoints/Endpoint.ts +771 -0
- package/src/endpoints/EndpointBuilder.ts +308 -0
- package/src/endpoints/EndpointFactory.ts +329 -0
- package/src/endpoints/HonoEndpointAdaptor.ts +365 -0
- package/src/endpoints/TestEndpointAdaptor.ts +130 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.events.spec.ts +553 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.spec.ts +927 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.events.spec.ts +721 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.factory-publisher.spec.ts +296 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.spec.ts +441 -0
- package/src/endpoints/__tests__/Endpoint.spec.ts +800 -0
- package/src/endpoints/__tests__/EndpointBuilder.spec.ts +488 -0
- package/src/endpoints/__tests__/EndpointFactory.spec.ts +479 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.events.spec.ts +569 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.openapi.spec.ts +313 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.spec.ts +1078 -0
- package/src/endpoints/__tests__/TestEndpointAdaptor.spec.ts +236 -0
- package/src/endpoints/__tests__/__snapshots__/HonoEndpointAdaptor.spec.ts.snap +54 -0
- package/src/endpoints/__tests__/endpoint-types.test.ts +88 -0
- package/src/endpoints/helpers.ts +99 -0
- package/src/endpoints/index.ts +5 -0
- package/src/endpoints/parseHonoQuery.ts +51 -0
- package/src/endpoints/parseQueryParams.ts +51 -0
- package/src/functions/AWSLambdaFunction.ts +222 -0
- package/src/functions/BaseFunctionBuilder.ts +110 -0
- package/src/functions/Function.ts +160 -0
- package/src/functions/FunctionBuilder.ts +182 -0
- package/src/functions/FunctionExecutionWrapper.ts +86 -0
- package/src/functions/TestFunctionAdaptor.ts +125 -0
- package/src/functions/__tests__/AWSLambdaFunctionAdaptor.spec.ts +376 -0
- package/src/functions/__tests__/Function.spec.ts +402 -0
- package/src/functions/__tests__/TestFunctionAdaptor.spec.ts +398 -0
- package/src/functions/index.ts +10 -0
- package/src/index.ts +14 -0
- package/src/publisher.ts +83 -0
- package/src/subscribers/AWSLambdaSubscriberAdaptor.ts +269 -0
- package/src/subscribers/Subscriber.ts +112 -0
- package/src/subscribers/SubscriberBuilder.ts +150 -0
- package/src/subscribers/__tests__/AWSLambdaSubscriberAdaptor.spec.ts +623 -0
- package/src/subscribers/__tests__/Subscriber.spec.ts +432 -0
- package/src/subscribers/index.ts +5 -0
- package/src/types.ts +13 -0
- package/tsdown.config.ts +3 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
2
|
+
import middy, { type MiddlewareObj } from '@middy/core';
|
|
3
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
+
import type { Context, Handler } from 'aws-lambda';
|
|
5
|
+
import type { Function, FunctionHandler } from './Function';
|
|
6
|
+
import { FunctionBuilder } from './FunctionBuilder';
|
|
7
|
+
|
|
8
|
+
import { wrapError } from '@geekmidas/errors';
|
|
9
|
+
import type { EventPublisher } from '@geekmidas/events';
|
|
10
|
+
import type { Logger } from '@geekmidas/logger';
|
|
11
|
+
import type {
|
|
12
|
+
ComposableStandardSchema,
|
|
13
|
+
InferComposableStandardSchema,
|
|
14
|
+
InferStandardSchema,
|
|
15
|
+
} from '@geekmidas/schema';
|
|
16
|
+
import type { Service, ServiceRecord } from '@geekmidas/services';
|
|
17
|
+
import { FunctionExecutionWrapper } from './FunctionExecutionWrapper';
|
|
18
|
+
|
|
19
|
+
export type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<
|
|
20
|
+
TEvent,
|
|
21
|
+
TResult
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
type FunctionEvent<
|
|
25
|
+
TEvent,
|
|
26
|
+
TInput extends ComposableStandardSchema | undefined,
|
|
27
|
+
TServices extends Service[],
|
|
28
|
+
TLogger extends Logger,
|
|
29
|
+
> = TEvent & {
|
|
30
|
+
parsedInput: InferComposableStandardSchema<TInput>;
|
|
31
|
+
services: ServiceRecord<TServices>;
|
|
32
|
+
logger: TLogger;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Middleware<
|
|
36
|
+
TEvent,
|
|
37
|
+
TInput extends ComposableStandardSchema | undefined,
|
|
38
|
+
TServices extends Service[],
|
|
39
|
+
TLogger extends Logger,
|
|
40
|
+
TOutSchema extends StandardSchemaV1 | undefined,
|
|
41
|
+
> = MiddlewareObj<
|
|
42
|
+
FunctionEvent<TEvent, TInput, TServices, TLogger>,
|
|
43
|
+
InferComposableStandardSchema<TOutSchema>,
|
|
44
|
+
Error,
|
|
45
|
+
Context
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
export class AWSLambdaFunction<
|
|
49
|
+
TInput extends ComposableStandardSchema | undefined = undefined,
|
|
50
|
+
TOutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
51
|
+
TServices extends Service[] = [],
|
|
52
|
+
TLogger extends Logger = Logger,
|
|
53
|
+
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
54
|
+
TEventPublisherServiceName extends string = string,
|
|
55
|
+
> extends FunctionExecutionWrapper<
|
|
56
|
+
TInput,
|
|
57
|
+
TOutSchema,
|
|
58
|
+
TServices,
|
|
59
|
+
TLogger,
|
|
60
|
+
TEventPublisher,
|
|
61
|
+
TEventPublisherServiceName
|
|
62
|
+
> {
|
|
63
|
+
constructor(
|
|
64
|
+
envParser: EnvironmentParser<{}>,
|
|
65
|
+
readonly fn: Function<
|
|
66
|
+
TInput,
|
|
67
|
+
TServices,
|
|
68
|
+
TLogger,
|
|
69
|
+
TOutSchema,
|
|
70
|
+
FunctionHandler<TInput, TServices, TLogger, TOutSchema>,
|
|
71
|
+
TEventPublisher,
|
|
72
|
+
TEventPublisherServiceName
|
|
73
|
+
>,
|
|
74
|
+
) {
|
|
75
|
+
super(envParser, fn);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private error<TEvent>(): Middleware<
|
|
79
|
+
TEvent,
|
|
80
|
+
TInput,
|
|
81
|
+
TServices,
|
|
82
|
+
TLogger,
|
|
83
|
+
TOutSchema
|
|
84
|
+
> {
|
|
85
|
+
return {
|
|
86
|
+
onError: (req) => {
|
|
87
|
+
const logger = req.event?.logger || this.fn.logger;
|
|
88
|
+
logger.error(req.error || {}, 'Error processing function');
|
|
89
|
+
|
|
90
|
+
// Re-throw the wrapped error to let Lambda handle it
|
|
91
|
+
throw wrapError(req.error);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private baseInput<TEvent>(): Middleware<
|
|
97
|
+
TEvent,
|
|
98
|
+
TInput,
|
|
99
|
+
TServices,
|
|
100
|
+
TLogger,
|
|
101
|
+
TOutSchema
|
|
102
|
+
> {
|
|
103
|
+
return {
|
|
104
|
+
before: (req) => {},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private input<
|
|
109
|
+
TEvent extends { input: InferComposableStandardSchema<TInput> },
|
|
110
|
+
>(): Middleware<TEvent, TInput, TServices, TLogger, TOutSchema> {
|
|
111
|
+
return {
|
|
112
|
+
before: async (req) => {
|
|
113
|
+
try {
|
|
114
|
+
// Parse input if schema is provided
|
|
115
|
+
if (this.fn.input) {
|
|
116
|
+
const parsedInput =
|
|
117
|
+
await FunctionBuilder.parseComposableStandardSchema(
|
|
118
|
+
req.event,
|
|
119
|
+
this.fn.input,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
req.event.parsedInput =
|
|
123
|
+
parsedInput as InferComposableStandardSchema<TInput>;
|
|
124
|
+
} else {
|
|
125
|
+
// If no schema, pass the event as-is
|
|
126
|
+
req.event.parsedInput = req.event as any;
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
this.logger.error(
|
|
130
|
+
{ error, event: req.event },
|
|
131
|
+
'Failed to parse input',
|
|
132
|
+
);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private loggerMiddleware<TEvent>(): Middleware<
|
|
140
|
+
TEvent,
|
|
141
|
+
TInput,
|
|
142
|
+
TServices,
|
|
143
|
+
TLogger,
|
|
144
|
+
TOutSchema
|
|
145
|
+
> {
|
|
146
|
+
return {
|
|
147
|
+
before: (req) => {
|
|
148
|
+
this._logger = this.fn.logger.child({
|
|
149
|
+
fn: {
|
|
150
|
+
name: req.context.functionName,
|
|
151
|
+
version: req.context.functionVersion,
|
|
152
|
+
memory: req.context.memoryLimitInMB,
|
|
153
|
+
},
|
|
154
|
+
req: {
|
|
155
|
+
id: req.context.awsRequestId,
|
|
156
|
+
},
|
|
157
|
+
}) as TLogger;
|
|
158
|
+
|
|
159
|
+
req.event.logger = this._logger;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private services<TEvent>(): Middleware<
|
|
165
|
+
TEvent,
|
|
166
|
+
TInput,
|
|
167
|
+
TServices,
|
|
168
|
+
TLogger,
|
|
169
|
+
TOutSchema
|
|
170
|
+
> {
|
|
171
|
+
return {
|
|
172
|
+
before: async (req) => {
|
|
173
|
+
req.event.services = await this.getServices();
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private events<TEvent>(): Middleware<
|
|
179
|
+
TEvent,
|
|
180
|
+
TInput,
|
|
181
|
+
TServices,
|
|
182
|
+
TLogger,
|
|
183
|
+
TOutSchema
|
|
184
|
+
> {
|
|
185
|
+
return {
|
|
186
|
+
after: async (req) => {
|
|
187
|
+
const response = (req.response ||
|
|
188
|
+
undefined) as InferStandardSchema<TOutSchema>;
|
|
189
|
+
await this.publishEvents(response);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async _handler<TEvent>(
|
|
195
|
+
event: FunctionEvent<TEvent, TInput, TServices, TLogger>,
|
|
196
|
+
) {
|
|
197
|
+
// Execute the function with the parsed context
|
|
198
|
+
const result = await this.fn['fn']({
|
|
199
|
+
input: event.parsedInput,
|
|
200
|
+
services: event.services,
|
|
201
|
+
logger: event.logger,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Parse output if schema is provided
|
|
205
|
+
const output = await this.fn.parseOutput(result);
|
|
206
|
+
|
|
207
|
+
return output;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get handler(): AWSLambdaHandler {
|
|
211
|
+
const handler = this._handler.bind(this);
|
|
212
|
+
|
|
213
|
+
// Apply middleware in order
|
|
214
|
+
return middy(handler)
|
|
215
|
+
.use(this.loggerMiddleware())
|
|
216
|
+
.use(this.baseInput())
|
|
217
|
+
.use(this.error())
|
|
218
|
+
.use(this.services())
|
|
219
|
+
.use(this.input())
|
|
220
|
+
.use(this.events()) as unknown as AWSLambdaHandler;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Logger } from '@geekmidas/logger';
|
|
2
|
+
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
3
|
+
import type { Service } from '@geekmidas/services';
|
|
4
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
|
+
import get from 'lodash.get';
|
|
6
|
+
import { ConstructType } from '../Construct';
|
|
7
|
+
|
|
8
|
+
import type { EventPublisher, MappedEvent } from '@geekmidas/events';
|
|
9
|
+
import type {
|
|
10
|
+
ComposableStandardSchema,
|
|
11
|
+
InferComposableStandardSchema,
|
|
12
|
+
} from '@geekmidas/schema';
|
|
13
|
+
|
|
14
|
+
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
15
|
+
|
|
16
|
+
export abstract class BaseFunctionBuilder<
|
|
17
|
+
TInput extends ComposableStandardSchema,
|
|
18
|
+
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
19
|
+
TServices extends Service[] = [],
|
|
20
|
+
TLogger extends Logger = Logger,
|
|
21
|
+
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
22
|
+
TEventPublisherServiceName extends string = string,
|
|
23
|
+
> {
|
|
24
|
+
protected inputSchema?: TInput;
|
|
25
|
+
protected outputSchema?: OutSchema;
|
|
26
|
+
protected _timeout?: number;
|
|
27
|
+
|
|
28
|
+
public _services: TServices = [] as Service[] as TServices;
|
|
29
|
+
public _logger: TLogger = DEFAULT_LOGGER;
|
|
30
|
+
|
|
31
|
+
protected _events: MappedEvent<TEventPublisher, OutSchema>[] = [];
|
|
32
|
+
protected _publisher?: Service<TEventPublisherServiceName, TEventPublisher>;
|
|
33
|
+
|
|
34
|
+
static isStandardSchemaV1(s: unknown): s is StandardSchemaV1 {
|
|
35
|
+
const schema = (s as StandardSchemaV1)['~standard'];
|
|
36
|
+
|
|
37
|
+
return schema && typeof schema.validate === 'function';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static async parseComposableStandardSchema<
|
|
41
|
+
T extends ComposableStandardSchema | undefined,
|
|
42
|
+
>(data: unknown, schema: T): Promise<InferComposableStandardSchema<T>> {
|
|
43
|
+
if (BaseFunctionBuilder.isStandardSchemaV1(schema)) {
|
|
44
|
+
const validated = await schema['~standard'].validate(data);
|
|
45
|
+
|
|
46
|
+
if (validated.issues) {
|
|
47
|
+
throw validated.issues;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return validated.value as InferComposableStandardSchema<T>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const result: any = {};
|
|
54
|
+
for (const key in schema) {
|
|
55
|
+
const item = schema[key];
|
|
56
|
+
if (BaseFunctionBuilder.isStandardSchemaV1(item)) {
|
|
57
|
+
const value = get(data, key);
|
|
58
|
+
const validated = await item['~standard'].validate(value);
|
|
59
|
+
|
|
60
|
+
if (validated.issues) {
|
|
61
|
+
throw validated.issues;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
result[key] = validated.value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result as InferComposableStandardSchema<T>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
constructor(public type = ConstructType.Function) {}
|
|
72
|
+
|
|
73
|
+
abstract services<T extends Service[]>(services: T): any;
|
|
74
|
+
|
|
75
|
+
abstract logger<T extends Logger>(logger: T): any;
|
|
76
|
+
|
|
77
|
+
timeout(timeout: number): this {
|
|
78
|
+
this._timeout = timeout;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
abstract output<T extends StandardSchemaV1>(schema: T): any;
|
|
83
|
+
|
|
84
|
+
abstract input<T extends ComposableStandardSchema>(schema: T): any;
|
|
85
|
+
|
|
86
|
+
event<TEvent extends MappedEvent<TEventPublisher, OutSchema>>(
|
|
87
|
+
event: TEvent,
|
|
88
|
+
): this {
|
|
89
|
+
this._events.push(event);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
publisher<T extends EventPublisher<any>, TName extends string>(
|
|
94
|
+
publisher: Service<TName, T>,
|
|
95
|
+
): BaseFunctionBuilder<TInput, OutSchema, TServices, TLogger, T, TName> {
|
|
96
|
+
this._publisher = publisher as unknown as Service<
|
|
97
|
+
TEventPublisherServiceName,
|
|
98
|
+
TEventPublisher
|
|
99
|
+
>;
|
|
100
|
+
|
|
101
|
+
return this as unknown as BaseFunctionBuilder<
|
|
102
|
+
TInput,
|
|
103
|
+
OutSchema,
|
|
104
|
+
TServices,
|
|
105
|
+
TLogger,
|
|
106
|
+
T,
|
|
107
|
+
TName
|
|
108
|
+
>;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import uniqBy from 'lodash.uniqby';
|
|
3
|
+
|
|
4
|
+
import type { Service, ServiceRecord } from '@geekmidas/services';
|
|
5
|
+
import { Construct, ConstructType } from '../Construct';
|
|
6
|
+
|
|
7
|
+
import type { EventPublisher, MappedEvent } from '@geekmidas/events';
|
|
8
|
+
import type { Logger } from '@geekmidas/logger';
|
|
9
|
+
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
10
|
+
import type {
|
|
11
|
+
ComposableStandardSchema,
|
|
12
|
+
InferComposableStandardSchema,
|
|
13
|
+
InferStandardSchema,
|
|
14
|
+
} from '@geekmidas/schema';
|
|
15
|
+
|
|
16
|
+
import { UnprocessableEntityError } from '@geekmidas/errors';
|
|
17
|
+
import { parseSchema } from '@geekmidas/schema/parser';
|
|
18
|
+
|
|
19
|
+
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
20
|
+
|
|
21
|
+
export class FunctionFactory<
|
|
22
|
+
TServices extends Service[] = [],
|
|
23
|
+
TLogger extends Logger = Logger,
|
|
24
|
+
> {
|
|
25
|
+
private defaultServices: TServices;
|
|
26
|
+
constructor(
|
|
27
|
+
defaultServices: TServices,
|
|
28
|
+
private defaultLogger: TLogger = DEFAULT_LOGGER,
|
|
29
|
+
) {
|
|
30
|
+
// Initialize default services
|
|
31
|
+
this.defaultServices = uniqBy(
|
|
32
|
+
defaultServices,
|
|
33
|
+
(s) => s.serviceName,
|
|
34
|
+
) as TServices;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Create a new factory with services
|
|
38
|
+
services<S extends Service[]>(
|
|
39
|
+
services: S,
|
|
40
|
+
): FunctionFactory<[...S, ...TServices], TLogger> {
|
|
41
|
+
return new FunctionFactory<[...S, ...TServices], TLogger>(
|
|
42
|
+
[...services, ...this.defaultServices],
|
|
43
|
+
this.defaultLogger,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
logger<L extends Logger>(logger: L): FunctionFactory<TServices, L> {
|
|
48
|
+
return new FunctionFactory<TServices, L>(this.defaultServices, logger);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class Function<
|
|
53
|
+
TInput extends ComposableStandardSchema | undefined = undefined,
|
|
54
|
+
TServices extends Service[] = [],
|
|
55
|
+
TLogger extends Logger = Logger,
|
|
56
|
+
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
57
|
+
Fn extends FunctionHandler<
|
|
58
|
+
TInput,
|
|
59
|
+
TServices,
|
|
60
|
+
TLogger,
|
|
61
|
+
OutSchema
|
|
62
|
+
> = FunctionHandler<TInput, TServices, TLogger, OutSchema>,
|
|
63
|
+
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
64
|
+
TEventPublisherServiceName extends string = string,
|
|
65
|
+
> extends Construct<
|
|
66
|
+
TLogger,
|
|
67
|
+
TEventPublisherServiceName,
|
|
68
|
+
TEventPublisher,
|
|
69
|
+
OutSchema,
|
|
70
|
+
TServices
|
|
71
|
+
> {
|
|
72
|
+
__IS_FUNCTION__ = true;
|
|
73
|
+
|
|
74
|
+
static isFunction(obj: any): obj is Function<any, any, any, any, any> {
|
|
75
|
+
return Boolean(
|
|
76
|
+
obj &&
|
|
77
|
+
obj.__IS_FUNCTION__ === true &&
|
|
78
|
+
obj.type === ConstructType.Function,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Validates data against a StandardSchema.
|
|
84
|
+
*
|
|
85
|
+
* @param schema - The StandardSchema to validate against
|
|
86
|
+
* @param data - The data to validate
|
|
87
|
+
* @returns Validation result with value or issues
|
|
88
|
+
*/
|
|
89
|
+
static validate<T extends StandardSchemaV1>(schema: T, data: unknown) {
|
|
90
|
+
return schema['~standard'].validate(data);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parses and validates data against a schema, throwing an error if validation fails.
|
|
95
|
+
*
|
|
96
|
+
* @param schema - The StandardSchema to validate against
|
|
97
|
+
* @param data - The data to parse and validate
|
|
98
|
+
* @returns The validated data with proper typing
|
|
99
|
+
* @throws {UnprocessableEntityError} When validation fails
|
|
100
|
+
*/
|
|
101
|
+
static async parseSchema<T extends StandardSchemaV1>(
|
|
102
|
+
schema: T,
|
|
103
|
+
data: unknown,
|
|
104
|
+
): Promise<InferStandardSchema<T>> {
|
|
105
|
+
try {
|
|
106
|
+
return await parseSchema(schema, data);
|
|
107
|
+
} catch (issues) {
|
|
108
|
+
throw new UnprocessableEntityError('Validation failed', issues);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Parses and validates the endpoint output against the output schema.
|
|
114
|
+
*
|
|
115
|
+
* @param output - The raw output data to validate
|
|
116
|
+
* @returns The validated output data
|
|
117
|
+
* @throws {UnprocessableEntityError} When output validation fails
|
|
118
|
+
*/
|
|
119
|
+
async parseOutput(output: unknown): Promise<InferStandardSchema<OutSchema>> {
|
|
120
|
+
return Function.parseSchema(
|
|
121
|
+
this.outputSchema as StandardSchemaV1,
|
|
122
|
+
output,
|
|
123
|
+
) as Promise<InferStandardSchema<OutSchema>>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
constructor(
|
|
127
|
+
protected readonly fn: Fn,
|
|
128
|
+
readonly timeout = 30000, // Default timeout of 30 seconds
|
|
129
|
+
type: ConstructType = ConstructType.Function,
|
|
130
|
+
public input?: TInput,
|
|
131
|
+
outputSchema?: OutSchema,
|
|
132
|
+
services: TServices = [] as unknown as TServices,
|
|
133
|
+
logger: TLogger = DEFAULT_LOGGER,
|
|
134
|
+
publisherService?: Service<TEventPublisherServiceName, TEventPublisher>,
|
|
135
|
+
events: MappedEvent<TEventPublisher, OutSchema>[] = [],
|
|
136
|
+
) {
|
|
137
|
+
super(type, logger, services, events, publisherService, outputSchema);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type FunctionHandler<
|
|
142
|
+
TInput extends ComposableStandardSchema | undefined = undefined,
|
|
143
|
+
TServices extends Service[] = [],
|
|
144
|
+
TLogger extends Logger = Logger,
|
|
145
|
+
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
146
|
+
> = (
|
|
147
|
+
ctx: FunctionContext<TInput, TServices, TLogger>,
|
|
148
|
+
) => OutSchema extends StandardSchemaV1
|
|
149
|
+
? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>
|
|
150
|
+
: any | Promise<any>;
|
|
151
|
+
|
|
152
|
+
export type FunctionContext<
|
|
153
|
+
Input extends ComposableStandardSchema | undefined = undefined,
|
|
154
|
+
TServices extends Service[] = [],
|
|
155
|
+
TLogger extends Logger = Logger,
|
|
156
|
+
> = {
|
|
157
|
+
services: ServiceRecord<TServices>;
|
|
158
|
+
logger: TLogger;
|
|
159
|
+
input: InferComposableStandardSchema<Input>;
|
|
160
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Logger } from '@geekmidas/logger';
|
|
2
|
+
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
3
|
+
import type { Service } from '@geekmidas/services';
|
|
4
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
|
+
import uniqBy from 'lodash.uniqby';
|
|
6
|
+
import { ConstructType } from '../Construct';
|
|
7
|
+
import { BaseFunctionBuilder } from './BaseFunctionBuilder';
|
|
8
|
+
import { Function, type FunctionHandler } from './Function';
|
|
9
|
+
|
|
10
|
+
import type { EventPublisher } from '@geekmidas/events';
|
|
11
|
+
import type { ComposableStandardSchema } from '@geekmidas/schema';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
14
|
+
|
|
15
|
+
export class FunctionBuilder<
|
|
16
|
+
TInput extends ComposableStandardSchema,
|
|
17
|
+
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
18
|
+
TServices extends Service[] = [],
|
|
19
|
+
TLogger extends Logger = Logger,
|
|
20
|
+
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
21
|
+
TEventPublisherServiceName extends string = string,
|
|
22
|
+
> extends BaseFunctionBuilder<
|
|
23
|
+
TInput,
|
|
24
|
+
OutSchema,
|
|
25
|
+
TServices,
|
|
26
|
+
TLogger,
|
|
27
|
+
TEventPublisher,
|
|
28
|
+
TEventPublisherServiceName
|
|
29
|
+
> {
|
|
30
|
+
constructor(public type = ConstructType.Function) {
|
|
31
|
+
super(type);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
timeout(timeout: number): this {
|
|
35
|
+
this._timeout = timeout;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
output<T extends StandardSchemaV1>(
|
|
40
|
+
schema: T,
|
|
41
|
+
): FunctionBuilder<
|
|
42
|
+
TInput,
|
|
43
|
+
T,
|
|
44
|
+
TServices,
|
|
45
|
+
TLogger,
|
|
46
|
+
TEventPublisher,
|
|
47
|
+
TEventPublisherServiceName
|
|
48
|
+
> {
|
|
49
|
+
this.outputSchema = schema as unknown as OutSchema;
|
|
50
|
+
|
|
51
|
+
return this as unknown as FunctionBuilder<
|
|
52
|
+
TInput,
|
|
53
|
+
T,
|
|
54
|
+
TServices,
|
|
55
|
+
TLogger,
|
|
56
|
+
TEventPublisher,
|
|
57
|
+
TEventPublisherServiceName
|
|
58
|
+
>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
input<T extends ComposableStandardSchema>(
|
|
62
|
+
schema: T,
|
|
63
|
+
): FunctionBuilder<
|
|
64
|
+
T,
|
|
65
|
+
OutSchema,
|
|
66
|
+
TServices,
|
|
67
|
+
TLogger,
|
|
68
|
+
TEventPublisher,
|
|
69
|
+
TEventPublisherServiceName
|
|
70
|
+
> {
|
|
71
|
+
this.inputSchema = schema as unknown as TInput;
|
|
72
|
+
|
|
73
|
+
return this as unknown as FunctionBuilder<
|
|
74
|
+
T,
|
|
75
|
+
OutSchema,
|
|
76
|
+
TServices,
|
|
77
|
+
TLogger,
|
|
78
|
+
TEventPublisher,
|
|
79
|
+
TEventPublisherServiceName
|
|
80
|
+
>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
services<T extends Service[]>(
|
|
84
|
+
services: T,
|
|
85
|
+
): FunctionBuilder<
|
|
86
|
+
TInput,
|
|
87
|
+
OutSchema,
|
|
88
|
+
[...TServices, ...T],
|
|
89
|
+
TLogger,
|
|
90
|
+
TEventPublisher,
|
|
91
|
+
TEventPublisherServiceName
|
|
92
|
+
> {
|
|
93
|
+
this._services = uniqBy(
|
|
94
|
+
[...this._services, ...services],
|
|
95
|
+
(s) => s.serviceName,
|
|
96
|
+
) as TServices;
|
|
97
|
+
|
|
98
|
+
return this as unknown as FunctionBuilder<
|
|
99
|
+
TInput,
|
|
100
|
+
OutSchema,
|
|
101
|
+
[...TServices, ...T],
|
|
102
|
+
TLogger,
|
|
103
|
+
TEventPublisher,
|
|
104
|
+
TEventPublisherServiceName
|
|
105
|
+
>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
logger<T extends Logger>(
|
|
109
|
+
logger: T,
|
|
110
|
+
): FunctionBuilder<
|
|
111
|
+
TInput,
|
|
112
|
+
OutSchema,
|
|
113
|
+
TServices,
|
|
114
|
+
T,
|
|
115
|
+
TEventPublisher,
|
|
116
|
+
TEventPublisherServiceName
|
|
117
|
+
> {
|
|
118
|
+
this._logger = logger as unknown as TLogger;
|
|
119
|
+
|
|
120
|
+
return this as unknown as FunctionBuilder<
|
|
121
|
+
TInput,
|
|
122
|
+
OutSchema,
|
|
123
|
+
TServices,
|
|
124
|
+
T,
|
|
125
|
+
TEventPublisher,
|
|
126
|
+
TEventPublisherServiceName
|
|
127
|
+
>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
publisher<T extends EventPublisher<any>, TName extends string>(
|
|
131
|
+
publisher: Service<TName, T>,
|
|
132
|
+
): FunctionBuilder<TInput, OutSchema, TServices, TLogger, T, TName> {
|
|
133
|
+
this._publisher = publisher as unknown as Service<
|
|
134
|
+
TEventPublisherServiceName,
|
|
135
|
+
TEventPublisher
|
|
136
|
+
>;
|
|
137
|
+
|
|
138
|
+
return this as unknown as FunctionBuilder<
|
|
139
|
+
TInput,
|
|
140
|
+
OutSchema,
|
|
141
|
+
TServices,
|
|
142
|
+
TLogger,
|
|
143
|
+
T,
|
|
144
|
+
TName
|
|
145
|
+
>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
handle(
|
|
149
|
+
fn: FunctionHandler<TInput, TServices, TLogger, OutSchema>,
|
|
150
|
+
): Function<
|
|
151
|
+
TInput,
|
|
152
|
+
TServices,
|
|
153
|
+
TLogger,
|
|
154
|
+
OutSchema,
|
|
155
|
+
FunctionHandler<TInput, TServices, TLogger, OutSchema>,
|
|
156
|
+
TEventPublisher,
|
|
157
|
+
TEventPublisherServiceName
|
|
158
|
+
> {
|
|
159
|
+
const func = new Function(
|
|
160
|
+
fn,
|
|
161
|
+
this._timeout,
|
|
162
|
+
this.type,
|
|
163
|
+
this.inputSchema,
|
|
164
|
+
this.outputSchema,
|
|
165
|
+
this._services,
|
|
166
|
+
this._logger,
|
|
167
|
+
this._publisher,
|
|
168
|
+
this._events,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Reset builder state after creating the function to prevent pollution
|
|
172
|
+
this._services = [] as Service[] as TServices;
|
|
173
|
+
this._logger = DEFAULT_LOGGER;
|
|
174
|
+
this._events = [];
|
|
175
|
+
this._publisher = undefined;
|
|
176
|
+
this.inputSchema = undefined;
|
|
177
|
+
this.outputSchema = undefined;
|
|
178
|
+
this._timeout = undefined;
|
|
179
|
+
|
|
180
|
+
return func;
|
|
181
|
+
}
|
|
182
|
+
}
|