-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Rational
Often times when working with partial DAGs we find ourselves with mix of materialized nodes for local blocks and links external blocks. When working in such a domain I often find myself wishing:
- I could pass either materialized node or a CID into functions without having to turn node into CID (often times that also requires checking if thing at hand is CID or a node).
- In functions that care about links I wish I could allow passing anything that can be linked via CID.
Both sides of the call would be happier if you could pass something "linkable" instead, that way callers could pass arbitrary nodes (as long as they are linkable) and callee could just use a link without having to inspect arguments.
Proposal
- I would like to propose introducing a new interface e.g.
Linkable
:
interface Linkable {
toLink(): CID
}
- Make CID implementation of proposed
Linkable
interface.
That way arbitrary objects could implement Linkable
interface which would allow them to be used everywhere Linkable
is accepted. Functions that typically want CID
s could also start accepting more general Linkable
s and there for allow passing arbitrary object that could be linked.
Alternative
For what it's worth we already have something along these lines in form of asCID
property. However it is a private property so TS complains about it. We could make it non private and achieve same goal by implementing asCID
property on desired nodes.