@@ -32,41 +32,26 @@ pub struct IntoValues {
3232 items : VecDeque < Item > ,
3333}
3434
35+ /// A resolver that uses object store.
3536impl Node {
3637 /// Resolves all child and item links in this node.
3738 ///
39+ /// This method uses [crate::Resolver] to resolve links.
40+ ///
3841 /// # Examples
3942 ///
4043 /// ```
4144 /// use stac::{Catalog, Node};
4245 ///
4346 /// let mut node: Node = stac::read::<Catalog>("examples/catalog.json").unwrap().into();
44- /// node.resolve().unwrap();
47+ /// # tokio_test::block_on(async {
48+ /// let node = node.resolve().await.unwrap();
49+ /// });
4550 /// ```
46- pub fn resolve ( & mut self ) -> Result < ( ) > {
47- let links = std:: mem:: take ( self . value . links_mut ( ) ) ;
48- let href = self . value . self_href ( ) . cloned ( ) ;
49- for mut link in links {
50- if link. is_child ( ) {
51- if let Some ( href) = & href {
52- link. make_absolute ( href) ?;
53- }
54- // TODO enable object store
55- tracing:: debug!( "resolving child: {}" , link. href) ;
56- let child: Container = crate :: read :: < Value > ( link. href ) ?. try_into ( ) ?;
57- self . children . push_back ( child. into ( ) ) ;
58- } else if link. is_item ( ) {
59- if let Some ( href) = & href {
60- link. make_absolute ( href) ?;
61- }
62- tracing:: debug!( "resolving item: {}" , link. href) ;
63- let item = crate :: read :: < Item > ( link. href ) ?;
64- self . items . push_back ( item) ;
65- } else {
66- self . value . links_mut ( ) . push ( link) ;
67- }
68- }
69- Ok ( ( ) )
51+ #[ cfg( feature = "object-store" ) ]
52+ pub async fn resolve ( self ) -> Result < Node > {
53+ let resolver = crate :: Resolver :: default ( ) ;
54+ resolver. resolve ( self ) . await
7055 }
7156
7257 /// Creates a consuming iterator over this node and its children and items.
@@ -205,20 +190,23 @@ impl SelfHref for Container {
205190#[ cfg( test) ]
206191mod tests {
207192 use super :: Node ;
208- use crate :: { Catalog , Collection , Links } ;
193+ use crate :: { Catalog , Collection } ;
209194
210195 #[ test]
211196 fn into_node ( ) {
212197 let _ = Node :: from ( Catalog :: new ( "an-id" , "a description" ) ) ;
213198 let _ = Node :: from ( Collection :: new ( "an-id" , "a description" ) ) ;
214199 }
215200
216- #[ test]
217- fn resolve ( ) {
218- let mut node: Node = crate :: read :: < Catalog > ( "examples/catalog.json" )
201+ #[ tokio:: test]
202+ #[ cfg( feature = "object-store" ) ]
203+ async fn resolve ( ) {
204+ use crate :: Links ;
205+
206+ let node: Node = crate :: read :: < Catalog > ( "examples/catalog.json" )
219207 . unwrap ( )
220208 . into ( ) ;
221- node. resolve ( ) . unwrap ( ) ;
209+ let node = node . resolve ( ) . await . unwrap ( ) ;
222210 assert_eq ! ( node. children. len( ) , 3 ) ;
223211 assert_eq ! ( node. items. len( ) , 1 ) ;
224212 assert_eq ! ( node. value. links( ) . len( ) , 2 ) ;
0 commit comments