2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  Translation ,  TypedTranslation  }  from  "../../UI/i18n/Translation"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  TagsFilter  }  from  "../../Logic/Tags/TagsFilter"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  DeleteConfigJson  }  from  "./Json/DeleteConfigJson"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Translations  from  "../../UI/i18n/Translations"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  TagUtils  }  from  "../../Logic/Tags/TagUtils"  
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  class  DeleteConfig  {  
						 
					
						
							
								
									
										
										
										
											2022-12-06 00:49:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    private  static  readonly  defaultDeleteReasons :  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        changesetMessage : string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        explanation : Translation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } [ ]  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 04:17:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            changesetMessage :  "testing point" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            explanation : Translations.t.delete.reasons.test , 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 04:17:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            changesetMessage :  "disused" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            explanation : Translations.t.delete.reasons.disused , 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 04:17:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            changesetMessage :  "not found" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            explanation : Translations.t.delete.reasons.notFound , 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 04:17:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            changesetMessage :  "duplicate" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            explanation : Translations.t.delete.reasons.duplicate , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-01 04:17:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 00:49:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  readonly  deleteReasons ? :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        explanation : TypedTranslation < object >  |  Translation 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        changesetMessage : string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  readonly  nonDeleteMappings ? :  {  if :  TagsFilter ;  then : TypedTranslation < object >  } [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  readonly  softDeletionTags? : TagsFilter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  neededChangesets? : number 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( json : DeleteConfigJson ,  context : string )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 00:49:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . deleteReasons  =  ( json . extraDeleteReasons  ? ?  [ ] ) . map ( ( reason ,  i )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            const  ctx  =  ` ${ context } .extraDeleteReasons[ ${ i } ] ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ( reason . changesetMessage  ? ?  "" ) . length  <=  5 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                throw  ` ${ ctx } .explanation is too short, needs at least 4 characters ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                explanation : Translations.T ( reason . explanation ,  ctx  +  ".explanation" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                changesetMessage : reason.changesetMessage , 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 00:49:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if ( ! json . omitDefaultDeleteReasons  ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( const  defaultDeleteReason  of  DeleteConfig . defaultDeleteReasons )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . deleteReasons . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    changesetMessage : defaultDeleteReason.changesetMessage , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    explanation : defaultDeleteReason.explanation.Clone ( /*Must clone, hides translation otherwise*/ ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . nonDeleteMappings  =  ( json . nonDeleteMappings  ? ?  [ ] ) . map ( ( nonDelete ,  i )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            const  ctx  =  ` ${ context } .extraDeleteReasons[ ${ i } ] ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if :  TagUtils . Tag ( nonDelete . if ,  ctx  +  ".if" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                then : Translations.T ( nonDelete . then ,  ctx  +  ".then" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 00:49:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( this . nonDeleteMappings . length  +  this . deleteReasons . length  ==  0 ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            throw  "At " + context + ": a deleteconfig should have some reasons to delete: either the default delete reasons or a nonDeleteMapping or extraDeletereason should be given" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . softDeletionTags  =  undefined 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( json . softDeletionTags  !==  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . softDeletionTags  =  TagUtils . Tag ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                json . softDeletionTags , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ` ${ context } .softDeletionTags ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:11:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( json [ "hardDeletionTags" ]  !==  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-05 16:20:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            throw  ` You probably meant 'softDeletionTags' instead of 'hardDeletionTags' (at  ${ context } ) ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-03 14:35:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . neededChangesets  =  json . neededChangesets 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}