@@ -9,8 +9,9 @@ import { registry } from './constants'
99
1010export const registerConfigDefaults = ( base : Class ) => {
1111 if ( ! registry . has ( base ) ) {
12- const dependencies : Array < Class > = Reflect . getMetadata ( 'design:paramtypes' , base ) || [ ]
12+ const dependencies : Array < Class > = Reflect . getMetadata ( 'design:paramtypes' , base ) ?? [ ]
1313
14+ // eslint-disable-next-line functional/immutable-data
1415 registry . set ( base , {
1516 base,
1617 dependencies,
@@ -28,6 +29,7 @@ export const registerConfigTransformOptions = (base: Class, transformOptions?: C
2829 throw new Error ( `Failed to find registered config. Make sure to decorate a class with @Config()!` )
2930 }
3031
32+ // eslint-disable-next-line functional/immutable-data
3133 registry . set ( base , {
3234 ...current ,
3335 transformOptions
@@ -41,10 +43,11 @@ export const registerConfigTransformTranslations = (base: Class, propertyName: s
4143 throw new Error ( `Failed to find registered config. Make sure to decorate a class with @Config()!` )
4244 }
4345
46+ // eslint-disable-next-line functional/immutable-data
4447 registry . set ( base , {
4548 ...current ,
4649 propertyNameTranslations : {
47- ...current ? .propertyNameTranslations ,
50+ ...current . propertyNameTranslations ,
4851 [ propertyName ] : environmentPropertyName
4952 }
5053 } )
@@ -57,7 +60,7 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
5760 throw new Error ( `Failed to find registered config. Make sure to decorate a class with @Config()!` )
5861 }
5962
60- if ( registeredDependency . instance ) {
63+ if ( isNotNil ( registeredDependency . instance ) ) {
6164 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
6265 return registeredDependency . instance
6366 }
@@ -80,27 +83,26 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
8083
8184 const storage = getMetadataStorage ( )
8285 const metadatas = storage . getTargetValidationMetadatas ( base , base . name , false , false )
83- const transformedProperties = metadatas . reduce (
84- ( acc , { propertyName, target } ) => {
85- if ( acc [ propertyName ] ) {
86- return acc
87- }
88-
89- const prototype : object = typeof target === 'function' ? target . prototype : { }
90- const environmentPropertyName = registeredDependency . propertyNameTranslations [ propertyName ]
91-
92- const key = environmentPropertyName || propertyName
93- const value = environmentVariables [ key ] || process . env [ key ]
94- const type = Reflect . getMetadata ( 'design:type' , prototype , propertyName )
95-
96- return {
97- ...acc ,
98- [ propertyName ] : isNotNil ( value ) ? toValueByType ( type , value ) : value
99- }
100- } ,
101- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102- { } as Record < string , any >
103- )
86+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87+ const transformedProperties = metadatas . reduce < Record < string , any > > ( ( acc , { propertyName, target } ) => {
88+ if ( isNotNil ( acc [ propertyName ] ) ) {
89+ return acc
90+ }
91+
92+ const prototype : object = typeof target === 'function' ? target . prototype : { }
93+ const environmentPropertyName = registeredDependency . propertyNameTranslations [ propertyName ]
94+
95+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
96+ const key = environmentPropertyName || propertyName
97+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
98+ const value = environmentVariables [ key ] || process . env [ key ]
99+ const type = Reflect . getMetadata ( 'design:type' , prototype , propertyName )
100+
101+ return {
102+ ...acc ,
103+ [ propertyName ] : isNotNil ( value ) ? toValueByType ( type , value ) : value
104+ }
105+ } , { } )
104106
105107 /**
106108 * Make the instance methods, auto-bindable to "this" reference so we can destruct the
@@ -114,18 +116,15 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
114116
115117 const descriptors = Object . getOwnPropertyDescriptors ( base . prototype )
116118 const descriptorNames = Object . keys ( descriptors ) . filter ( name => name !== 'constructor' )
117- const unreferencedMethods = descriptorNames . reduce (
118- ( result , name ) => {
119- const descriptor = descriptors [ name ]
120-
121- return {
122- ...result ,
123- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return, functional/functional-parameters
124- [ name ] : ( ...args : Array < any > ) => descriptor . value . apply ( instance , args )
125- }
126- } ,
127- { } as Record < string , ( ) => void >
128- )
119+ const unreferencedMethods = descriptorNames . reduce < Record < string , ( ) => void > > ( ( result , name ) => {
120+ const descriptor = descriptors [ name ]
121+
122+ return {
123+ ...result ,
124+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return, functional/functional-parameters
125+ [ name ] : ( ...args : Array < any > ) => descriptor . value . apply ( instance , args )
126+ }
127+ } , { } )
129128
130129 /**
131130 * Due to missing option for passing constructor arguments, we are creating
@@ -137,7 +136,7 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
137136 static readonly name = base . name
138137
139138 // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, functional/functional-parameters
140- constructor ( ...unusedArgs : Array < any > ) {
139+ constructor ( ...args : Array < any > ) {
141140 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
142141 super ( ...resolvedDependencies )
143142 }
@@ -161,7 +160,7 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
161160 }
162161 } )
163162
164- if ( validationErrors . length ) {
163+ if ( validationErrors . length > 0 ) {
165164 throw new ValidationException ( base . name , validationErrors )
166165 }
167166
@@ -171,6 +170,7 @@ export const getConfigInstance = <T extends Class>(base: T, transformOptions?: T
171170 instance
172171 }
173172
173+ // eslint-disable-next-line functional/immutable-data
174174 registry . set ( base , config )
175175
176176 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
0 commit comments