@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,192 @@
|
|
|
1
|
+
import type { Logger } from '@geekmidas/logger';
|
|
2
|
+
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
3
|
+
import type { ComposableStandardSchema } from '@geekmidas/schema';
|
|
4
|
+
import type { Service } from '@geekmidas/services';
|
|
5
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import uniqBy from 'lodash.uniqby';
|
|
7
|
+
import { ConstructType } from '../Construct';
|
|
8
|
+
import { FunctionBuilder, type FunctionHandler } from '../functions';
|
|
9
|
+
import { Cron, type ScheduleExpression } from './Cron';
|
|
10
|
+
|
|
11
|
+
import type { EventPublisher } from '@geekmidas/events';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
14
|
+
|
|
15
|
+
export class CronBuilder<
|
|
16
|
+
TInput extends ComposableStandardSchema,
|
|
17
|
+
TServices extends Service[],
|
|
18
|
+
TLogger extends Logger = Logger,
|
|
19
|
+
OutSchema extends StandardSchemaV1 | undefined = undefined,
|
|
20
|
+
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
21
|
+
TEventPublisherServiceName extends string = string,
|
|
22
|
+
> extends FunctionBuilder<
|
|
23
|
+
TInput,
|
|
24
|
+
OutSchema,
|
|
25
|
+
TServices,
|
|
26
|
+
TLogger,
|
|
27
|
+
TEventPublisher,
|
|
28
|
+
TEventPublisherServiceName
|
|
29
|
+
> {
|
|
30
|
+
private _schedule?: ScheduleExpression;
|
|
31
|
+
constructor() {
|
|
32
|
+
super(ConstructType.Cron);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
schedule(
|
|
36
|
+
_expression: ScheduleExpression,
|
|
37
|
+
): CronBuilder<
|
|
38
|
+
TInput,
|
|
39
|
+
TServices,
|
|
40
|
+
TLogger,
|
|
41
|
+
OutSchema,
|
|
42
|
+
TEventPublisher,
|
|
43
|
+
TEventPublisherServiceName
|
|
44
|
+
> {
|
|
45
|
+
this._schedule = _expression;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
input<T extends ComposableStandardSchema>(
|
|
50
|
+
schema: T,
|
|
51
|
+
): CronBuilder<
|
|
52
|
+
T,
|
|
53
|
+
TServices,
|
|
54
|
+
TLogger,
|
|
55
|
+
OutSchema,
|
|
56
|
+
TEventPublisher,
|
|
57
|
+
TEventPublisherServiceName
|
|
58
|
+
> {
|
|
59
|
+
this.inputSchema = schema as unknown as TInput;
|
|
60
|
+
|
|
61
|
+
return this as unknown as CronBuilder<
|
|
62
|
+
T,
|
|
63
|
+
TServices,
|
|
64
|
+
TLogger,
|
|
65
|
+
OutSchema,
|
|
66
|
+
TEventPublisher,
|
|
67
|
+
TEventPublisherServiceName
|
|
68
|
+
>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
output<T extends StandardSchemaV1>(
|
|
72
|
+
schema: T,
|
|
73
|
+
): CronBuilder<
|
|
74
|
+
TInput,
|
|
75
|
+
TServices,
|
|
76
|
+
TLogger,
|
|
77
|
+
T,
|
|
78
|
+
TEventPublisher,
|
|
79
|
+
TEventPublisherServiceName
|
|
80
|
+
> {
|
|
81
|
+
this.outputSchema = schema as unknown as OutSchema;
|
|
82
|
+
|
|
83
|
+
return this as unknown as CronBuilder<
|
|
84
|
+
TInput,
|
|
85
|
+
TServices,
|
|
86
|
+
TLogger,
|
|
87
|
+
T,
|
|
88
|
+
TEventPublisher,
|
|
89
|
+
TEventPublisherServiceName
|
|
90
|
+
>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
services<T extends Service[]>(
|
|
94
|
+
services: T,
|
|
95
|
+
): CronBuilder<
|
|
96
|
+
TInput,
|
|
97
|
+
[...TServices, ...T],
|
|
98
|
+
TLogger,
|
|
99
|
+
OutSchema,
|
|
100
|
+
TEventPublisher,
|
|
101
|
+
TEventPublisherServiceName
|
|
102
|
+
> {
|
|
103
|
+
this._services = uniqBy(
|
|
104
|
+
[...this._services, ...services],
|
|
105
|
+
(s) => s.serviceName,
|
|
106
|
+
) as TServices;
|
|
107
|
+
|
|
108
|
+
return this as unknown as CronBuilder<
|
|
109
|
+
TInput,
|
|
110
|
+
[...TServices, ...T],
|
|
111
|
+
TLogger,
|
|
112
|
+
OutSchema,
|
|
113
|
+
TEventPublisher,
|
|
114
|
+
TEventPublisherServiceName
|
|
115
|
+
>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
logger<T extends Logger>(
|
|
119
|
+
logger: T,
|
|
120
|
+
): CronBuilder<
|
|
121
|
+
TInput,
|
|
122
|
+
TServices,
|
|
123
|
+
T,
|
|
124
|
+
OutSchema,
|
|
125
|
+
TEventPublisher,
|
|
126
|
+
TEventPublisherServiceName
|
|
127
|
+
> {
|
|
128
|
+
this._logger = logger as unknown as TLogger;
|
|
129
|
+
|
|
130
|
+
return this as unknown as CronBuilder<
|
|
131
|
+
TInput,
|
|
132
|
+
TServices,
|
|
133
|
+
T,
|
|
134
|
+
OutSchema,
|
|
135
|
+
TEventPublisher,
|
|
136
|
+
TEventPublisherServiceName
|
|
137
|
+
>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
publisher<T extends EventPublisher<any>, TName extends string>(
|
|
141
|
+
publisher: Service<TName, T>,
|
|
142
|
+
): CronBuilder<TInput, TServices, TLogger, OutSchema, T, TName> {
|
|
143
|
+
this._publisher = publisher as unknown as Service<
|
|
144
|
+
TEventPublisherServiceName,
|
|
145
|
+
TEventPublisher
|
|
146
|
+
>;
|
|
147
|
+
|
|
148
|
+
return this as unknown as CronBuilder<
|
|
149
|
+
TInput,
|
|
150
|
+
TServices,
|
|
151
|
+
TLogger,
|
|
152
|
+
OutSchema,
|
|
153
|
+
T,
|
|
154
|
+
TName
|
|
155
|
+
>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
handle(
|
|
159
|
+
fn: FunctionHandler<TInput, TServices, TLogger, OutSchema>,
|
|
160
|
+
): Cron<
|
|
161
|
+
TInput,
|
|
162
|
+
TServices,
|
|
163
|
+
TLogger,
|
|
164
|
+
OutSchema,
|
|
165
|
+
TEventPublisher,
|
|
166
|
+
TEventPublisherServiceName
|
|
167
|
+
> {
|
|
168
|
+
const cron = new Cron(
|
|
169
|
+
fn,
|
|
170
|
+
this._timeout,
|
|
171
|
+
this._schedule,
|
|
172
|
+
this.inputSchema,
|
|
173
|
+
this.outputSchema,
|
|
174
|
+
this._services,
|
|
175
|
+
this._logger,
|
|
176
|
+
this._publisher,
|
|
177
|
+
this._events,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Reset builder state after creating the cron to prevent pollution
|
|
181
|
+
this._services = [] as Service[] as TServices;
|
|
182
|
+
this._logger = DEFAULT_LOGGER;
|
|
183
|
+
this._events = [];
|
|
184
|
+
this._publisher = undefined;
|
|
185
|
+
this._schedule = undefined;
|
|
186
|
+
this.inputSchema = undefined;
|
|
187
|
+
this.outputSchema = undefined;
|
|
188
|
+
this._timeout = undefined;
|
|
189
|
+
|
|
190
|
+
return cron;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
2
|
+
import type { Service } from '@geekmidas/services';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ConstructType } from '../../Construct';
|
|
6
|
+
import { Cron, type CronExpression, type RateExpression } from '../Cron';
|
|
7
|
+
import { CronBuilder } from '../CronBuilder';
|
|
8
|
+
|
|
9
|
+
// Mock service for testing
|
|
10
|
+
class MockService implements Service<'MockService', MockService> {
|
|
11
|
+
serviceName = 'MockService' as const;
|
|
12
|
+
|
|
13
|
+
async register() {
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getValue() {
|
|
18
|
+
return 'mock-value';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('Cron', () => {
|
|
23
|
+
describe('Cron class', () => {
|
|
24
|
+
it('should create a Cron instance with basic handler', () => {
|
|
25
|
+
const handler = vi.fn().mockResolvedValue({ success: true });
|
|
26
|
+
const cron = new Cron(handler);
|
|
27
|
+
|
|
28
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
29
|
+
expect(cron.type).toBe(ConstructType.Cron);
|
|
30
|
+
expect(cron.timeout).toBe(30000); // Default timeout
|
|
31
|
+
// The handler is stored in the protected fn property
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should create a Cron instance with timeout', () => {
|
|
35
|
+
const handler = vi.fn().mockResolvedValue({ data: 'test' });
|
|
36
|
+
const timeout = 60000;
|
|
37
|
+
const cron = new Cron(handler, timeout);
|
|
38
|
+
|
|
39
|
+
expect(cron.timeout).toBe(timeout);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should create a Cron instance with schedule expression', () => {
|
|
43
|
+
const handler = vi.fn();
|
|
44
|
+
const schedule: CronExpression = 'cron(0 12 * * MON)';
|
|
45
|
+
const cron = new Cron(handler, undefined, schedule);
|
|
46
|
+
|
|
47
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
48
|
+
expect(cron.type).toBe(ConstructType.Cron);
|
|
49
|
+
// Schedule is protected, so we can't directly test it, but it should be set
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should create a Cron instance with input schema', () => {
|
|
53
|
+
const inputSchema = z.object({
|
|
54
|
+
id: z.string(),
|
|
55
|
+
count: z.number(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const handler = vi.fn().mockImplementation(async ({ input }) => {
|
|
59
|
+
return { processed: input.id };
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const cron = new Cron(handler, undefined, undefined, inputSchema);
|
|
63
|
+
|
|
64
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
65
|
+
expect(cron.input).toBe(inputSchema);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should create a Cron instance with output schema', () => {
|
|
69
|
+
const outputSchema = z.object({
|
|
70
|
+
result: z.string(),
|
|
71
|
+
timestamp: z.number(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const handler = vi.fn().mockResolvedValue({
|
|
75
|
+
result: 'success',
|
|
76
|
+
timestamp: Date.now(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const cron = new Cron(
|
|
80
|
+
handler,
|
|
81
|
+
undefined,
|
|
82
|
+
undefined,
|
|
83
|
+
undefined,
|
|
84
|
+
outputSchema,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
88
|
+
expect(cron.outputSchema).toBe(outputSchema);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should create a Cron instance with services', () => {
|
|
92
|
+
const mockService = new MockService();
|
|
93
|
+
const services = [mockService];
|
|
94
|
+
|
|
95
|
+
const handler = vi.fn().mockImplementation(async ({ services }) => {
|
|
96
|
+
return { value: services.MockService.getValue() };
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const cron = new Cron(
|
|
100
|
+
handler,
|
|
101
|
+
undefined,
|
|
102
|
+
undefined,
|
|
103
|
+
undefined,
|
|
104
|
+
undefined,
|
|
105
|
+
services,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
109
|
+
expect(cron.services).toEqual(services);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should create a Cron instance with custom logger', () => {
|
|
113
|
+
const customLogger = new ConsoleLogger();
|
|
114
|
+
|
|
115
|
+
const handler = vi.fn().mockImplementation(async ({ logger }) => {
|
|
116
|
+
logger.info('Cron executed');
|
|
117
|
+
return { logged: true };
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const cron = new Cron(
|
|
121
|
+
handler,
|
|
122
|
+
undefined,
|
|
123
|
+
undefined,
|
|
124
|
+
undefined,
|
|
125
|
+
undefined,
|
|
126
|
+
[],
|
|
127
|
+
customLogger,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
131
|
+
expect(cron.logger).toBe(customLogger);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should create a Cron with all parameters', () => {
|
|
135
|
+
const inputSchema = z.object({ name: z.string() });
|
|
136
|
+
const outputSchema = z.object({ greeting: z.string() });
|
|
137
|
+
const schedule: RateExpression = 'rate(5 minutes)';
|
|
138
|
+
const timeout = 60000;
|
|
139
|
+
const service = new MockService();
|
|
140
|
+
const logger = new ConsoleLogger();
|
|
141
|
+
|
|
142
|
+
const handler = vi
|
|
143
|
+
.fn()
|
|
144
|
+
.mockImplementation(async ({ input, services }) => {
|
|
145
|
+
return {
|
|
146
|
+
greeting: `Hello ${input.name} from ${services.MockService.getValue()}`,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const cron = new Cron(
|
|
151
|
+
handler,
|
|
152
|
+
timeout,
|
|
153
|
+
schedule,
|
|
154
|
+
inputSchema,
|
|
155
|
+
outputSchema,
|
|
156
|
+
[service],
|
|
157
|
+
logger,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
161
|
+
expect(cron.type).toBe(ConstructType.Cron);
|
|
162
|
+
expect(cron.timeout).toBe(timeout);
|
|
163
|
+
expect(cron.input).toBe(inputSchema);
|
|
164
|
+
expect(cron.outputSchema).toBe(outputSchema);
|
|
165
|
+
expect(cron.services).toEqual([service]);
|
|
166
|
+
expect(cron.logger).toBe(logger);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('Cron.isCron', () => {
|
|
171
|
+
it('should return true for Cron instances', () => {
|
|
172
|
+
const cron = new Cron(vi.fn());
|
|
173
|
+
expect(Cron.isCron(cron)).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should return false for non-Cron objects', () => {
|
|
177
|
+
expect(Cron.isCron({})).toBe(false);
|
|
178
|
+
expect(Cron.isCron(null)).toBeFalsy();
|
|
179
|
+
expect(Cron.isCron(undefined)).toBeFalsy();
|
|
180
|
+
expect(Cron.isCron('string')).toBe(false);
|
|
181
|
+
expect(Cron.isCron(123)).toBe(false);
|
|
182
|
+
expect(Cron.isCron([])).toBe(false);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should return false for objects with similar structure', () => {
|
|
186
|
+
const fakeCron = {
|
|
187
|
+
__IS_FUNCTION__: true,
|
|
188
|
+
type: 'SomethingElse',
|
|
189
|
+
};
|
|
190
|
+
expect(Cron.isCron(fakeCron)).toBe(false);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should return false for objects with __IS_FUNCTION__ but wrong type', () => {
|
|
194
|
+
const fakeFunction = {
|
|
195
|
+
__IS_FUNCTION__: true,
|
|
196
|
+
type: ConstructType.Function,
|
|
197
|
+
};
|
|
198
|
+
expect(Cron.isCron(fakeFunction)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('CronBuilder', () => {
|
|
203
|
+
it('should create a CronBuilder instance', () => {
|
|
204
|
+
const builder = new CronBuilder();
|
|
205
|
+
expect(builder).toBeInstanceOf(CronBuilder);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should set schedule with schedule() method', () => {
|
|
209
|
+
const builder = new CronBuilder();
|
|
210
|
+
const schedule: CronExpression = 'cron(0 0 * * SUN)';
|
|
211
|
+
|
|
212
|
+
const result = builder.schedule(schedule);
|
|
213
|
+
expect(result).toBe(builder); // Should return self for chaining
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should build Cron with handle() method', () => {
|
|
217
|
+
const builder = new CronBuilder();
|
|
218
|
+
const handler = vi.fn().mockResolvedValue({ done: true });
|
|
219
|
+
|
|
220
|
+
const cron = builder.handle(handler);
|
|
221
|
+
|
|
222
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
223
|
+
expect(cron.type).toBe(ConstructType.Cron);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should build Cron with full builder chain', () => {
|
|
227
|
+
const inputSchema = z.object({ task: z.string() });
|
|
228
|
+
const outputSchema = z.object({ completed: z.boolean() });
|
|
229
|
+
const schedule: RateExpression = 'rate(1 hour)';
|
|
230
|
+
const service = new MockService();
|
|
231
|
+
const logger = new ConsoleLogger();
|
|
232
|
+
|
|
233
|
+
const handler = vi.fn().mockImplementation(async ({ input }) => {
|
|
234
|
+
return { completed: input.task === 'test' };
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const cron = new CronBuilder()
|
|
238
|
+
.input(inputSchema)
|
|
239
|
+
.output(outputSchema)
|
|
240
|
+
.services([service])
|
|
241
|
+
.logger(logger)
|
|
242
|
+
.timeout(45000)
|
|
243
|
+
.schedule(schedule)
|
|
244
|
+
.handle(handler);
|
|
245
|
+
|
|
246
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
247
|
+
expect(cron.type).toBe(ConstructType.Cron);
|
|
248
|
+
expect(cron.timeout).toBe(45000);
|
|
249
|
+
expect(cron.input).toBe(inputSchema);
|
|
250
|
+
expect(cron.outputSchema).toBe(outputSchema);
|
|
251
|
+
expect(cron.services).toEqual([service]);
|
|
252
|
+
expect(cron.logger).toBe(logger);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should support method chaining in any order', () => {
|
|
256
|
+
const builder = new CronBuilder();
|
|
257
|
+
const schedule: CronExpression = 'cron(30 2 * * TUE)';
|
|
258
|
+
|
|
259
|
+
const chained = builder
|
|
260
|
+
.timeout(30000)
|
|
261
|
+
.schedule(schedule)
|
|
262
|
+
.input(z.object({ data: z.string() }));
|
|
263
|
+
|
|
264
|
+
expect(chained).toBe(builder);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('Schedule Expression Types', () => {
|
|
269
|
+
it('should accept valid rate expressions', () => {
|
|
270
|
+
const validRates: RateExpression[] = [
|
|
271
|
+
'rate(5 minutes)',
|
|
272
|
+
'rate(1 hour)',
|
|
273
|
+
'rate(7 days)',
|
|
274
|
+
'rate(30 seconds)',
|
|
275
|
+
'rate(2 weeks)',
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
validRates.forEach((rate) => {
|
|
279
|
+
const builder = new CronBuilder();
|
|
280
|
+
expect(() => builder.schedule(rate)).not.toThrow();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('should accept valid cron expressions', () => {
|
|
285
|
+
const validCrons: CronExpression[] = [
|
|
286
|
+
'cron(0 12 * * MON)',
|
|
287
|
+
'cron(15 10 * * FRI)',
|
|
288
|
+
'cron(0 0 1 JAN SUN)',
|
|
289
|
+
'cron(*/5 * * * *)',
|
|
290
|
+
'cron(0 0-23/2 * * *)',
|
|
291
|
+
'cron(30 4 1,15 * *)',
|
|
292
|
+
'cron(0 12 * DEC MON)',
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
validCrons.forEach((cron) => {
|
|
296
|
+
const builder = new CronBuilder();
|
|
297
|
+
expect(() => builder.schedule(cron)).not.toThrow();
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should work with complex cron patterns', () => {
|
|
302
|
+
const complexPatterns: CronExpression[] = [
|
|
303
|
+
'cron(*/15 * * * *)', // Every 15 minutes
|
|
304
|
+
'cron(0 */4 * * *)', // Every 4 hours
|
|
305
|
+
'cron(0 9-17 * * MON-FRI)', // Every hour 9-5 on weekdays
|
|
306
|
+
'cron(0 0 1-7 * SUN)', // First Sunday of month
|
|
307
|
+
'cron(*/30 8-18 * * *)', // Every 30 min during business hours
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
complexPatterns.forEach((pattern) => {
|
|
311
|
+
const builder = new CronBuilder();
|
|
312
|
+
expect(() => builder.schedule(pattern)).not.toThrow();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should handle all month names', () => {
|
|
317
|
+
const months: CronExpression[] = [
|
|
318
|
+
'cron(0 0 1 JAN *)',
|
|
319
|
+
'cron(0 0 1 FEB *)',
|
|
320
|
+
'cron(0 0 1 MAR *)',
|
|
321
|
+
'cron(0 0 1 APR *)',
|
|
322
|
+
'cron(0 0 1 MAY *)',
|
|
323
|
+
'cron(0 0 1 JUN *)',
|
|
324
|
+
'cron(0 0 1 JUL *)',
|
|
325
|
+
'cron(0 0 1 AUG *)',
|
|
326
|
+
'cron(0 0 1 SEP *)',
|
|
327
|
+
'cron(0 0 1 OCT *)',
|
|
328
|
+
'cron(0 0 1 NOV *)',
|
|
329
|
+
'cron(0 0 1 DEC *)',
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
months.forEach((expression) => {
|
|
333
|
+
const builder = new CronBuilder();
|
|
334
|
+
expect(() => builder.schedule(expression)).not.toThrow();
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('should handle all weekday names', () => {
|
|
339
|
+
const weekdays: CronExpression[] = [
|
|
340
|
+
'cron(0 0 * * SUN)',
|
|
341
|
+
'cron(0 0 * * MON)',
|
|
342
|
+
'cron(0 0 * * TUE)',
|
|
343
|
+
'cron(0 0 * * WED)',
|
|
344
|
+
'cron(0 0 * * THU)',
|
|
345
|
+
'cron(0 0 * * FRI)',
|
|
346
|
+
'cron(0 0 * * SAT)',
|
|
347
|
+
];
|
|
348
|
+
|
|
349
|
+
weekdays.forEach((expression) => {
|
|
350
|
+
const builder = new CronBuilder();
|
|
351
|
+
expect(() => builder.schedule(expression)).not.toThrow();
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('Cron configuration', () => {
|
|
357
|
+
it('should store handler with error handling capability', () => {
|
|
358
|
+
const error = new Error('Cron execution failed');
|
|
359
|
+
const handler = vi.fn().mockRejectedValue(error);
|
|
360
|
+
|
|
361
|
+
const cron = new Cron(handler);
|
|
362
|
+
|
|
363
|
+
expect(cron).toBeInstanceOf(Cron);
|
|
364
|
+
// Handler is stored but not directly accessible (protected)
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('should store input schema for validation', () => {
|
|
368
|
+
const inputSchema = z.object({
|
|
369
|
+
id: z.string().uuid(),
|
|
370
|
+
amount: z.number().positive(),
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const handler = vi.fn();
|
|
374
|
+
const cron = new Cron(handler, undefined, undefined, inputSchema);
|
|
375
|
+
|
|
376
|
+
expect(cron.input).toBe(inputSchema);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('should store output schema for validation', () => {
|
|
380
|
+
const outputSchema = z.object({
|
|
381
|
+
status: z.enum(['success', 'failure']),
|
|
382
|
+
count: z.number().int(),
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const handler = vi.fn().mockResolvedValue({
|
|
386
|
+
status: 'invalid',
|
|
387
|
+
count: 3.14,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const cron = new Cron(
|
|
391
|
+
handler,
|
|
392
|
+
undefined,
|
|
393
|
+
undefined,
|
|
394
|
+
undefined,
|
|
395
|
+
outputSchema,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
expect(cron.outputSchema).toBe(outputSchema);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should work with multiple services', () => {
|
|
402
|
+
class ServiceA implements Service<'ServiceA', ServiceA> {
|
|
403
|
+
serviceName = 'ServiceA' as const;
|
|
404
|
+
async register() {
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
getA() {
|
|
408
|
+
return 'A';
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
class ServiceB implements Service<'ServiceB', ServiceB> {
|
|
413
|
+
serviceName = 'ServiceB' as const;
|
|
414
|
+
async register() {
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
getB() {
|
|
418
|
+
return 'B';
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const services = [new ServiceA(), new ServiceB()];
|
|
423
|
+
|
|
424
|
+
const handler = vi.fn().mockImplementation(async ({ services }) => {
|
|
425
|
+
return {
|
|
426
|
+
a: services.ServiceA.getA(),
|
|
427
|
+
b: services.ServiceB.getB(),
|
|
428
|
+
};
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const cron = new Cron(
|
|
432
|
+
handler,
|
|
433
|
+
undefined,
|
|
434
|
+
undefined,
|
|
435
|
+
undefined,
|
|
436
|
+
undefined,
|
|
437
|
+
services,
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
expect(cron.services).toEqual(services);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('should maintain separate instances with different configurations', () => {
|
|
444
|
+
const handler1 = vi.fn().mockResolvedValue({ cron: 1 });
|
|
445
|
+
const handler2 = vi.fn().mockResolvedValue({ cron: 2 });
|
|
446
|
+
|
|
447
|
+
const cron1 = new CronBuilder()
|
|
448
|
+
.timeout(1000)
|
|
449
|
+
.schedule('rate(5 minutes)')
|
|
450
|
+
.handle(handler1);
|
|
451
|
+
|
|
452
|
+
const cron2 = new CronBuilder()
|
|
453
|
+
.timeout(2000)
|
|
454
|
+
.schedule('cron(0 0 * * *)')
|
|
455
|
+
.handle(handler2);
|
|
456
|
+
|
|
457
|
+
expect(cron1).toBeInstanceOf(Cron);
|
|
458
|
+
expect(cron2).toBeInstanceOf(Cron);
|
|
459
|
+
expect(cron1.timeout).toBe(1000);
|
|
460
|
+
expect(cron2.timeout).toBe(2000);
|
|
461
|
+
expect(cron1).not.toBe(cron2);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
});
|