@@ -5,7 +5,7 @@ pub(crate) mod utils;
55
66use std:: {
77 collections:: HashMap ,
8- sync:: LazyLock ,
8+ sync:: { Arc , LazyLock } ,
99 time:: { Duration , SystemTime } ,
1010} ;
1111
@@ -22,19 +22,16 @@ use rules::{
2222
2323use crate :: {
2424 doc_types:: {
25- deprecated:: {
26- CATEGORY_DOCUMENT_UUID_TYPE , COMMENT_TEMPLATE_UUID_TYPE , PROPOSAL_TEMPLATE_UUID_TYPE ,
27- } ,
28- COMMENT_UUID_TYPE , PROPOSAL_ACTION_DOC , PROPOSAL_COMMENT_DOC , PROPOSAL_DOC_TYPE ,
29- PROPOSAL_UUID_TYPE ,
25+ deprecated:: { self } ,
26+ PROPOSAL_ACTION_DOC , PROPOSAL_COMMENT_DOC , PROPOSAL_DOC_TYPE ,
3027 } ,
3128 metadata:: DocType ,
3229 providers:: { CatalystSignedDocumentProvider , VerifyingKeyProvider } ,
3330 CatalystSignedDocument , ContentEncoding , ContentType ,
3431} ;
3532
3633/// A table representing a full set or validation rules per document id.
37- static DOCUMENT_RULES : LazyLock < HashMap < DocType , Rules > > = LazyLock :: new ( document_rules_init) ;
34+ static DOCUMENT_RULES : LazyLock < HashMap < DocType , Arc < Rules > > > = LazyLock :: new ( document_rules_init) ;
3835
3936/// Returns an `DocType` from the provided argument.
4037/// Reduce redundant conversion.
5047
5148/// `DOCUMENT_RULES` initialization function
5249#[ allow( clippy:: expect_used) ]
53- fn document_rules_init ( ) -> HashMap < DocType , Rules > {
50+ fn document_rules_init ( ) -> HashMap < DocType , Arc < Rules > > {
5451 let mut document_rules_map = HashMap :: new ( ) ;
5552
5653 let proposal_document_rules = Rules {
@@ -62,10 +59,10 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
6259 optional : false ,
6360 } ,
6461 content : ContentRule :: Templated {
65- exp_template_type : expect_doc_type ( PROPOSAL_TEMPLATE_UUID_TYPE ) ,
62+ exp_template_type : expect_doc_type ( deprecated :: PROPOSAL_TEMPLATE_UUID_TYPE ) ,
6663 } ,
6764 parameters : ParametersRule :: Specified {
68- exp_parameters_type : expect_doc_type ( CATEGORY_DOCUMENT_UUID_TYPE ) ,
65+ exp_parameters_type : expect_doc_type ( deprecated :: CATEGORY_DOCUMENT_UUID_TYPE ) ,
6966 optional : true ,
7067 } ,
7168 doc_ref : RefRule :: NotSpecified ,
@@ -76,8 +73,6 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
7673 } ,
7774 } ;
7875
79- document_rules_map. insert ( PROPOSAL_DOC_TYPE . clone ( ) , proposal_document_rules) ;
80-
8176 let comment_document_rules = Rules {
8277 content_type : ContentTypeRule {
8378 exp : ContentType :: Json ,
@@ -87,14 +82,14 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
8782 optional : false ,
8883 } ,
8984 content : ContentRule :: Templated {
90- exp_template_type : expect_doc_type ( COMMENT_TEMPLATE_UUID_TYPE ) ,
85+ exp_template_type : expect_doc_type ( deprecated :: COMMENT_TEMPLATE_UUID_TYPE ) ,
9186 } ,
9287 doc_ref : RefRule :: Specified {
93- exp_ref_type : expect_doc_type ( PROPOSAL_UUID_TYPE ) ,
88+ exp_ref_type : expect_doc_type ( deprecated :: PROPOSAL_DOCUMENT_UUID_TYPE ) ,
9489 optional : false ,
9590 } ,
9691 reply : ReplyRule :: Specified {
97- exp_reply_type : expect_doc_type ( COMMENT_UUID_TYPE ) ,
92+ exp_reply_type : expect_doc_type ( deprecated :: COMMENT_DOCUMENT_UUID_TYPE ) ,
9893 optional : true ,
9994 } ,
10095 section : SectionRule :: Specified { optional : true } ,
@@ -103,7 +98,6 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
10398 exp : & [ RoleId :: Role0 ] ,
10499 } ,
105100 } ;
106- document_rules_map. insert ( PROPOSAL_COMMENT_DOC . clone ( ) , comment_document_rules) ;
107101
108102 let proposal_action_json_schema = jsonschema:: options ( )
109103 . with_draft ( jsonschema:: Draft :: Draft7 )
@@ -124,11 +118,11 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
124118 } ,
125119 content : ContentRule :: Static ( ContentSchema :: Json ( proposal_action_json_schema) ) ,
126120 parameters : ParametersRule :: Specified {
127- exp_parameters_type : expect_doc_type ( CATEGORY_DOCUMENT_UUID_TYPE ) ,
121+ exp_parameters_type : expect_doc_type ( deprecated :: CATEGORY_DOCUMENT_UUID_TYPE ) ,
128122 optional : true ,
129123 } ,
130124 doc_ref : RefRule :: Specified {
131- exp_ref_type : expect_doc_type ( PROPOSAL_UUID_TYPE ) ,
125+ exp_ref_type : expect_doc_type ( deprecated :: PROPOSAL_DOCUMENT_UUID_TYPE ) ,
132126 optional : false ,
133127 } ,
134128 reply : ReplyRule :: NotSpecified ,
@@ -138,9 +132,22 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
138132 } ,
139133 } ;
140134
135+ let proposal_rules = Arc :: new ( proposal_document_rules) ;
136+ let comment_rules = Arc :: new ( comment_document_rules) ;
137+ let action_rules = Arc :: new ( proposal_submission_action_rules) ;
138+
139+ document_rules_map. insert ( PROPOSAL_DOC_TYPE . clone ( ) , Arc :: clone ( & proposal_rules) ) ;
140+ document_rules_map. insert ( PROPOSAL_COMMENT_DOC . clone ( ) , Arc :: clone ( & comment_rules) ) ;
141+ document_rules_map. insert ( PROPOSAL_ACTION_DOC . clone ( ) , Arc :: clone ( & action_rules) ) ;
142+
143+ // Insert old rules (for backward compatibility)
144+ document_rules_map. insert (
145+ expect_doc_type ( deprecated:: COMMENT_DOCUMENT_UUID_TYPE ) ,
146+ Arc :: clone ( & comment_rules) ,
147+ ) ;
141148 document_rules_map. insert (
142- PROPOSAL_ACTION_DOC . clone ( ) ,
143- proposal_submission_action_rules ,
149+ expect_doc_type ( deprecated :: PROPOSAL_ACTION_DOCUMENT_UUID_TYPE ) ,
150+ Arc :: clone ( & action_rules ) ,
144151 ) ;
145152
146153 document_rules_map
0 commit comments