@@ -41,6 +41,7 @@ export interface ListenerUtils {
41
41
extractDifferences : ( type : keyof typeof unexposedConfigs , data : any ) => Record < string , any >
42
42
objectToHocon ( obj : Record < string , any > ) : string
43
43
hoconToObject : ( hoconData : string ) => Record < string , any >
44
+ resetCustomConfig : ( data : Listener , defaultConfig : Listener ) => Listener
44
45
}
45
46
46
47
export default ( gatewayName ?: string | undefined ) : ListenerUtils => {
@@ -416,15 +417,43 @@ export default (gatewayName?: string | undefined): ListenerUtils => {
416
417
417
418
const hoconToObject = ( hoconData : string ) : Record < string , any > => {
418
419
try {
419
- console . log ( hoconData )
420
420
const parsedData = parseHoconToObject ( hoconData )
421
- console . log ( parsedData )
422
421
return Promise . resolve ( parsedData )
423
422
} catch ( error ) {
424
423
return Promise . reject ( error )
425
424
}
426
425
}
427
426
427
+ /**
428
+ * Resets the custom configuration by merging it with the default configuration.
429
+ * If a property in the custom configuration is undefined, null, empty string, or an empty object,
430
+ * it will be replaced with the corresponding property from the default configuration.
431
+ * If a property in the custom configuration is an object and the corresponding property in the default configuration is also an object,
432
+ * the function will recursively reset the nested properties.
433
+ *
434
+ * @param customData - The custom configuration to be reset.
435
+ * @param defaultCustomConfig - The default configuration to merge with the custom configuration.
436
+ * @returns The custom configuration after resetting.
437
+ */
438
+ const resetCustomConfig = ( customData : Listener , defaultCustomConfig : Listener ) : Listener => {
439
+ for ( const key in defaultCustomConfig ) {
440
+ if (
441
+ customData [ key ] === undefined ||
442
+ customData [ key ] === null ||
443
+ customData [ key ] === '' ||
444
+ ( typeof customData [ key ] === 'object' && isEmptyObj ( customData [ key ] ) )
445
+ ) {
446
+ customData [ key ] = defaultCustomConfig [ key ]
447
+ } else if (
448
+ typeof customData [ key ] === 'object' &&
449
+ typeof defaultCustomConfig [ key ] === 'object'
450
+ ) {
451
+ customData [ key ] = resetCustomConfig ( customData [ key ] , defaultCustomConfig [ key ] )
452
+ }
453
+ }
454
+ return customData
455
+ }
456
+
428
457
return {
429
458
completeGatewayListenerTypeList,
430
459
listenerTypeList,
@@ -451,5 +480,6 @@ export default (gatewayName?: string | undefined): ListenerUtils => {
451
480
extractDifferences,
452
481
objectToHocon,
453
482
hoconToObject,
483
+ resetCustomConfig,
454
484
}
455
485
}
0 commit comments