@@ -9,26 +9,29 @@ OF ANY KIND, either express or implied. See the License for the specific languag
99governing permissions and limitations under the License.
1010*/
1111
12- const cleanText = require ( './cleanText' ) ;
12+ const cleanTextFn = require ( './cleanText' ) ;
1313
1414const enhanceErrorMessage = ( dataElementName , e ) => {
1515 e . message = `Failed to execute module for data element "${ dataElementName } ". ${ e . message } ` ;
1616} ;
1717
1818module . exports =
19- ( moduleProvider , getDataElementDefinition ) => ( name , context ) => {
19+ ( moduleProvider , getDataElementDefinition ) => ( dataElementName , context ) => {
2020 const { dataElementCallStack = [ ] , arcAndUtils } = context ;
2121 const { utils } = arcAndUtils ;
2222
23- const dataDef = getDataElementDefinition ( name ) ;
23+ const dataDef = getDataElementDefinition ( dataElementName ) ;
24+
2425 if ( ! dataDef ) {
2526 return Promise . reject (
26- new Error ( `Data element definition for "${ name } " was not found.` )
27+ new Error (
28+ `Data element definition for "${ dataElementName } " was not found.`
29+ )
2730 ) ;
2831 }
2932
30- if ( dataElementCallStack . includes ( name ) ) {
31- dataElementCallStack . push ( name ) ;
33+ if ( dataElementCallStack . includes ( dataElementName ) ) {
34+ dataElementCallStack . push ( dataElementName ) ;
3235
3336 return Promise . reject (
3437 new Error (
@@ -38,35 +41,48 @@ module.exports =
3841 )
3942 ) ;
4043 }
41- dataElementCallStack . push ( name ) ;
44+ dataElementCallStack . push ( dataElementName ) ;
4245
43- const moduleExports = moduleProvider . getModuleExports ( dataDef . modulePath ) ;
46+ const {
47+ modulePath,
48+ getSettings,
49+ id,
50+ name,
51+ defaultValue,
52+ cleanText,
53+ forceLowerCase
54+ } = dataDef ;
4455
45- const valuePromise = dataDef . getSettings ( context ) . then ( ( settings ) => {
56+ const moduleExports = moduleProvider . getModuleExports ( modulePath ) ;
57+ const valuePromise = getSettings ( context ) . then ( ( settings ) => {
4658 try {
4759 return moduleExports ( {
4860 ...arcAndUtils ,
49- utils : { ...utils , getSettings : ( ) => settings }
61+ utils : {
62+ ...utils ,
63+ getSettings : ( ) => settings ,
64+ getComponent : ( ) => ( { id, name } )
65+ }
5066 } ) ;
5167 } catch ( e ) {
52- enhanceErrorMessage ( name , e ) ;
68+ enhanceErrorMessage ( dataElementName , e ) ;
5369 throw e ;
5470 }
5571 } ) ;
5672
5773 return valuePromise . then ( ( resolvedValue ) => {
5874 let value = resolvedValue ;
5975
60- if ( value == null && dataDef . defaultValue != null ) {
61- value = dataDef . defaultValue ;
76+ if ( value == null && defaultValue != null ) {
77+ value = defaultValue ;
6278 }
6379
6480 if ( typeof value === 'string' ) {
65- if ( dataDef . cleanText ) {
66- value = cleanText ( value ) ;
81+ if ( cleanText ) {
82+ value = cleanTextFn ( value ) ;
6783 }
6884
69- if ( dataDef . forceLowerCase ) {
85+ if ( forceLowerCase ) {
7086 value = value . toLowerCase ( ) ;
7187 }
7288 }
0 commit comments