-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set controller
, alsoKnownAs
fields from Account
#658
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef3b771
poc `set_controller`
10a31a4
implement `set_also_known_as`
6010425
format
2915bcd
add tests for `set_controller` and `also_known_as`
be909de
remote redundant `set_also_known_as(..)`
cfa1742
Merge branch 'dev' into feat/account-fields-controller-aka
abdulmth deaecd5
fix set controller
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really follow the convention the account updates have so far. The existing updates add or remove a service/method from the set of services/methods in the document. These
Set*
updates overwrite whatever was there previously. Either we change this to beCreateController
&DeleteController
andCreateAlsoKnownAs
&DeleteAlsoKnownAs
or we change the existing updates to also beSet*
updates.I think the
Set*
variants are rather unwieldy for non-trivial updates, where e.g. one wants to add a controller to a document. You'd have to copy over the old controllers. So, I'm in favor of having theCreate*
andDelete*
-style updates. One way or another, we should be consistent.The
Create
terminology doesn't feel appropriate here, so we could also use theAdd*
prefix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly due to my description in issue #647. The
controller
andalso_known_as
fields are simple collections rather than complex structs likeVerificationMethod
andService
, so it is my opinion that they don't need fine-grained operations which contribute to API pollution (maybe too strong a term).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how simple the other account updates are, I don't think set-style updates fit nicely with the ease of the API that we have so far. Just adding a controller requires:
I assume these updates "in code" are infrequent, to either controller or alsoKnownAs, compared to services or methods, but when they occur it's quite verbose.
I generally don't see set operations for collections exposed on APIs because they are unwieldy to work with. And since in our API we don't have the possibility to return a
&mut OrderedSet
to let users append through that, I think the nicest solution would be to expose add and delete operations. Of course, I would like to avoid the pollution of the API, but that takes lower priority in my mind.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That example can be simplified somewhat (and even more so if using an intermediate
Vec
andFrom
/TryFrom
):Would it be better if they took
Vec
instead ofOneOrSet
? That would work around the awkwardOneOrSet
restrictions at the risk of runtime errors?My problem with individual builder operations on collections is that it's even more difficult to use when you actually have a collection you want to pass to the builder. As was seen when exposing the
attach/detach_method_relationships
API to the Wasm bindings due to intermediate, temporary structs in the builder pattern being dropped.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can solve the latter by using something like:
on the
AttachMethodRelationshipBuilder
so someone can callGranted, it's not ergonomic to require
TryInto
so we may want to reconsider the bounds onOneOrSet
(probably not possible) or introduce a new small type to facilitate that. (This example ignores the errors). We could do that similarly for controllers/alsoKnownAs. I think that would at least solve the "extend an existing collection with a collection" problem.If we still want to do set-style updates, I think taking
Vec
would be a good step at least.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding
relationships
: I opened #654 previously and recommended either a vec, slice, or iterator as input sinceMethodRelationship
implementsCopy
.I wouldn't mind using
TryInto
. The only difference is that it moves the error fromapply
up to the field call atrelationships
, so really the example would be:Not much different but it sets a precedent about where update builder errors can be thrown. One good thing about requiring the actual type (
OneOrSet
) is that it forces the developer to handle those errors up-front rather than having to interpret errors from the builder, but I do admit it is less easy-to-use.Edit:
attach_method_relationship
/detach_method_relationship
are idempotent so they can just useVec
/slice, having them called with an empty list or duplicates doesn't matter there since it's an operation not a field setter likecontroller
/also_known_as
. The example translates to the matter at hand though.Back to this: what's the conclusion? Are we staying with
set_controller
/set_also_known_as
(with improved ergonomics for the input parameters such asVec
orTryInto
) or are we set on splitting them into four methods for create/remove each? I'm still of the opinion thatset_*
methods are preferable for these fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For builders, I think I'd prefer them not to throw errors. Not sure how common errors in builders are. If
From<Vec<T>> for OrderedSet
was implemented, that would make things a lot easier, and we could by ignoring duplicates. But I suppose that was a deliberate choice, so I don't want to reopen that discussion, too.I'm still more in favor of the create/delete methods, since with the
Vec
orTryInto
, it should make working with single and collection values fairly easy, and because adding any value with set-style methods is cumbersome.Since we're not really coming to a conclusion, though, I'm fine with going with set-updates for now and see how they turn out in practice. In that case, I would go with
Vec
to avoid errors on the builder method.Unless there's more opinions, @abdulmth this might be the conclusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PhilippGackstatter and I agreed in a call that we might want to keep the implementation as-is since it's not trivial to implement the delete methods because it must deal with
IotaDID
andUrl
objects rather than enum variants (for example indetach_relationships
). We also don't wanna useVec
to keep parity with the return values of the getter methods.