1+ import { isNumberLike , parseNumber } from '@douglasneuroinformatics/libjs' ;
12import { $BooleanString } from '@opendatacapture/schemas/core' ;
23import { z } from 'zod' ;
34
@@ -10,18 +11,27 @@ const $OptionalURL = z.preprocess(
1011 . transform ( ( arg ) => ( arg ? new URL ( arg ) : undefined ) )
1112) ;
1213
14+ const $ParsedNumber = < TSchema extends z . ZodTypeAny > ( schema : TSchema ) => {
15+ return z . preprocess ( ( arg ) => {
16+ if ( ! isNumberLike ( arg ) ) {
17+ return undefined ;
18+ }
19+ return parseNumber ( arg ) ;
20+ } , schema ) ;
21+ } ;
22+
1323export const $Configuration = z
1424 . object ( {
15- API_DEV_SERVER_PORT : z . coerce . number ( ) . positive ( ) . int ( ) . optional ( ) ,
16- API_PROD_SERVER_PORT : z . coerce . number ( ) . positive ( ) . int ( ) . default ( 80 ) ,
17- API_RESPONSE_DELAY : z . coerce . number ( ) . positive ( ) . int ( ) . optional ( ) ,
25+ API_DEV_SERVER_PORT : $ParsedNumber ( z . number ( ) . positive ( ) . int ( ) . optional ( ) ) ,
26+ API_PROD_SERVER_PORT : $ParsedNumber ( z . number ( ) . positive ( ) . int ( ) . default ( 80 ) ) ,
27+ API_RESPONSE_DELAY : $ParsedNumber ( z . number ( ) . positive ( ) . int ( ) . optional ( ) ) ,
1828 DANGEROUSLY_DISABLE_PBKDF2_ITERATION : $BooleanString . default ( false ) ,
1929 DEBUG : $BooleanString ,
2030 GATEWAY_API_KEY : z . string ( ) . min ( 32 ) ,
21- GATEWAY_DEV_SERVER_PORT : z . coerce . number ( ) . positive ( ) . int ( ) . optional ( ) ,
31+ GATEWAY_DEV_SERVER_PORT : $ParsedNumber ( z . number ( ) . positive ( ) . int ( ) . optional ( ) ) ,
2232 GATEWAY_ENABLED : $BooleanString ,
2333 GATEWAY_INTERNAL_NETWORK_URL : $OptionalURL ,
24- GATEWAY_REFRESH_INTERVAL : z . coerce . number ( ) . positive ( ) . int ( ) ,
34+ GATEWAY_REFRESH_INTERVAL : $ParsedNumber ( z . number ( ) . positive ( ) . int ( ) ) ,
2535 GATEWAY_SITE_ADDRESS : $OptionalURL ,
2636 MONGO_DIRECT_CONNECTION : z . string ( ) . optional ( ) ,
2737 MONGO_REPLICA_SET : z . string ( ) . optional ( ) ,
0 commit comments