Implement traversal.FocusedTransform. #130
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
traversal.FocusedTransform
is now available. It takes a starting Node, a Path, and a TransformFn (which is essentially just a function from Node to Node), and uses those instructions to build a new Node tree with the transform applied at the given path.Like all the other
traversal.*
functions, it carries atraversal.Progress
object around, which you can use in the TransformFn to see where you are, or to do continued traversals or transformations at deeper levels of the data while keeping a coherent track of overall position, etc.This works even if the Path happens to cross links! If you've configured enough Loader and Storer functions in the
traversal.Config
, any links crossed will be automatically loaded, the transform will continue inside, and when the transform is complete, the data beyond the link will be reserialized in the same style as the original link (e.g. in the case of CIDs, that means: same multicodec will be used, same multihash will be used, etc etc), and the link will be replaced with a link to the new data, which will also have been stored.This patch also includes a few new accessors for Path that are helpful and reasonable.