Skip to content

Proposal: add some method e.g. .toLink(): CID on CID object #185

@Gozala

Description

@Gozala

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:

  1. 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).
  2. 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

  1. I would like to propose introducing a new interface e.g. Linkable:
interface Linkable {
  toLink(): CID
}
  1. 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 CIDs could also start accepting more general Linkables 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions