github.com/storacha/go-ucanto@v0.7.2/core/ipld/view.go (about) 1 package ipld 2 3 import ( 4 "iter" 5 ) 6 7 // View represents a materialized IPLD DAG View, which provides a generic 8 // traversal API. It is useful for encoding (potentially partial) IPLD DAGs 9 // into content archives (e.g. CARs). 10 type View interface { 11 // Root is the root block of the IPLD DAG this is the view of. This is the 12 // block from which all other blocks are linked directly or transitively. 13 Root() Block 14 // Blocks returns an iterator of all the IPLD blocks that are included in 15 // this view. 16 // 17 // It is RECOMMENDED that implementations return blocks in bottom up order 18 // (i.e. leaf blocks first, root block last). 19 // 20 // Iterator MUST include the root block otherwise it will lead encoders into 21 // omitting it when encoding the view into a CAR archive. 22 Blocks() iter.Seq2[Block, error] 23 } 24 25 // ViewBuilder represents a materializable IPLD DAG View. It is a useful 26 // abstraction that can be used to defer actual IPLD encoding. 27 // 28 // Note that represented DAG could be partial implying that some of the blocks 29 // may not be included. This by design allowing a user to include whatever 30 // blocks they want to include. 31 type ViewBuilder[V View] interface { 32 // BuildIPLDView encodes all the blocks and creates a new IPLDView instance over them. 33 BuildIPLDView() V 34 }