@@ -68,6 +68,7 @@ interface ConnectionCallbacks {
6868
6969interface ConnectionConfigFiles {
7070 settings : ConfigFile < RemoteConfigFile > ;
71+ [ key : string ] : ConfigFile < any > ;
7172}
7273
7374export default class IBMi {
@@ -157,8 +158,37 @@ export default class IBMi {
157158 this . disconnectedCallback = callback ;
158159 }
159160
161+ /**
162+ * getConfigFile can return pre-defined configuration files,
163+ * but can lazy load new configuration files as well.
164+ *
165+ * This does not load the configuration file from the server,
166+ * it only returns a ConfigFile instance. You should check the
167+ * state of the ConfigFile instance to see if it has been loaded,
168+ * and if not, call `loadFromServer()` on it.
169+ */
160170 getConfigFile < T > ( id : keyof ConnectionConfigFiles ) {
161- return this . configFiles [ id ] as ConfigFile < T > ;
171+ if ( ! this . configFiles [ id ] ) {
172+ this . configFiles [ id ] = new ConfigFile < T > ( this , id as string , { } as T ) ;
173+ }
174+
175+ const configFile = this . configFiles [ id ] as ConfigFile < T > ;
176+
177+ return configFile ;
178+ }
179+
180+ async loadRemoteConfigs ( ) {
181+ for ( const configFile in this . configFiles ) {
182+ const currentConfig = this . configFiles [ configFile as keyof ConnectionConfigFiles ] ;
183+
184+ currentConfig . reset ( ) ;
185+
186+ try {
187+ await currentConfig . loadFromServer ( ) ;
188+ } catch ( e ) { }
189+
190+ this . appendOutput ( `${ configFile } config state: ` + JSON . stringify ( currentConfig . getState ( ) ) + `\n` ) ;
191+ }
162192 }
163193
164194 get canUseCqsh ( ) {
@@ -507,7 +537,7 @@ export default class IBMi {
507537 await this . loadRemoteConfigs ( ) ;
508538
509539 const remoteConnectionConfig = this . getConfigFile < RemoteConfigFile > ( `settings` ) ;
510- if ( remoteConnectionConfig . getState ( ) . server === `ok` ) {
540+ if ( remoteConnectionConfig . getState ( ) === `ok` ) {
511541 const remoteConfig = await remoteConnectionConfig . get ( ) ;
512542
513543 if ( remoteConfig . codefori ) {
@@ -1075,20 +1105,6 @@ export default class IBMi {
10751105 return this . shell === IBMi . bashShellPath ;
10761106 }
10771107
1078- async loadRemoteConfigs ( ) {
1079- for ( const configFile in this . configFiles ) {
1080- const currentConfig = this . configFiles [ configFile as keyof ConnectionConfigFiles ] ;
1081-
1082- this . configFiles [ configFile as keyof ConnectionConfigFiles ] . reset ( ) ;
1083-
1084- try {
1085- await this . configFiles [ configFile as keyof ConnectionConfigFiles ] . loadFromServer ( ) ;
1086- } catch ( e ) { }
1087-
1088- this . appendOutput ( `${ configFile } config state: ` + JSON . stringify ( currentConfig . getState ( ) ) + `\n` ) ;
1089- }
1090- }
1091-
10921108 /**
10931109 * - Send PASE/QSH/ILE commands simply
10941110 * - Commands sent here end in the 'IBM i Output' channel
0 commit comments