9
9
//! - Validate data against OCA Bundle.
10
10
//! - Traverse through OCA Bundle attributes.
11
11
pub mod data_validator;
12
- pub use oca_ast_semantics:: ast:: { AttributeType , NestedAttrType , OverlayType , RefValue , recursive_attributes:: NestedAttrTypeFrame } ;
12
+ pub use oca_ast_semantics:: ast:: {
13
+ recursive_attributes:: NestedAttrTypeFrame , AttributeType , NestedAttrType ,
14
+ OverlayType , RefValue ,
15
+ } ;
13
16
14
17
/// Performs semantic validation of an `OCABundle` and returns a status
15
18
/// indicating whether the validation succeeded or failed, along with any associated errors.
@@ -57,17 +60,17 @@ pub use oca_bundle_semantics::{
57
60
controller:: load_oca as load,
58
61
state:: {
59
62
attribute:: Attribute ,
60
- oca:: { OCABox , OCABundle , overlay } ,
63
+ oca:: { overlay , OCABox , OCABundle } ,
61
64
validator:: { SemanticValidationStatus , Validator as OCAValidator } ,
62
65
} ,
63
66
} ;
64
- pub use oca_rs:: facade:: { Facade , build:: { build_from_ocafile, parse_oca_bundle_to_ocafile} } ;
65
- use oca_rs:: {
66
- facade:: bundle:: Bundle , EncodeBundle , HashFunctionCode ,
67
- SerializationFormats ,
67
+ pub use oca_rs:: facade:: {
68
+ build:: { build_from_ocafile, parse_oca_bundle_to_ocafile} ,
69
+ Facade ,
68
70
} ;
71
+ use oca_rs:: { EncodeBundle , HashFunctionCode , SerializationFormats } ;
69
72
use std:: collections:: HashMap ;
70
- pub use transformation_file :: state :: Transformation ;
73
+ use std :: sync :: OnceLock ;
71
74
72
75
pub trait ToJSON {
73
76
fn get_json_bundle ( & self ) -> String ;
@@ -83,45 +86,42 @@ impl ToJSON for OCABundle {
83
86
}
84
87
85
88
pub trait WithInfo {
86
- fn info ( & self ) -> BundleInfo ;
89
+ fn info ( & self ) -> & OCABundleInfo ;
87
90
}
88
91
89
- impl WithInfo for Bundle {
90
- fn info ( & self ) -> BundleInfo {
91
- BundleInfo :: new ( self . clone ( ) )
92
+ impl WithInfo for OCABundle {
93
+ fn info ( & self ) -> & OCABundleInfo {
94
+ static CACHE : OnceLock < OCABundleInfo > = OnceLock :: new ( ) ;
95
+ CACHE . get_or_init ( || OCABundleInfo :: new ( self ) )
92
96
}
93
97
}
94
98
95
- pub struct BundleInfo {
96
- pub attributes : HashMap < String , Attribute > ,
99
+ pub struct OCABundleInfo {
100
+ attributes : HashMap < String , Attribute > ,
97
101
pub meta : HashMap < String , HashMap < String , String > > ,
98
- pub links : Vec < Transformation > ,
99
- pub framing : Vec < String > ,
102
+ pub links : Vec < overlay :: Link > ,
103
+ pub framing : Vec < overlay :: AttributeFraming > ,
100
104
}
101
105
102
- impl BundleInfo {
103
- pub fn new ( bundle : Bundle ) -> Self {
104
- let mut attributes = HashMap :: new ( ) ;
106
+ impl OCABundleInfo {
107
+ pub fn new ( bundle : & OCABundle ) -> Self {
105
108
let mut meta = HashMap :: new ( ) ;
106
- if let Some ( structural_bundle) = bundle. structural {
107
- let structural_box = OCABox :: from ( structural_bundle. clone ( ) ) ;
108
- if let Some ( m) = structural_box. meta {
109
- m. iter ( ) . for_each ( |( k, v) | {
110
- meta. insert ( k. to_639_3 ( ) . to_string ( ) , v. to_owned ( ) ) ;
111
- } )
112
- }
113
- attributes = structural_box. attributes ;
109
+ let oca_box = OCABox :: from ( bundle. clone ( ) ) ;
110
+ if let Some ( m) = oca_box. meta {
111
+ m. iter ( ) . for_each ( |( k, v) | {
112
+ meta. insert ( k. to_639_3 ( ) . to_string ( ) , v. to_owned ( ) ) ;
113
+ } )
114
114
}
115
115
116
116
Self {
117
- attributes,
117
+ attributes : oca_box . attributes ,
118
118
meta,
119
- links : bundle . transformations ,
119
+ links : vec ! [ ] ,
120
120
framing : vec ! [ ] ,
121
121
}
122
122
}
123
123
124
- pub fn attributes ( & self ) -> impl Iterator < Item = & Attribute > {
124
+ pub fn attributes ( & self ) -> impl Iterator < Item = & Attribute > {
125
125
self . attributes . values ( )
126
126
}
127
127
0 commit comments