@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,139 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_EndpointBuilder = require('./EndpointBuilder-BHFSpbPR.cjs');
|
|
3
|
+
const lodash_uniqby = require_chunk.__toESM(require("lodash.uniqby"));
|
|
4
|
+
const __geekmidas_logger_console = require_chunk.__toESM(require("@geekmidas/logger/console"));
|
|
5
|
+
|
|
6
|
+
//#region src/endpoints/EndpointFactory.ts
|
|
7
|
+
const DEFAULT_LOGGER = new __geekmidas_logger_console.ConsoleLogger();
|
|
8
|
+
var EndpointFactory = class EndpointFactory {
|
|
9
|
+
defaultServices;
|
|
10
|
+
basePath = "";
|
|
11
|
+
defaultAuthorizeFn;
|
|
12
|
+
defaultEventPublisher;
|
|
13
|
+
defaultSessionExtractor;
|
|
14
|
+
defaultLogger = DEFAULT_LOGGER;
|
|
15
|
+
constructor({ basePath, defaultAuthorizeFn, defaultLogger, defaultSessionExtractor, defaultServices = [], defaultEventPublisher } = {}) {
|
|
16
|
+
this.defaultServices = (0, lodash_uniqby.default)(defaultServices, (s) => s.serviceName);
|
|
17
|
+
this.basePath = basePath || "";
|
|
18
|
+
this.defaultAuthorizeFn = defaultAuthorizeFn;
|
|
19
|
+
this.defaultLogger = defaultLogger || DEFAULT_LOGGER;
|
|
20
|
+
this.defaultSessionExtractor = defaultSessionExtractor;
|
|
21
|
+
this.defaultEventPublisher = defaultEventPublisher;
|
|
22
|
+
}
|
|
23
|
+
static joinPaths(path, basePath = "") {
|
|
24
|
+
if (!basePath && !path) return "/";
|
|
25
|
+
if (!basePath) return path.startsWith("/") ? path : "/" + path;
|
|
26
|
+
if (!path) return basePath.startsWith("/") ? basePath : "/" + basePath;
|
|
27
|
+
const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
28
|
+
const segment = path.startsWith("/") ? path : "/" + path;
|
|
29
|
+
let result = base + segment;
|
|
30
|
+
if (!result.startsWith("/")) result = "/" + result;
|
|
31
|
+
result = result.replace(/^\/+/g, "/");
|
|
32
|
+
if (result.length > 1 && result.endsWith("/")) result = result.slice(0, -1);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
route(path) {
|
|
36
|
+
const newBasePath = EndpointFactory.joinPaths(path, this.basePath);
|
|
37
|
+
return new EndpointFactory({
|
|
38
|
+
defaultServices: this.defaultServices,
|
|
39
|
+
basePath: newBasePath,
|
|
40
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
41
|
+
defaultLogger: this.defaultLogger,
|
|
42
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
43
|
+
defaultEventPublisher: this.defaultEventPublisher
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
authorize(fn) {
|
|
47
|
+
return new EndpointFactory({
|
|
48
|
+
defaultServices: this.defaultServices,
|
|
49
|
+
basePath: this.basePath,
|
|
50
|
+
defaultAuthorizeFn: fn,
|
|
51
|
+
defaultLogger: this.defaultLogger,
|
|
52
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
53
|
+
defaultEventPublisher: this.defaultEventPublisher
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
services(services) {
|
|
57
|
+
return new EndpointFactory({
|
|
58
|
+
defaultServices: [...services, ...this.defaultServices],
|
|
59
|
+
basePath: this.basePath,
|
|
60
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
61
|
+
defaultLogger: this.defaultLogger,
|
|
62
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
63
|
+
defaultEventPublisher: this.defaultEventPublisher
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
logger(logger) {
|
|
67
|
+
return new EndpointFactory({
|
|
68
|
+
defaultServices: this.defaultServices,
|
|
69
|
+
basePath: this.basePath,
|
|
70
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
71
|
+
defaultLogger: logger,
|
|
72
|
+
defaultSessionExtractor: this.defaultSessionExtractor
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
publisher(publisher) {
|
|
76
|
+
return new EndpointFactory({
|
|
77
|
+
defaultServices: this.defaultServices,
|
|
78
|
+
basePath: this.basePath,
|
|
79
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
80
|
+
defaultLogger: this.defaultLogger,
|
|
81
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
82
|
+
defaultEventPublisher: publisher
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
session(session) {
|
|
86
|
+
return new EndpointFactory({
|
|
87
|
+
defaultServices: this.defaultServices,
|
|
88
|
+
basePath: this.basePath,
|
|
89
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
90
|
+
defaultLogger: this.defaultLogger,
|
|
91
|
+
defaultSessionExtractor: session,
|
|
92
|
+
defaultEventPublisher: this.defaultEventPublisher
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
createBuilder(method, path) {
|
|
96
|
+
const fullPath = EndpointFactory.joinPaths(path, this.basePath);
|
|
97
|
+
const builder = new require_EndpointBuilder.EndpointBuilder(fullPath, method);
|
|
98
|
+
if (this.defaultAuthorizeFn) builder._authorize = this.defaultAuthorizeFn;
|
|
99
|
+
if (this.defaultServices.length) builder._services = this.defaultServices;
|
|
100
|
+
if (this.defaultLogger) builder._logger = this.defaultLogger;
|
|
101
|
+
if (this.defaultSessionExtractor) builder._getSession = this.defaultSessionExtractor;
|
|
102
|
+
if (this.defaultEventPublisher) builder._setPublisher(this.defaultEventPublisher);
|
|
103
|
+
return builder;
|
|
104
|
+
}
|
|
105
|
+
post(path) {
|
|
106
|
+
return this.createBuilder("POST", path);
|
|
107
|
+
}
|
|
108
|
+
get(path) {
|
|
109
|
+
return this.createBuilder("GET", path);
|
|
110
|
+
}
|
|
111
|
+
put(path) {
|
|
112
|
+
return this.createBuilder("PUT", path);
|
|
113
|
+
}
|
|
114
|
+
delete(path) {
|
|
115
|
+
return this.createBuilder("DELETE", path);
|
|
116
|
+
}
|
|
117
|
+
patch(path) {
|
|
118
|
+
return this.createBuilder("PATCH", path);
|
|
119
|
+
}
|
|
120
|
+
options(path) {
|
|
121
|
+
return this.createBuilder("OPTIONS", path);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const e = new EndpointFactory();
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
Object.defineProperty(exports, 'EndpointFactory', {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return EndpointFactory;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, 'e', {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return e;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=EndpointFactory-CXX4E6Gx.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EndpointFactory-CXX4E6Gx.cjs","names":["ConsoleLogger","path: P","basePath: TBasePath","path: TPath","fn: AuthorizeFn<TServices, TLogger, TSession>","services: S","logger: L","publisher: Service<TServiceName, T>","session: SessionFn<TServices, TLogger, T>","method: TMethod","EndpointBuilder"],"sources":["../src/endpoints/EndpointFactory.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { ConsoleLogger } from '@geekmidas/logger/console';\nimport type { Service } from '@geekmidas/services';\nimport uniqBy from 'lodash.uniqby';\nimport type { AuthorizeFn, SessionFn } from './Endpoint';\nimport { EndpointBuilder } from './EndpointBuilder';\n\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { HttpMethod } from '../types';\n\nconst DEFAULT_LOGGER = new ConsoleLogger() as any;\n\nexport class EndpointFactory<\n TServices extends Service[] = [],\n TBasePath extends string = '',\n TLogger extends Logger = Logger,\n TSession = unknown,\n TEventPublisher extends EventPublisher<any> | undefined = undefined,\n TEventPublisherServiceName extends string = string,\n> {\n // @ts-ignore\n private defaultServices: TServices;\n private basePath: TBasePath = '' as TBasePath;\n private defaultAuthorizeFn?: AuthorizeFn<TServices, TLogger, TSession>;\n private defaultEventPublisher:\n | Service<TEventPublisherServiceName, TEventPublisher>\n | undefined;\n private defaultSessionExtractor?: SessionFn<TServices, TLogger, TSession>;\n private defaultLogger: TLogger = DEFAULT_LOGGER;\n\n constructor({\n basePath,\n defaultAuthorizeFn,\n defaultLogger,\n defaultSessionExtractor,\n // @ts-ignore\n defaultServices = [] as TServices,\n defaultEventPublisher,\n }: EndpointFactoryOptions<\n TServices,\n TBasePath,\n TLogger,\n TSession,\n TEventPublisher,\n TEventPublisherServiceName\n > = {}) {\n // Initialize default services\n this.defaultServices = uniqBy(\n defaultServices,\n (s) => s.serviceName,\n ) as TServices;\n\n this.basePath = basePath || ('' as TBasePath);\n this.defaultAuthorizeFn = defaultAuthorizeFn;\n this.defaultLogger = defaultLogger || (DEFAULT_LOGGER as TLogger);\n this.defaultSessionExtractor = defaultSessionExtractor;\n this.defaultEventPublisher = defaultEventPublisher;\n }\n\n static joinPaths<TBasePath extends string, P extends string>(\n path: P,\n basePath: TBasePath = '' as TBasePath,\n ): JoinPaths<TBasePath, P> {\n // Handle empty cases\n if (!basePath && !path) return '/' as JoinPaths<TBasePath, P>;\n if (!basePath)\n return (path.startsWith('/') ? path : '/' + path) as JoinPaths<\n TBasePath,\n P\n >;\n if (!path)\n return (\n basePath.startsWith('/') ? basePath : '/' + basePath\n ) as JoinPaths<TBasePath, P>;\n\n const base = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;\n const segment = path.startsWith('/') ? path : '/' + path;\n\n let result = base + segment;\n\n // Ensure leading slash\n if (!result.startsWith('/')) {\n result = '/' + result;\n }\n\n // Normalize multiple slashes (except in the middle of the path where they might be intentional)\n result = result.replace(/^\\/+/g, '/');\n\n // Remove trailing slash unless it's the root path \"/\"\n if (result.length > 1 && result.endsWith('/')) {\n result = result.slice(0, -1);\n }\n\n return result as JoinPaths<TBasePath, P>;\n }\n\n // Create a sub-router with a path prefix\n route<TPath extends string>(\n path: TPath,\n ): EndpointFactory<\n TServices,\n JoinPaths<TBasePath, TPath>,\n TLogger,\n TSession,\n TEventPublisher\n > {\n const newBasePath = EndpointFactory.joinPaths(path, this.basePath);\n return new EndpointFactory({\n defaultServices: this.defaultServices,\n basePath: newBasePath,\n defaultAuthorizeFn: this.defaultAuthorizeFn,\n defaultLogger: this.defaultLogger,\n defaultSessionExtractor: this.defaultSessionExtractor,\n defaultEventPublisher: this.defaultEventPublisher,\n });\n }\n\n // Create a new factory with authorization\n authorize(\n fn: AuthorizeFn<TServices, TLogger, TSession>,\n ): EndpointFactory<TServices, TBasePath, TLogger, TSession, TEventPublisher> {\n return new EndpointFactory({\n defaultServices: this.defaultServices,\n basePath: this.basePath,\n defaultAuthorizeFn: fn,\n defaultLogger: this.defaultLogger,\n defaultSessionExtractor: this.defaultSessionExtractor,\n defaultEventPublisher: this.defaultEventPublisher,\n });\n }\n\n // Create a new factory with services\n services<S extends Service[]>(\n services: S,\n ): EndpointFactory<\n [...S, ...TServices],\n TBasePath,\n TLogger,\n TSession,\n TEventPublisher\n > {\n return new EndpointFactory<\n [...S, ...TServices],\n TBasePath,\n TLogger,\n TSession,\n TEventPublisher\n >({\n defaultServices: [...services, ...this.defaultServices],\n basePath: this.basePath,\n defaultAuthorizeFn: this.defaultAuthorizeFn,\n defaultLogger: this.defaultLogger,\n defaultSessionExtractor: this.defaultSessionExtractor,\n defaultEventPublisher: this.defaultEventPublisher,\n });\n }\n\n logger<L extends Logger>(\n logger: L,\n ): EndpointFactory<TServices, TBasePath, L, TSession> {\n return new EndpointFactory<TServices, TBasePath, L, TSession>({\n defaultServices: this.defaultServices,\n basePath: this.basePath,\n defaultAuthorizeFn: this.defaultAuthorizeFn,\n defaultLogger: logger,\n defaultSessionExtractor: this.defaultSessionExtractor,\n } as EndpointFactoryOptions<TServices, TBasePath, L, TSession>);\n }\n\n publisher<\n T extends EventPublisher<any>,\n TServiceName extends string = string,\n >(\n publisher: Service<TServiceName, T>,\n ): EndpointFactory<TServices, TBasePath, TLogger, TSession, T> {\n return new EndpointFactory<TServices, TBasePath, TLogger, TSession, T>({\n defaultServices: this.defaultServices,\n basePath: this.basePath,\n defaultAuthorizeFn: this.defaultAuthorizeFn,\n defaultLogger: this.defaultLogger,\n defaultSessionExtractor: this.defaultSessionExtractor,\n defaultEventPublisher: publisher,\n });\n }\n\n session<T>(session: SessionFn<TServices, TLogger, T>) {\n return new EndpointFactory<TServices, TBasePath, TLogger, T>({\n defaultServices: this.defaultServices,\n basePath: this.basePath,\n // @ts-ignore\n defaultAuthorizeFn: this.defaultAuthorizeFn,\n defaultLogger: this.defaultLogger,\n defaultSessionExtractor: session,\n defaultEventPublisher: this.defaultEventPublisher as any,\n });\n }\n\n private createBuilder<TMethod extends HttpMethod, TPath extends string>(\n method: TMethod,\n path: TPath,\n ): EndpointBuilder<\n JoinPaths<TBasePath, TPath>,\n TMethod,\n {},\n TServices,\n TLogger,\n undefined,\n TSession,\n TEventPublisher\n > {\n const fullPath = EndpointFactory.joinPaths(path, this.basePath);\n const builder = new EndpointBuilder<\n JoinPaths<TBasePath, TPath>,\n TMethod,\n {},\n TServices,\n TLogger,\n undefined,\n TSession,\n TEventPublisher\n >(fullPath, method);\n\n if (this.defaultAuthorizeFn) {\n // @ts-ignore\n builder._authorize = this.defaultAuthorizeFn;\n }\n if (this.defaultServices.length) {\n builder._services = this.defaultServices as TServices;\n }\n\n if (this.defaultLogger) {\n builder._logger = this.defaultLogger as TLogger;\n }\n\n if (this.defaultSessionExtractor) {\n builder._getSession = this.defaultSessionExtractor as SessionFn<\n TServices,\n TLogger,\n TSession\n >;\n }\n\n if (this.defaultEventPublisher) {\n builder._setPublisher(this.defaultEventPublisher);\n }\n\n return builder as unknown as EndpointBuilder<\n JoinPaths<TBasePath, TPath>,\n TMethod,\n {},\n TServices,\n TLogger,\n undefined,\n TSession,\n TEventPublisher,\n TEventPublisherServiceName\n >;\n }\n\n post<TPath extends string>(path: TPath) {\n return this.createBuilder('POST', path);\n }\n\n get<TPath extends string>(path: TPath) {\n return this.createBuilder('GET', path);\n }\n\n put<TPath extends string>(path: TPath) {\n return this.createBuilder('PUT', path);\n }\n\n delete<TPath extends string>(path: TPath) {\n return this.createBuilder('DELETE', path);\n }\n\n patch<TPath extends string>(path: TPath) {\n return this.createBuilder('PATCH', path);\n }\n\n options<TPath extends string>(path: TPath) {\n return this.createBuilder('OPTIONS', path);\n }\n}\n\nexport type RemoveTrailingSlash<T extends string> = T extends `${infer Rest}/`\n ? Rest extends ''\n ? T // Keep \"/\" as is\n : Rest\n : T;\n\nexport type JoinPaths<\n TBasePath extends string,\n TPath extends string,\n> = RemoveTrailingSlash<\n TBasePath extends ''\n ? TPath\n : TPath extends ''\n ? TBasePath\n : TBasePath extends '/'\n ? TPath extends `/${string}`\n ? TPath\n : `/${TPath}`\n : TBasePath extends `${infer Base}/`\n ? TPath extends `/${infer Rest}`\n ? `${Base}/${Rest}`\n : `${Base}/${TPath}`\n : TPath extends `/${infer Rest}`\n ? `${TBasePath}/${Rest}`\n : `${TBasePath}/${TPath}`\n>;\n\nexport interface EndpointFactoryOptions<\n TServices extends Service[] = [],\n TBasePath extends string = '',\n TLogger extends Logger = Logger,\n TSession = unknown,\n TEventPublisher extends EventPublisher<any> | undefined = undefined,\n TEventPublisherServiceName extends string = string,\n> {\n defaultServices?: TServices;\n basePath?: TBasePath;\n defaultAuthorizeFn?: AuthorizeFn<TServices, TLogger, TSession>;\n defaultLogger?: TLogger;\n defaultSessionExtractor?: SessionFn<TServices, TLogger, TSession>;\n defaultEventPublisher?: Service<TEventPublisherServiceName, TEventPublisher>;\n defaultEvents?: MappedEvent<TEventPublisher, undefined>[];\n}\n\nexport const e = new EndpointFactory();\n"],"mappings":";;;;;;AAUA,MAAM,iBAAiB,IAAIA;AAE3B,IAAa,kBAAb,MAAa,gBAOX;CAEA,AAAQ;CACR,AAAQ,WAAsB;CAC9B,AAAQ;CACR,AAAQ;CAGR,AAAQ;CACR,AAAQ,gBAAyB;CAEjC,YAAY,EACV,UACA,oBACA,eACA,yBAEA,kBAAkB,CAAE,GACpB,uBAQD,GAAG,CAAE,GAAE;AAEN,OAAK,kBAAkB,2BACrB,iBACA,CAAC,MAAM,EAAE,YACV;AAED,OAAK,WAAW,YAAa;AAC7B,OAAK,qBAAqB;AAC1B,OAAK,gBAAgB,iBAAkB;AACvC,OAAK,0BAA0B;AAC/B,OAAK,wBAAwB;CAC9B;CAED,OAAO,UACLC,MACAC,WAAsB,IACG;AAEzB,OAAK,aAAa,KAAM,QAAO;AAC/B,OAAK,SACH,QAAQ,KAAK,WAAW,IAAI,GAAG,OAAO,MAAM;AAI9C,OAAK,KACH,QACE,SAAS,WAAW,IAAI,GAAG,WAAW,MAAM;EAGhD,MAAM,OAAO,SAAS,SAAS,IAAI,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG;EAC9D,MAAM,UAAU,KAAK,WAAW,IAAI,GAAG,OAAO,MAAM;EAEpD,IAAI,SAAS,OAAO;AAGpB,OAAK,OAAO,WAAW,IAAI,CACzB,UAAS,MAAM;AAIjB,WAAS,OAAO,QAAQ,SAAS,IAAI;AAGrC,MAAI,OAAO,SAAS,KAAK,OAAO,SAAS,IAAI,CAC3C,UAAS,OAAO,MAAM,GAAG,GAAG;AAG9B,SAAO;CACR;CAGD,MACEC,MAOA;EACA,MAAM,cAAc,gBAAgB,UAAU,MAAM,KAAK,SAAS;AAClE,SAAO,IAAI,gBAAgB;GACzB,iBAAiB,KAAK;GACtB,UAAU;GACV,oBAAoB,KAAK;GACzB,eAAe,KAAK;GACpB,yBAAyB,KAAK;GAC9B,uBAAuB,KAAK;EAC7B;CACF;CAGD,UACEC,IAC2E;AAC3E,SAAO,IAAI,gBAAgB;GACzB,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,oBAAoB;GACpB,eAAe,KAAK;GACpB,yBAAyB,KAAK;GAC9B,uBAAuB,KAAK;EAC7B;CACF;CAGD,SACEC,UAOA;AACA,SAAO,IAAI,gBAMT;GACA,iBAAiB,CAAC,GAAG,UAAU,GAAG,KAAK,eAAgB;GACvD,UAAU,KAAK;GACf,oBAAoB,KAAK;GACzB,eAAe,KAAK;GACpB,yBAAyB,KAAK;GAC9B,uBAAuB,KAAK;EAC7B;CACF;CAED,OACEC,QACoD;AACpD,SAAO,IAAI,gBAAmD;GAC5D,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,oBAAoB,KAAK;GACzB,eAAe;GACf,yBAAyB,KAAK;EAC/B;CACF;CAED,UAIEC,WAC6D;AAC7D,SAAO,IAAI,gBAA4D;GACrE,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,oBAAoB,KAAK;GACzB,eAAe,KAAK;GACpB,yBAAyB,KAAK;GAC9B,uBAAuB;EACxB;CACF;CAED,QAAWC,SAA2C;AACpD,SAAO,IAAI,gBAAkD;GAC3D,iBAAiB,KAAK;GACtB,UAAU,KAAK;GAEf,oBAAoB,KAAK;GACzB,eAAe,KAAK;GACpB,yBAAyB;GACzB,uBAAuB,KAAK;EAC7B;CACF;CAED,AAAQ,cACNC,QACAN,MAUA;EACA,MAAM,WAAW,gBAAgB,UAAU,MAAM,KAAK,SAAS;EAC/D,MAAM,UAAU,IAAIO,wCASlB,UAAU;AAEZ,MAAI,KAAK,mBAEP,SAAQ,aAAa,KAAK;AAE5B,MAAI,KAAK,gBAAgB,OACvB,SAAQ,YAAY,KAAK;AAG3B,MAAI,KAAK,cACP,SAAQ,UAAU,KAAK;AAGzB,MAAI,KAAK,wBACP,SAAQ,cAAc,KAAK;AAO7B,MAAI,KAAK,sBACP,SAAQ,cAAc,KAAK,sBAAsB;AAGnD,SAAO;CAWR;CAED,KAA2BP,MAAa;AACtC,SAAO,KAAK,cAAc,QAAQ,KAAK;CACxC;CAED,IAA0BA,MAAa;AACrC,SAAO,KAAK,cAAc,OAAO,KAAK;CACvC;CAED,IAA0BA,MAAa;AACrC,SAAO,KAAK,cAAc,OAAO,KAAK;CACvC;CAED,OAA6BA,MAAa;AACxC,SAAO,KAAK,cAAc,UAAU,KAAK;CAC1C;CAED,MAA4BA,MAAa;AACvC,SAAO,KAAK,cAAc,SAAS,KAAK;CACzC;CAED,QAA8BA,MAAa;AACzC,SAAO,KAAK,cAAc,WAAW,KAAK;CAC3C;AACF;AA8CD,MAAa,IAAI,IAAI"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AuthorizeFn, SessionFn } from "./Endpoint-C7z9YJHK.cjs";
|
|
2
|
+
import { EndpointBuilder } from "./EndpointBuilder-CP9RGwZH.cjs";
|
|
3
|
+
import { EventPublisher, MappedEvent } from "@geekmidas/events";
|
|
4
|
+
import { Logger } from "@geekmidas/logger";
|
|
5
|
+
import { Service } from "@geekmidas/services";
|
|
6
|
+
|
|
7
|
+
//#region src/endpoints/EndpointFactory.d.ts
|
|
8
|
+
declare class EndpointFactory<TServices extends Service[] = [], TBasePath extends string = '', TLogger extends Logger = Logger, TSession = unknown, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> {
|
|
9
|
+
private defaultServices;
|
|
10
|
+
private basePath;
|
|
11
|
+
private defaultAuthorizeFn?;
|
|
12
|
+
private defaultEventPublisher;
|
|
13
|
+
private defaultSessionExtractor?;
|
|
14
|
+
private defaultLogger;
|
|
15
|
+
constructor({
|
|
16
|
+
basePath,
|
|
17
|
+
defaultAuthorizeFn,
|
|
18
|
+
defaultLogger,
|
|
19
|
+
defaultSessionExtractor,
|
|
20
|
+
defaultServices,
|
|
21
|
+
defaultEventPublisher
|
|
22
|
+
}?: EndpointFactoryOptions<TServices, TBasePath, TLogger, TSession, TEventPublisher, TEventPublisherServiceName>);
|
|
23
|
+
static joinPaths<TBasePath extends string, P extends string>(path: P, basePath?: TBasePath): JoinPaths<TBasePath, P>;
|
|
24
|
+
route<TPath extends string>(path: TPath): EndpointFactory<TServices, JoinPaths<TBasePath, TPath>, TLogger, TSession, TEventPublisher>;
|
|
25
|
+
authorize(fn: AuthorizeFn<TServices, TLogger, TSession>): EndpointFactory<TServices, TBasePath, TLogger, TSession, TEventPublisher>;
|
|
26
|
+
services<S extends Service[]>(services: S): EndpointFactory<[...S, ...TServices], TBasePath, TLogger, TSession, TEventPublisher>;
|
|
27
|
+
logger<L extends Logger>(logger: L): EndpointFactory<TServices, TBasePath, L, TSession>;
|
|
28
|
+
publisher<T extends EventPublisher<any>, TServiceName extends string = string>(publisher: Service<TServiceName, T>): EndpointFactory<TServices, TBasePath, TLogger, TSession, T>;
|
|
29
|
+
session<T>(session: SessionFn<TServices, TLogger, T>): EndpointFactory<TServices, TBasePath, TLogger, T, undefined, string>;
|
|
30
|
+
private createBuilder;
|
|
31
|
+
post<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "POST", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
32
|
+
get<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "GET", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
33
|
+
put<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "PUT", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
34
|
+
delete<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "DELETE", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
35
|
+
patch<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "PATCH", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
36
|
+
options<TPath extends string>(path: TPath): EndpointBuilder<RemoveTrailingSlash<TBasePath extends "" ? TPath : TPath extends "" ? TBasePath : TBasePath extends "/" ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest_1}` ? `${TBasePath}/${Rest_1}` : `${TBasePath}/${TPath}`>, "OPTIONS", {}, TServices, TLogger, undefined, TSession, TEventPublisher, string>;
|
|
37
|
+
}
|
|
38
|
+
type RemoveTrailingSlash<T extends string> = T extends `${infer Rest}/` ? Rest extends '' ? T : Rest : T;
|
|
39
|
+
type JoinPaths<TBasePath extends string, TPath extends string> = RemoveTrailingSlash<TBasePath extends '' ? TPath : TPath extends '' ? TBasePath : TBasePath extends '/' ? TPath extends `/${string}` ? TPath : `/${TPath}` : TBasePath extends `${infer Base}/` ? TPath extends `/${infer Rest}` ? `${Base}/${Rest}` : `${Base}/${TPath}` : TPath extends `/${infer Rest}` ? `${TBasePath}/${Rest}` : `${TBasePath}/${TPath}`>;
|
|
40
|
+
interface EndpointFactoryOptions<TServices extends Service[] = [], TBasePath extends string = '', TLogger extends Logger = Logger, TSession = unknown, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> {
|
|
41
|
+
defaultServices?: TServices;
|
|
42
|
+
basePath?: TBasePath;
|
|
43
|
+
defaultAuthorizeFn?: AuthorizeFn<TServices, TLogger, TSession>;
|
|
44
|
+
defaultLogger?: TLogger;
|
|
45
|
+
defaultSessionExtractor?: SessionFn<TServices, TLogger, TSession>;
|
|
46
|
+
defaultEventPublisher?: Service<TEventPublisherServiceName, TEventPublisher>;
|
|
47
|
+
defaultEvents?: MappedEvent<TEventPublisher, undefined>[];
|
|
48
|
+
}
|
|
49
|
+
declare const e: EndpointFactory<[], "", Logger, unknown, undefined, string>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { EndpointFactory, EndpointFactoryOptions, JoinPaths, RemoveTrailingSlash, e };
|
|
52
|
+
//# sourceMappingURL=EndpointFactory-D2zgWbXZ.d.cts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Construct, ConstructType } from "./Construct-Bm-PSO2V.cjs";
|
|
2
|
+
import { EventPublisher, MappedEvent } from "@geekmidas/events";
|
|
3
|
+
import { Logger } from "@geekmidas/logger";
|
|
4
|
+
import { Service, ServiceRecord } from "@geekmidas/services";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema } from "@geekmidas/schema";
|
|
7
|
+
|
|
8
|
+
//#region src/functions/Function.d.ts
|
|
9
|
+
declare class FunctionFactory<TServices extends Service[] = [], TLogger extends Logger = Logger> {
|
|
10
|
+
private defaultLogger;
|
|
11
|
+
private defaultServices;
|
|
12
|
+
constructor(defaultServices: TServices, defaultLogger?: TLogger);
|
|
13
|
+
services<S extends Service[]>(services: S): FunctionFactory<[...S, ...TServices], TLogger>;
|
|
14
|
+
logger<L extends Logger>(logger: L): FunctionFactory<TServices, L>;
|
|
15
|
+
}
|
|
16
|
+
declare class Function<TInput extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, Fn extends FunctionHandler<TInput, TServices, TLogger, OutSchema> = FunctionHandler<TInput, TServices, TLogger, OutSchema>, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> extends Construct<TLogger, TEventPublisherServiceName, TEventPublisher, OutSchema, TServices> {
|
|
17
|
+
protected readonly fn: Fn;
|
|
18
|
+
readonly timeout: number;
|
|
19
|
+
input?: TInput | undefined;
|
|
20
|
+
__IS_FUNCTION__: boolean;
|
|
21
|
+
static isFunction(obj: any): obj is Function<any, any, any, any, any>;
|
|
22
|
+
/**
|
|
23
|
+
* Validates data against a StandardSchema.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - The StandardSchema to validate against
|
|
26
|
+
* @param data - The data to validate
|
|
27
|
+
* @returns Validation result with value or issues
|
|
28
|
+
*/
|
|
29
|
+
static validate<T extends StandardSchemaV1>(schema: T, data: unknown): StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
30
|
+
/**
|
|
31
|
+
* Parses and validates data against a schema, throwing an error if validation fails.
|
|
32
|
+
*
|
|
33
|
+
* @param schema - The StandardSchema to validate against
|
|
34
|
+
* @param data - The data to parse and validate
|
|
35
|
+
* @returns The validated data with proper typing
|
|
36
|
+
* @throws {UnprocessableEntityError} When validation fails
|
|
37
|
+
*/
|
|
38
|
+
static parseSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<InferStandardSchema<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Parses and validates the endpoint output against the output schema.
|
|
41
|
+
*
|
|
42
|
+
* @param output - The raw output data to validate
|
|
43
|
+
* @returns The validated output data
|
|
44
|
+
* @throws {UnprocessableEntityError} When output validation fails
|
|
45
|
+
*/
|
|
46
|
+
parseOutput(output: unknown): Promise<InferStandardSchema<OutSchema>>;
|
|
47
|
+
constructor(fn: Fn, timeout?: number,
|
|
48
|
+
// Default timeout of 30 seconds
|
|
49
|
+
type?: ConstructType, input?: TInput | undefined, outputSchema?: OutSchema, services?: TServices, logger?: TLogger, publisherService?: Service<TEventPublisherServiceName, TEventPublisher>, events?: MappedEvent<TEventPublisher, OutSchema>[]);
|
|
50
|
+
}
|
|
51
|
+
type FunctionHandler<TInput extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined> = (ctx: FunctionContext<TInput, TServices, TLogger>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
|
|
52
|
+
type FunctionContext<Input extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger> = {
|
|
53
|
+
services: ServiceRecord<TServices>;
|
|
54
|
+
logger: TLogger;
|
|
55
|
+
input: InferComposableStandardSchema<Input>;
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { Function, FunctionContext, FunctionFactory, FunctionHandler };
|
|
59
|
+
//# sourceMappingURL=Function-BP58p9Mp.d.cts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Construct, ConstructType } from "./Construct-DIguIyw4.mjs";
|
|
2
|
+
import { Service, ServiceRecord } from "@geekmidas/services";
|
|
3
|
+
import { EventPublisher, MappedEvent } from "@geekmidas/events";
|
|
4
|
+
import { Logger } from "@geekmidas/logger";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema } from "@geekmidas/schema";
|
|
7
|
+
|
|
8
|
+
//#region src/functions/Function.d.ts
|
|
9
|
+
declare class FunctionFactory<TServices extends Service[] = [], TLogger extends Logger = Logger> {
|
|
10
|
+
private defaultLogger;
|
|
11
|
+
private defaultServices;
|
|
12
|
+
constructor(defaultServices: TServices, defaultLogger?: TLogger);
|
|
13
|
+
services<S extends Service[]>(services: S): FunctionFactory<[...S, ...TServices], TLogger>;
|
|
14
|
+
logger<L extends Logger>(logger: L): FunctionFactory<TServices, L>;
|
|
15
|
+
}
|
|
16
|
+
declare class Function<TInput extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, Fn extends FunctionHandler<TInput, TServices, TLogger, OutSchema> = FunctionHandler<TInput, TServices, TLogger, OutSchema>, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> extends Construct<TLogger, TEventPublisherServiceName, TEventPublisher, OutSchema, TServices> {
|
|
17
|
+
protected readonly fn: Fn;
|
|
18
|
+
readonly timeout: number;
|
|
19
|
+
input?: TInput | undefined;
|
|
20
|
+
__IS_FUNCTION__: boolean;
|
|
21
|
+
static isFunction(obj: any): obj is Function<any, any, any, any, any>;
|
|
22
|
+
/**
|
|
23
|
+
* Validates data against a StandardSchema.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - The StandardSchema to validate against
|
|
26
|
+
* @param data - The data to validate
|
|
27
|
+
* @returns Validation result with value or issues
|
|
28
|
+
*/
|
|
29
|
+
static validate<T extends StandardSchemaV1>(schema: T, data: unknown): StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
30
|
+
/**
|
|
31
|
+
* Parses and validates data against a schema, throwing an error if validation fails.
|
|
32
|
+
*
|
|
33
|
+
* @param schema - The StandardSchema to validate against
|
|
34
|
+
* @param data - The data to parse and validate
|
|
35
|
+
* @returns The validated data with proper typing
|
|
36
|
+
* @throws {UnprocessableEntityError} When validation fails
|
|
37
|
+
*/
|
|
38
|
+
static parseSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<InferStandardSchema<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Parses and validates the endpoint output against the output schema.
|
|
41
|
+
*
|
|
42
|
+
* @param output - The raw output data to validate
|
|
43
|
+
* @returns The validated output data
|
|
44
|
+
* @throws {UnprocessableEntityError} When output validation fails
|
|
45
|
+
*/
|
|
46
|
+
parseOutput(output: unknown): Promise<InferStandardSchema<OutSchema>>;
|
|
47
|
+
constructor(fn: Fn, timeout?: number,
|
|
48
|
+
// Default timeout of 30 seconds
|
|
49
|
+
type?: ConstructType, input?: TInput | undefined, outputSchema?: OutSchema, services?: TServices, logger?: TLogger, publisherService?: Service<TEventPublisherServiceName, TEventPublisher>, events?: MappedEvent<TEventPublisher, OutSchema>[]);
|
|
50
|
+
}
|
|
51
|
+
type FunctionHandler<TInput extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined> = (ctx: FunctionContext<TInput, TServices, TLogger>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
|
|
52
|
+
type FunctionContext<Input extends ComposableStandardSchema | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger> = {
|
|
53
|
+
services: ServiceRecord<TServices>;
|
|
54
|
+
logger: TLogger;
|
|
55
|
+
input: InferComposableStandardSchema<Input>;
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { Function, FunctionContext, FunctionFactory, FunctionHandler };
|
|
59
|
+
//# sourceMappingURL=Function-BsBxc2wA.d.mts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Construct, ConstructType } from "./Construct-BbKCIPQm.mjs";
|
|
2
|
+
import uniqBy from "lodash.uniqby";
|
|
3
|
+
import { ConsoleLogger } from "@geekmidas/logger/console";
|
|
4
|
+
import { UnprocessableEntityError } from "@geekmidas/errors";
|
|
5
|
+
import { parseSchema } from "@geekmidas/schema/parser";
|
|
6
|
+
|
|
7
|
+
//#region src/functions/Function.ts
|
|
8
|
+
const DEFAULT_LOGGER$1 = new ConsoleLogger();
|
|
9
|
+
var FunctionFactory = class FunctionFactory {
|
|
10
|
+
defaultServices;
|
|
11
|
+
constructor(defaultServices, defaultLogger = DEFAULT_LOGGER$1) {
|
|
12
|
+
this.defaultLogger = defaultLogger;
|
|
13
|
+
this.defaultServices = uniqBy(defaultServices, (s) => s.serviceName);
|
|
14
|
+
}
|
|
15
|
+
services(services) {
|
|
16
|
+
return new FunctionFactory([...services, ...this.defaultServices], this.defaultLogger);
|
|
17
|
+
}
|
|
18
|
+
logger(logger) {
|
|
19
|
+
return new FunctionFactory(this.defaultServices, logger);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var Function = class Function extends Construct {
|
|
23
|
+
__IS_FUNCTION__ = true;
|
|
24
|
+
static isFunction(obj) {
|
|
25
|
+
return Boolean(obj && obj.__IS_FUNCTION__ === true && obj.type === ConstructType.Function);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates data against a StandardSchema.
|
|
29
|
+
*
|
|
30
|
+
* @param schema - The StandardSchema to validate against
|
|
31
|
+
* @param data - The data to validate
|
|
32
|
+
* @returns Validation result with value or issues
|
|
33
|
+
*/
|
|
34
|
+
static validate(schema, data) {
|
|
35
|
+
return schema["~standard"].validate(data);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parses and validates data against a schema, throwing an error if validation fails.
|
|
39
|
+
*
|
|
40
|
+
* @param schema - The StandardSchema to validate against
|
|
41
|
+
* @param data - The data to parse and validate
|
|
42
|
+
* @returns The validated data with proper typing
|
|
43
|
+
* @throws {UnprocessableEntityError} When validation fails
|
|
44
|
+
*/
|
|
45
|
+
static async parseSchema(schema, data) {
|
|
46
|
+
try {
|
|
47
|
+
return await parseSchema(schema, data);
|
|
48
|
+
} catch (issues) {
|
|
49
|
+
throw new UnprocessableEntityError("Validation failed", issues);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses and validates the endpoint output against the output schema.
|
|
54
|
+
*
|
|
55
|
+
* @param output - The raw output data to validate
|
|
56
|
+
* @returns The validated output data
|
|
57
|
+
* @throws {UnprocessableEntityError} When output validation fails
|
|
58
|
+
*/
|
|
59
|
+
async parseOutput(output) {
|
|
60
|
+
return Function.parseSchema(this.outputSchema, output);
|
|
61
|
+
}
|
|
62
|
+
constructor(fn, timeout = 3e4, type = ConstructType.Function, input, outputSchema, services = [], logger = DEFAULT_LOGGER$1, publisherService, events = []) {
|
|
63
|
+
super(type, logger, services, events, publisherService, outputSchema);
|
|
64
|
+
this.fn = fn;
|
|
65
|
+
this.timeout = timeout;
|
|
66
|
+
this.input = input;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { Function, FunctionFactory };
|
|
72
|
+
//# sourceMappingURL=Function-C5mW-38v.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Function-C5mW-38v.mjs","names":["DEFAULT_LOGGER","defaultServices: TServices","defaultLogger: TLogger","services: S","logger: L","obj: any","schema: T","data: unknown","output: unknown","fn: Fn","type: ConstructType","input?: TInput","outputSchema?: OutSchema","services: TServices","logger: TLogger","publisherService?: Service<TEventPublisherServiceName, TEventPublisher>","events: MappedEvent<TEventPublisher, OutSchema>[]"],"sources":["../src/functions/Function.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport uniqBy from 'lodash.uniqby';\n\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { Construct, ConstructType } from '../Construct';\n\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { ConsoleLogger } from '@geekmidas/logger/console';\nimport type {\n ComposableStandardSchema,\n InferComposableStandardSchema,\n InferStandardSchema,\n} from '@geekmidas/schema';\n\nimport { UnprocessableEntityError } from '@geekmidas/errors';\nimport { parseSchema } from '@geekmidas/schema/parser';\n\nconst DEFAULT_LOGGER = new ConsoleLogger() as any;\n\nexport class FunctionFactory<\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n> {\n private defaultServices: TServices;\n constructor(\n defaultServices: TServices,\n private defaultLogger: TLogger = DEFAULT_LOGGER,\n ) {\n // Initialize default services\n this.defaultServices = uniqBy(\n defaultServices,\n (s) => s.serviceName,\n ) as TServices;\n }\n\n // Create a new factory with services\n services<S extends Service[]>(\n services: S,\n ): FunctionFactory<[...S, ...TServices], TLogger> {\n return new FunctionFactory<[...S, ...TServices], TLogger>(\n [...services, ...this.defaultServices],\n this.defaultLogger,\n );\n }\n\n logger<L extends Logger>(logger: L): FunctionFactory<TServices, L> {\n return new FunctionFactory<TServices, L>(this.defaultServices, logger);\n }\n}\n\nexport class Function<\n TInput extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n OutSchema extends StandardSchemaV1 | undefined = undefined,\n Fn extends FunctionHandler<\n TInput,\n TServices,\n TLogger,\n OutSchema\n > = FunctionHandler<TInput, TServices, TLogger, OutSchema>,\n TEventPublisher extends EventPublisher<any> | undefined = undefined,\n TEventPublisherServiceName extends string = string,\n> extends Construct<\n TLogger,\n TEventPublisherServiceName,\n TEventPublisher,\n OutSchema,\n TServices\n> {\n __IS_FUNCTION__ = true;\n\n static isFunction(obj: any): obj is Function<any, any, any, any, any> {\n return Boolean(\n obj &&\n obj.__IS_FUNCTION__ === true &&\n obj.type === ConstructType.Function,\n );\n }\n\n /**\n * Validates data against a StandardSchema.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to validate\n * @returns Validation result with value or issues\n */\n static validate<T extends StandardSchemaV1>(schema: T, data: unknown) {\n return schema['~standard'].validate(data);\n }\n\n /**\n * Parses and validates data against a schema, throwing an error if validation fails.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to parse and validate\n * @returns The validated data with proper typing\n * @throws {UnprocessableEntityError} When validation fails\n */\n static async parseSchema<T extends StandardSchemaV1>(\n schema: T,\n data: unknown,\n ): Promise<InferStandardSchema<T>> {\n try {\n return await parseSchema(schema, data);\n } catch (issues) {\n throw new UnprocessableEntityError('Validation failed', issues);\n }\n }\n\n /**\n * Parses and validates the endpoint output against the output schema.\n *\n * @param output - The raw output data to validate\n * @returns The validated output data\n * @throws {UnprocessableEntityError} When output validation fails\n */\n async parseOutput(output: unknown): Promise<InferStandardSchema<OutSchema>> {\n return Function.parseSchema(\n this.outputSchema as StandardSchemaV1,\n output,\n ) as Promise<InferStandardSchema<OutSchema>>;\n }\n\n constructor(\n protected readonly fn: Fn,\n readonly timeout = 30000, // Default timeout of 30 seconds\n type: ConstructType = ConstructType.Function,\n public input?: TInput,\n outputSchema?: OutSchema,\n services: TServices = [] as unknown as TServices,\n logger: TLogger = DEFAULT_LOGGER,\n publisherService?: Service<TEventPublisherServiceName, TEventPublisher>,\n events: MappedEvent<TEventPublisher, OutSchema>[] = [],\n ) {\n super(type, logger, services, events, publisherService, outputSchema);\n }\n}\n\nexport type FunctionHandler<\n TInput extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n OutSchema extends StandardSchemaV1 | undefined = undefined,\n> = (\n ctx: FunctionContext<TInput, TServices, TLogger>,\n) => OutSchema extends StandardSchemaV1\n ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n : any | Promise<any>;\n\nexport type FunctionContext<\n Input extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n> = {\n services: ServiceRecord<TServices>;\n logger: TLogger;\n input: InferComposableStandardSchema<Input>;\n};\n"],"mappings":";;;;;;;AAkBA,MAAMA,mBAAiB,IAAI;AAE3B,IAAa,kBAAb,MAAa,gBAGX;CACA,AAAQ;CACR,YACEC,iBACQC,gBAAyBF,kBACjC;EADQ;AAGR,OAAK,kBAAkB,OACrB,iBACA,CAAC,MAAM,EAAE,YACV;CACF;CAGD,SACEG,UACgD;AAChD,SAAO,IAAI,gBACT,CAAC,GAAG,UAAU,GAAG,KAAK,eAAgB,GACtC,KAAK;CAER;CAED,OAAyBC,QAA0C;AACjE,SAAO,IAAI,gBAA8B,KAAK,iBAAiB;CAChE;AACF;AAED,IAAa,WAAb,MAAa,iBAaH,UAMR;CACA,kBAAkB;CAElB,OAAO,WAAWC,KAAoD;AACpE,SAAO,QACL,OACE,IAAI,oBAAoB,QACxB,IAAI,SAAS,cAAc,SAC9B;CACF;;;;;;;;CASD,OAAO,SAAqCC,QAAWC,MAAe;AACpE,SAAO,OAAO,aAAa,SAAS,KAAK;CAC1C;;;;;;;;;CAUD,aAAa,YACXD,QACAC,MACiC;AACjC,MAAI;AACF,UAAO,MAAM,YAAY,QAAQ,KAAK;EACvC,SAAQ,QAAQ;AACf,SAAM,IAAI,yBAAyB,qBAAqB;EACzD;CACF;;;;;;;;CASD,MAAM,YAAYC,QAA0D;AAC1E,SAAO,SAAS,YACd,KAAK,cACL,OACD;CACF;CAED,YACqBC,IACV,UAAU,KACnBC,OAAsB,cAAc,UAC7BC,OACPC,cACAC,WAAsB,CAAE,GACxBC,SAAkBd,kBAClBe,kBACAC,SAAoD,CAAE,GACtD;AACA,QAAM,MAAM,QAAQ,UAAU,QAAQ,kBAAkB,aAAa;EAVlD;EACV;EAEF;CAQR;AACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_Construct = require('./Construct-BSEs6uwW.cjs');
|
|
3
|
+
const lodash_uniqby = require_chunk.__toESM(require("lodash.uniqby"));
|
|
4
|
+
const __geekmidas_logger_console = require_chunk.__toESM(require("@geekmidas/logger/console"));
|
|
5
|
+
const __geekmidas_errors = require_chunk.__toESM(require("@geekmidas/errors"));
|
|
6
|
+
const __geekmidas_schema_parser = require_chunk.__toESM(require("@geekmidas/schema/parser"));
|
|
7
|
+
|
|
8
|
+
//#region src/functions/Function.ts
|
|
9
|
+
const DEFAULT_LOGGER = new __geekmidas_logger_console.ConsoleLogger();
|
|
10
|
+
var FunctionFactory = class FunctionFactory {
|
|
11
|
+
defaultServices;
|
|
12
|
+
constructor(defaultServices, defaultLogger = DEFAULT_LOGGER) {
|
|
13
|
+
this.defaultLogger = defaultLogger;
|
|
14
|
+
this.defaultServices = (0, lodash_uniqby.default)(defaultServices, (s) => s.serviceName);
|
|
15
|
+
}
|
|
16
|
+
services(services) {
|
|
17
|
+
return new FunctionFactory([...services, ...this.defaultServices], this.defaultLogger);
|
|
18
|
+
}
|
|
19
|
+
logger(logger) {
|
|
20
|
+
return new FunctionFactory(this.defaultServices, logger);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var Function = class Function extends require_Construct.Construct {
|
|
24
|
+
__IS_FUNCTION__ = true;
|
|
25
|
+
static isFunction(obj) {
|
|
26
|
+
return Boolean(obj && obj.__IS_FUNCTION__ === true && obj.type === require_Construct.ConstructType.Function);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates data against a StandardSchema.
|
|
30
|
+
*
|
|
31
|
+
* @param schema - The StandardSchema to validate against
|
|
32
|
+
* @param data - The data to validate
|
|
33
|
+
* @returns Validation result with value or issues
|
|
34
|
+
*/
|
|
35
|
+
static validate(schema, data) {
|
|
36
|
+
return schema["~standard"].validate(data);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses and validates data against a schema, throwing an error if validation fails.
|
|
40
|
+
*
|
|
41
|
+
* @param schema - The StandardSchema to validate against
|
|
42
|
+
* @param data - The data to parse and validate
|
|
43
|
+
* @returns The validated data with proper typing
|
|
44
|
+
* @throws {UnprocessableEntityError} When validation fails
|
|
45
|
+
*/
|
|
46
|
+
static async parseSchema(schema, data) {
|
|
47
|
+
try {
|
|
48
|
+
return await (0, __geekmidas_schema_parser.parseSchema)(schema, data);
|
|
49
|
+
} catch (issues) {
|
|
50
|
+
throw new __geekmidas_errors.UnprocessableEntityError("Validation failed", issues);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parses and validates the endpoint output against the output schema.
|
|
55
|
+
*
|
|
56
|
+
* @param output - The raw output data to validate
|
|
57
|
+
* @returns The validated output data
|
|
58
|
+
* @throws {UnprocessableEntityError} When output validation fails
|
|
59
|
+
*/
|
|
60
|
+
async parseOutput(output) {
|
|
61
|
+
return Function.parseSchema(this.outputSchema, output);
|
|
62
|
+
}
|
|
63
|
+
constructor(fn, timeout = 3e4, type = require_Construct.ConstructType.Function, input, outputSchema, services = [], logger = DEFAULT_LOGGER, publisherService, events = []) {
|
|
64
|
+
super(type, logger, services, events, publisherService, outputSchema);
|
|
65
|
+
this.fn = fn;
|
|
66
|
+
this.timeout = timeout;
|
|
67
|
+
this.input = input;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
Object.defineProperty(exports, 'Function', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return Function;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, 'FunctionFactory', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return FunctionFactory;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=Function-CbO2NZx-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Function-CbO2NZx-.cjs","names":["ConsoleLogger","defaultServices: TServices","defaultLogger: TLogger","services: S","logger: L","Construct","obj: any","ConstructType","schema: T","data: unknown","UnprocessableEntityError","output: unknown","fn: Fn","type: ConstructType","input?: TInput","outputSchema?: OutSchema","services: TServices","logger: TLogger","publisherService?: Service<TEventPublisherServiceName, TEventPublisher>","events: MappedEvent<TEventPublisher, OutSchema>[]"],"sources":["../src/functions/Function.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport uniqBy from 'lodash.uniqby';\n\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { Construct, ConstructType } from '../Construct';\n\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { ConsoleLogger } from '@geekmidas/logger/console';\nimport type {\n ComposableStandardSchema,\n InferComposableStandardSchema,\n InferStandardSchema,\n} from '@geekmidas/schema';\n\nimport { UnprocessableEntityError } from '@geekmidas/errors';\nimport { parseSchema } from '@geekmidas/schema/parser';\n\nconst DEFAULT_LOGGER = new ConsoleLogger() as any;\n\nexport class FunctionFactory<\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n> {\n private defaultServices: TServices;\n constructor(\n defaultServices: TServices,\n private defaultLogger: TLogger = DEFAULT_LOGGER,\n ) {\n // Initialize default services\n this.defaultServices = uniqBy(\n defaultServices,\n (s) => s.serviceName,\n ) as TServices;\n }\n\n // Create a new factory with services\n services<S extends Service[]>(\n services: S,\n ): FunctionFactory<[...S, ...TServices], TLogger> {\n return new FunctionFactory<[...S, ...TServices], TLogger>(\n [...services, ...this.defaultServices],\n this.defaultLogger,\n );\n }\n\n logger<L extends Logger>(logger: L): FunctionFactory<TServices, L> {\n return new FunctionFactory<TServices, L>(this.defaultServices, logger);\n }\n}\n\nexport class Function<\n TInput extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n OutSchema extends StandardSchemaV1 | undefined = undefined,\n Fn extends FunctionHandler<\n TInput,\n TServices,\n TLogger,\n OutSchema\n > = FunctionHandler<TInput, TServices, TLogger, OutSchema>,\n TEventPublisher extends EventPublisher<any> | undefined = undefined,\n TEventPublisherServiceName extends string = string,\n> extends Construct<\n TLogger,\n TEventPublisherServiceName,\n TEventPublisher,\n OutSchema,\n TServices\n> {\n __IS_FUNCTION__ = true;\n\n static isFunction(obj: any): obj is Function<any, any, any, any, any> {\n return Boolean(\n obj &&\n obj.__IS_FUNCTION__ === true &&\n obj.type === ConstructType.Function,\n );\n }\n\n /**\n * Validates data against a StandardSchema.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to validate\n * @returns Validation result with value or issues\n */\n static validate<T extends StandardSchemaV1>(schema: T, data: unknown) {\n return schema['~standard'].validate(data);\n }\n\n /**\n * Parses and validates data against a schema, throwing an error if validation fails.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to parse and validate\n * @returns The validated data with proper typing\n * @throws {UnprocessableEntityError} When validation fails\n */\n static async parseSchema<T extends StandardSchemaV1>(\n schema: T,\n data: unknown,\n ): Promise<InferStandardSchema<T>> {\n try {\n return await parseSchema(schema, data);\n } catch (issues) {\n throw new UnprocessableEntityError('Validation failed', issues);\n }\n }\n\n /**\n * Parses and validates the endpoint output against the output schema.\n *\n * @param output - The raw output data to validate\n * @returns The validated output data\n * @throws {UnprocessableEntityError} When output validation fails\n */\n async parseOutput(output: unknown): Promise<InferStandardSchema<OutSchema>> {\n return Function.parseSchema(\n this.outputSchema as StandardSchemaV1,\n output,\n ) as Promise<InferStandardSchema<OutSchema>>;\n }\n\n constructor(\n protected readonly fn: Fn,\n readonly timeout = 30000, // Default timeout of 30 seconds\n type: ConstructType = ConstructType.Function,\n public input?: TInput,\n outputSchema?: OutSchema,\n services: TServices = [] as unknown as TServices,\n logger: TLogger = DEFAULT_LOGGER,\n publisherService?: Service<TEventPublisherServiceName, TEventPublisher>,\n events: MappedEvent<TEventPublisher, OutSchema>[] = [],\n ) {\n super(type, logger, services, events, publisherService, outputSchema);\n }\n}\n\nexport type FunctionHandler<\n TInput extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n OutSchema extends StandardSchemaV1 | undefined = undefined,\n> = (\n ctx: FunctionContext<TInput, TServices, TLogger>,\n) => OutSchema extends StandardSchemaV1\n ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n : any | Promise<any>;\n\nexport type FunctionContext<\n Input extends ComposableStandardSchema | undefined = undefined,\n TServices extends Service[] = [],\n TLogger extends Logger = Logger,\n> = {\n services: ServiceRecord<TServices>;\n logger: TLogger;\n input: InferComposableStandardSchema<Input>;\n};\n"],"mappings":";;;;;;;;AAkBA,MAAM,iBAAiB,IAAIA;AAE3B,IAAa,kBAAb,MAAa,gBAGX;CACA,AAAQ;CACR,YACEC,iBACQC,gBAAyB,gBACjC;EADQ;AAGR,OAAK,kBAAkB,2BACrB,iBACA,CAAC,MAAM,EAAE,YACV;CACF;CAGD,SACEC,UACgD;AAChD,SAAO,IAAI,gBACT,CAAC,GAAG,UAAU,GAAG,KAAK,eAAgB,GACtC,KAAK;CAER;CAED,OAAyBC,QAA0C;AACjE,SAAO,IAAI,gBAA8B,KAAK,iBAAiB;CAChE;AACF;AAED,IAAa,WAAb,MAAa,iBAaHC,4BAMR;CACA,kBAAkB;CAElB,OAAO,WAAWC,KAAoD;AACpE,SAAO,QACL,OACE,IAAI,oBAAoB,QACxB,IAAI,SAASC,gCAAc,SAC9B;CACF;;;;;;;;CASD,OAAO,SAAqCC,QAAWC,MAAe;AACpE,SAAO,OAAO,aAAa,SAAS,KAAK;CAC1C;;;;;;;;;CAUD,aAAa,YACXD,QACAC,MACiC;AACjC,MAAI;AACF,UAAO,MAAM,2CAAY,QAAQ,KAAK;EACvC,SAAQ,QAAQ;AACf,SAAM,IAAIC,4CAAyB,qBAAqB;EACzD;CACF;;;;;;;;CASD,MAAM,YAAYC,QAA0D;AAC1E,SAAO,SAAS,YACd,KAAK,cACL,OACD;CACF;CAED,YACqBC,IACV,UAAU,KACnBC,OAAsBN,gCAAc,UAC7BO,OACPC,cACAC,WAAsB,CAAE,GACxBC,SAAkB,gBAClBC,kBACAC,SAAoD,CAAE,GACtD;AACA,QAAM,MAAM,QAAQ,UAAU,QAAQ,kBAAkB,aAAa;EAVlD;EACV;EAEF;CAQR;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConstructType } from "./Construct-Bm-PSO2V.cjs";
|
|
2
|
+
import { Function, FunctionHandler } from "./Function-BP58p9Mp.cjs";
|
|
3
|
+
import { BaseFunctionBuilder } from "./BaseFunctionBuilder-5QCHkchp.cjs";
|
|
4
|
+
import { EventPublisher } from "@geekmidas/events";
|
|
5
|
+
import { Logger } from "@geekmidas/logger";
|
|
6
|
+
import { Service } from "@geekmidas/services";
|
|
7
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
8
|
+
import { ComposableStandardSchema } from "@geekmidas/schema";
|
|
9
|
+
|
|
10
|
+
//#region src/functions/FunctionBuilder.d.ts
|
|
11
|
+
declare class FunctionBuilder<TInput extends ComposableStandardSchema, OutSchema extends StandardSchemaV1 | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> extends BaseFunctionBuilder<TInput, OutSchema, TServices, TLogger, TEventPublisher, TEventPublisherServiceName> {
|
|
12
|
+
type: ConstructType;
|
|
13
|
+
constructor(type?: ConstructType);
|
|
14
|
+
timeout(timeout: number): this;
|
|
15
|
+
output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<TInput, T, TServices, TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
16
|
+
input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, OutSchema, TServices, TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
17
|
+
services<T extends Service[]>(services: T): FunctionBuilder<TInput, OutSchema, [...TServices, ...T], TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
18
|
+
logger<T extends Logger>(logger: T): FunctionBuilder<TInput, OutSchema, TServices, T, TEventPublisher, TEventPublisherServiceName>;
|
|
19
|
+
publisher<T extends EventPublisher<any>, TName extends string>(publisher: Service<TName, T>): FunctionBuilder<TInput, OutSchema, TServices, TLogger, T, TName>;
|
|
20
|
+
handle(fn: FunctionHandler<TInput, TServices, TLogger, OutSchema>): Function<TInput, TServices, TLogger, OutSchema, FunctionHandler<TInput, TServices, TLogger, OutSchema>, TEventPublisher, TEventPublisherServiceName>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { FunctionBuilder };
|
|
24
|
+
//# sourceMappingURL=FunctionBuilder-BS1KgxA_.d.cts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConstructType } from "./Construct-DIguIyw4.mjs";
|
|
2
|
+
import { Function, FunctionHandler } from "./Function-BsBxc2wA.mjs";
|
|
3
|
+
import { BaseFunctionBuilder } from "./BaseFunctionBuilder-BFPVGnKi.mjs";
|
|
4
|
+
import { Service } from "@geekmidas/services";
|
|
5
|
+
import { EventPublisher } from "@geekmidas/events";
|
|
6
|
+
import { Logger } from "@geekmidas/logger";
|
|
7
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
8
|
+
import { ComposableStandardSchema } from "@geekmidas/schema";
|
|
9
|
+
|
|
10
|
+
//#region src/functions/FunctionBuilder.d.ts
|
|
11
|
+
declare class FunctionBuilder<TInput extends ComposableStandardSchema, OutSchema extends StandardSchemaV1 | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger, TEventPublisher extends EventPublisher<any> | undefined = undefined, TEventPublisherServiceName extends string = string> extends BaseFunctionBuilder<TInput, OutSchema, TServices, TLogger, TEventPublisher, TEventPublisherServiceName> {
|
|
12
|
+
type: ConstructType;
|
|
13
|
+
constructor(type?: ConstructType);
|
|
14
|
+
timeout(timeout: number): this;
|
|
15
|
+
output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<TInput, T, TServices, TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
16
|
+
input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, OutSchema, TServices, TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
17
|
+
services<T extends Service[]>(services: T): FunctionBuilder<TInput, OutSchema, [...TServices, ...T], TLogger, TEventPublisher, TEventPublisherServiceName>;
|
|
18
|
+
logger<T extends Logger>(logger: T): FunctionBuilder<TInput, OutSchema, TServices, T, TEventPublisher, TEventPublisherServiceName>;
|
|
19
|
+
publisher<T extends EventPublisher<any>, TName extends string>(publisher: Service<TName, T>): FunctionBuilder<TInput, OutSchema, TServices, TLogger, T, TName>;
|
|
20
|
+
handle(fn: FunctionHandler<TInput, TServices, TLogger, OutSchema>): Function<TInput, TServices, TLogger, OutSchema, FunctionHandler<TInput, TServices, TLogger, OutSchema>, TEventPublisher, TEventPublisherServiceName>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { FunctionBuilder };
|
|
24
|
+
//# sourceMappingURL=FunctionBuilder-C-PfPN3r.d.mts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConstructType } from "./Construct-BbKCIPQm.mjs";
|
|
2
|
+
import { Function } from "./Function-C5mW-38v.mjs";
|
|
3
|
+
import { BaseFunctionBuilder } from "./BaseFunctionBuilder-BPE9JBbT.mjs";
|
|
4
|
+
import uniqBy from "lodash.uniqby";
|
|
5
|
+
import { ConsoleLogger } from "@geekmidas/logger/console";
|
|
6
|
+
|
|
7
|
+
//#region src/functions/FunctionBuilder.ts
|
|
8
|
+
const DEFAULT_LOGGER$1 = new ConsoleLogger();
|
|
9
|
+
var FunctionBuilder = class extends BaseFunctionBuilder {
|
|
10
|
+
constructor(type = ConstructType.Function) {
|
|
11
|
+
super(type);
|
|
12
|
+
this.type = type;
|
|
13
|
+
}
|
|
14
|
+
timeout(timeout) {
|
|
15
|
+
this._timeout = timeout;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
output(schema) {
|
|
19
|
+
this.outputSchema = schema;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
input(schema) {
|
|
23
|
+
this.inputSchema = schema;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
services(services) {
|
|
27
|
+
this._services = uniqBy([...this._services, ...services], (s) => s.serviceName);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
logger(logger) {
|
|
31
|
+
this._logger = logger;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
publisher(publisher) {
|
|
35
|
+
this._publisher = publisher;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
handle(fn) {
|
|
39
|
+
const func = new Function(fn, this._timeout, this.type, this.inputSchema, this.outputSchema, this._services, this._logger, this._publisher, this._events);
|
|
40
|
+
this._services = [];
|
|
41
|
+
this._logger = DEFAULT_LOGGER$1;
|
|
42
|
+
this._events = [];
|
|
43
|
+
this._publisher = void 0;
|
|
44
|
+
this.inputSchema = void 0;
|
|
45
|
+
this.outputSchema = void 0;
|
|
46
|
+
this._timeout = void 0;
|
|
47
|
+
return func;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { FunctionBuilder };
|
|
53
|
+
//# sourceMappingURL=FunctionBuilder-CosgPmMl.mjs.map
|