@@ -5,7 +5,7 @@ pub(crate) mod utils;
5
5
6
6
use std:: {
7
7
collections:: HashMap ,
8
- sync:: LazyLock ,
8
+ sync:: { Arc , LazyLock } ,
9
9
time:: { Duration , SystemTime } ,
10
10
} ;
11
11
@@ -22,19 +22,16 @@ use rules::{
22
22
23
23
use crate :: {
24
24
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 ,
30
27
} ,
31
28
metadata:: DocType ,
32
29
providers:: { CatalystSignedDocumentProvider , VerifyingKeyProvider } ,
33
30
CatalystSignedDocument , ContentEncoding , ContentType ,
34
31
} ;
35
32
36
33
/// 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) ;
38
35
39
36
/// Returns an `DocType` from the provided argument.
40
37
/// Reduce redundant conversion.
50
47
51
48
/// `DOCUMENT_RULES` initialization function
52
49
#[ allow( clippy:: expect_used) ]
53
- fn document_rules_init ( ) -> HashMap < DocType , Rules > {
50
+ fn document_rules_init ( ) -> HashMap < DocType , Arc < Rules > > {
54
51
let mut document_rules_map = HashMap :: new ( ) ;
55
52
56
53
let proposal_document_rules = Rules {
@@ -62,10 +59,10 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
62
59
optional : false ,
63
60
} ,
64
61
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 ) ,
66
63
} ,
67
64
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 ) ,
69
66
optional : true ,
70
67
} ,
71
68
doc_ref : RefRule :: NotSpecified ,
@@ -76,8 +73,6 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
76
73
} ,
77
74
} ;
78
75
79
- document_rules_map. insert ( PROPOSAL_DOC_TYPE . clone ( ) , proposal_document_rules) ;
80
-
81
76
let comment_document_rules = Rules {
82
77
content_type : ContentTypeRule {
83
78
exp : ContentType :: Json ,
@@ -87,14 +82,14 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
87
82
optional : false ,
88
83
} ,
89
84
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 ) ,
91
86
} ,
92
87
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 ) ,
94
89
optional : false ,
95
90
} ,
96
91
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 ) ,
98
93
optional : true ,
99
94
} ,
100
95
section : SectionRule :: Specified { optional : true } ,
@@ -103,7 +98,6 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
103
98
exp : & [ RoleId :: Role0 ] ,
104
99
} ,
105
100
} ;
106
- document_rules_map. insert ( PROPOSAL_COMMENT_DOC . clone ( ) , comment_document_rules) ;
107
101
108
102
let proposal_action_json_schema = jsonschema:: options ( )
109
103
. with_draft ( jsonschema:: Draft :: Draft7 )
@@ -124,11 +118,11 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
124
118
} ,
125
119
content : ContentRule :: Static ( ContentSchema :: Json ( proposal_action_json_schema) ) ,
126
120
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 ) ,
128
122
optional : true ,
129
123
} ,
130
124
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 ) ,
132
126
optional : false ,
133
127
} ,
134
128
reply : ReplyRule :: NotSpecified ,
@@ -138,9 +132,22 @@ fn document_rules_init() -> HashMap<DocType, Rules> {
138
132
} ,
139
133
} ;
140
134
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
+ ) ;
141
148
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 ) ,
144
151
) ;
145
152
146
153
document_rules_map
0 commit comments