@@ -56,17 +56,10 @@ impl<'a, RT: Runtime> ComponentsModel<'a, RT> {
5656 [ attribute] => attribute,
5757 _ => anyhow:: bail!( "Nested component argument references unsupported" ) ,
5858 } ;
59- let component = BootstrapComponentsModel :: new ( self . tx )
60- . load_component ( component_id)
61- . await ?
62- . ok_or_else ( || {
63- ErrorMetadata :: bad_request (
64- "InvalidReference" ,
65- format ! ( "Component {:?} not found" , component_id) ,
66- )
67- } ) ?;
68- let ComponentType :: ChildComponent { ref args, .. } = component. component_type
69- else {
59+ let component_type = BootstrapComponentsModel :: new ( self . tx )
60+ . load_component_type ( component_id)
61+ . await ?;
62+ let ComponentType :: ChildComponent { ref args, .. } = component_type else {
7063 anyhow:: bail!( ErrorMetadata :: bad_request(
7164 "InvalidReference" ,
7265 "Can't use an argument reference in the app"
@@ -160,7 +153,7 @@ impl<'a, RT: Runtime> ComponentsModel<'a, RT> {
160153 ) -> anyhow:: Result < Resource > {
161154 let mut m = BootstrapComponentsModel :: new ( self . tx ) ;
162155 let definition_id = m. component_definition ( component_id) . await ?;
163- let definition = m. load_definition ( definition_id) . await ?;
156+ let definition = m. load_definition_metadata ( definition_id) . await ?;
164157
165158 let mut current = & definition. exports ;
166159 let mut attribute_iter = attributes. iter ( ) ;
@@ -193,19 +186,15 @@ impl<'a, RT: Runtime> ComponentsModel<'a, RT> {
193186 component_id : ComponentId ,
194187 ) -> anyhow:: Result < BTreeMap < Reference , Resource > > {
195188 let mut m = BootstrapComponentsModel :: new ( self . tx ) ;
196- let component = m. load_component ( component_id) . await ?. ok_or_else ( || {
197- ErrorMetadata :: bad_request (
198- "InvalidReference" ,
199- format ! ( "Component {:?} not found" , component_id) ,
200- )
201- } ) ?;
189+ let component = m. load_component ( component_id) . await ?;
190+ let component_type = m. load_component_type ( component_id) . await ?;
202191 let definition_id = m. component_definition ( component_id) . await ?;
203- let definition = m. load_definition ( definition_id) . await ?;
192+ let definition = m. load_definition_metadata ( definition_id) . await ?;
204193 let component_path = m. get_component_path ( component_id) . await ?;
205194
206195 let mut result = BTreeMap :: new ( ) ;
207196
208- if let ComponentType :: ChildComponent { ref args, .. } = component . component_type {
197+ if let ComponentType :: ChildComponent { ref args, .. } = component_type {
209198 for ( name, resource) in args {
210199 let reference = Reference :: ComponentArgument {
211200 attributes : vec ! [ name. clone( ) ] ,
@@ -236,21 +225,23 @@ impl<'a, RT: Runtime> ComponentsModel<'a, RT> {
236225 }
237226 }
238227
239- for instantiation in & definition. child_components {
240- let parent = ( component. id ( ) . internal_id ( ) , instantiation. name . clone ( ) ) ;
241- let child_component = BootstrapComponentsModel :: new ( self . tx )
242- . component_in_parent ( Some ( parent) )
243- . await ?
244- . context ( "Missing child component" ) ?;
245- let child_component_id = ComponentId :: Child ( child_component. id ( ) . internal_id ( ) ) ;
246- for ( attributes, resource) in
247- self . preload_exported_resources ( child_component_id) . await ?
248- {
249- let reference = Reference :: ChildComponent {
250- component : instantiation. name . clone ( ) ,
251- attributes,
252- } ;
253- result. insert ( reference, resource) ;
228+ if let Some ( component) = component {
229+ for instantiation in & definition. child_components {
230+ let parent = ( component. id ( ) . internal_id ( ) , instantiation. name . clone ( ) ) ;
231+ let child_component = BootstrapComponentsModel :: new ( self . tx )
232+ . component_in_parent ( Some ( parent) )
233+ . await ?
234+ . context ( "Missing child component" ) ?;
235+ let child_component_id = ComponentId :: Child ( child_component. id ( ) . internal_id ( ) ) ;
236+ for ( attributes, resource) in
237+ self . preload_exported_resources ( child_component_id) . await ?
238+ {
239+ let reference = Reference :: ChildComponent {
240+ component : instantiation. name . clone ( ) ,
241+ attributes,
242+ } ;
243+ result. insert ( reference, resource) ;
244+ }
254245 }
255246 }
256247
@@ -263,7 +254,7 @@ impl<'a, RT: Runtime> ComponentsModel<'a, RT> {
263254 ) -> anyhow:: Result < BTreeMap < Vec < Identifier > , Resource > > {
264255 let mut m = BootstrapComponentsModel :: new ( self . tx ) ;
265256 let definition_id = m. component_definition ( component_id) . await ?;
266- let definition = m. load_definition ( definition_id) . await ?;
257+ let definition = m. load_definition_metadata ( definition_id) . await ?;
267258
268259 let mut stack = vec ! [ ( vec![ ] , & definition. exports) ] ;
269260 let mut result = BTreeMap :: new ( ) ;
0 commit comments