[DONE] How can we access advanced functionality in the library? #419
Replies: 3 comments 6 replies
-
Option 1 is fine, but I don't like that it pollutes the API for regular/most users. Also, we will have to decide what dangerous functionality to expose, which might not allow for as much flexibility as being able to freely mutate a document. The second option basically means we have to make all fields public (or add setters and getters). That's pretty straightforward while allowing for maximum flexibility. To avoid API pollution, I would hide all setters and getters behind a different type, i.e. I also like the third option, but we will again have to decide what to expose. |
Beta Was this translation helpful? Give feedback.
-
Option 1 This requires that we have functions for all such operations, which is not always the case. While some structs such as Option 2 This would be my preference as it exposes the full functionality that the low-level API allows (arbitrary document mutations via Option 3 This is similar to Option 1 in my opinion in that we essentially need to create duplicate functions to expose the full suite of unsafe functionality. I personally haven't seen this pattern in the wild. I think the one advantage it has over Option 1 is that it clearly delineates the separation between the safe and unsafe API: a developer has to call a single function with intention to even see the unsafe functionality, so API pollution is less of an issue. tl;dr I like Option 2 the most currently; Option 1 and Option 3 are very similar but the clear API separation may make Option 3 slightly more preferable. |
Beta Was this translation helpful? Give feedback.
-
Issue opened to implement Option 2: #433 |
Beta Was this translation helpful? Give feedback.
-
Currently the IOTA Identity framework has two different public API's:
low-level-api
and theaccount
. Thelow-level-api
is designed to give developers complete freedom at the cost of complexity. It is completely stateless, meaning that developers have a large responsibility to keep track of the state of an identity and its storage. Theaccount
is the opposite and a perfect entry point for new developers. The API protects developers from making common mistakes and provides a much easier API, at the cost of flexibility. It is stateful, therefore the developer has to take care of much less problems. The goal was that 90%+ of the use cases that have simple Identity requirements would do fine with just theaccount
.This discussion is about a
trapdoor
design (coined by Dave de Fijter), wherelow-level-api
capabilities are exposed in theaccount
API through a certain mechanism (a hidden door to a larger API). It would allow more flexibility to the account, but we are looking for a way to introduce the flexibility, but not at the cost of complexity. The team currently favours the idea of hiding the more advanced API behind some sort of mechanism. This discussion is about how a developer could access the more flexible yet dangerous functionalities, but new developers will understand that these functionalities are dangerous and not intended for them.This might even allow the
low-level-api
to be retired as a public API and moved to an internal API, reducing the complexity of the framework on first glance. That is being discussed in #398.Motivation
We want to enable users of the library to access advanced functionality, that only a small percentage of users would need, without complicating the API for the remaining users.
Proposal
1. Naming convention
Have the methods for the advanced functionality co-located with the other methods. The nature of the advanced functions can described by using keywords like
unchecked
ordangerous
or characters like_
in the method name. Those "markers" can be adapted to different language targets in the bindings, e.g. the methoduncheckedSetIssuer
in Rust could be converted todangerouslySetIssuer
in WASM/JS.For example:
2. Mutable DID-Document
Supply one method to return a DID or VC/VP document each and let advanced users directly mutate the document and commit the changes. This opens all possibilities of the documents, but might allow advanced users to bring the documents in a state, that is not supported by the more user friendly API methods.
3. Advanced / Elevated API
In the chain of a builder pattern have a command like
.advanced()
or.elevate()
, that returns a new builder that contains advanced methods like mentioned in proposal 1, but with clean names.Option 3.1
Option 3.2
A similar approach, including a naming convention, would be:
Edit: @JelleMillenaar edited the Discussion with intro and examples.
Edit: @PhilippGackstatter made the Rust examples more idiomatic and added 3.2.
Beta Was this translation helpful? Give feedback.
All reactions