@@ -184,47 +184,31 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
184184 */
185185 constructConfigurationObject ( options ?: ConfigurationObjectConstructionOptions ) : Record < string , any > {
186186 const separator = options ?. separator ?? "." ;
187- const prefix = options ?. prefix ?? "" ;
188- const onError = options ?. onError ?? "error" ;
189187
190188 // construct hierarchical data object from map
191189 const data : Record < string , any > = { } ;
192190 for ( const [ key , value ] of this . #configMap) {
193- if ( key . startsWith ( prefix ) ) {
194- const segments = key . slice ( prefix . length ) . split ( separator ) ;
195- let current = data ;
196- // construct hierarchical data object along the path
197- for ( let i = 0 ; i < segments . length - 1 ; i ++ ) {
198- const segment = segments [ i ] ;
199- // undefined or empty string
200- if ( ! segment ) {
201- if ( onError === "error" ) {
202- throw new Error ( `invalid key: ${ key } ` ) ;
203- } else if ( onError === "ignore" ) {
204- continue ;
205- } else {
206- throw new Error ( `The value of 'onError' is not supported: ${ onError } ` ) ;
207- }
208- }
209- // create path if not exist
210- if ( current [ segment ] === undefined ) {
211- current [ segment ] = { } ;
212- }
213- // The path has been occupied by a non-object value, causing ambiguity.
214- if ( typeof current [ segment ] !== "object" ) {
215- if ( onError === "error" ) {
216- throw new Error ( `The key '${ prefix } ${ segments . slice ( 0 , i + 1 ) . join ( separator ) } ' is not a valid path.` ) ;
217- } else if ( onError === "ignore" ) {
218- current [ segment ] = { } ; // overwrite the non-object value
219- } else {
220- throw new Error ( `The value of 'onError' is not supported: ${ onError } ` ) ;
221- }
222- }
223- current = current [ segment ] ;
191+ const segments = key . split ( separator ) ;
192+ let current = data ;
193+ // construct hierarchical data object along the path
194+ for ( let i = 0 ; i < segments . length - 1 ; i ++ ) {
195+ const segment = segments [ i ] ;
196+ // undefined or empty string
197+ if ( ! segment ) {
198+ throw new Error ( `invalid key: ${ key } ` ) ;
199+ }
200+ // create path if not exist
201+ if ( current [ segment ] === undefined ) {
202+ current [ segment ] = { } ;
203+ }
204+ // The path has been occupied by a non-object value, causing ambiguity.
205+ if ( typeof current [ segment ] !== "object" ) {
206+ throw new Error ( `The key '${ segments . slice ( 0 , i + 1 ) . join ( separator ) } ' is not a valid path.` ) ;
224207 }
225- // set value to the last segment
226- current [ segments [ segments . length - 1 ] ] = value ;
208+ current = current [ segment ] ;
227209 }
210+ // set value to the last segment
211+ current [ segments [ segments . length - 1 ] ] = value ;
228212 }
229213 return data ;
230214 }
0 commit comments