Skip to content
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

another take on simpler way of adding a service #313

Closed
wants to merge 4 commits into from

Conversation

michaelneale
Copy link

For bug #310

an alternative take on #311 which adds a service more directly without taking an update object.

@codecov-commenter
Copy link

codecov-commenter commented May 16, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 73.72%. Comparing base (fb1f9aa) to head (8bff058).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #313      +/-   ##
==========================================
+ Coverage   73.58%   73.72%   +0.13%     
==========================================
  Files          45       45              
  Lines        2162     2177      +15     
  Branches      402      403       +1     
==========================================
+ Hits         1591     1605      +14     
  Misses        376      376              
- Partials      195      196       +1     
Components Coverage Δ
credentials 81.27% <ø> (ø)
crypto 49.16% <ø> (ø)
dids 80.71% <93.33%> (+0.20%) ⬆️
common 65.21% <ø> (ø)

Copy link
Contributor

@jiyoontbd jiyoontbd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm generally more in favor of this PR than #311 , with a couple caveats:

the original issue #310 is wanting a DX that allows a service to be added and not a whole new list of services to be provided to be replaced. whether under the hood a whole new did doc is created should be irrelevant to the client, imo.

in this PR, i'd also like to see removal of deleteService() and clearService() as that was not in the scope of #310 , and according to #311 (comment) we have a bit more thinking to do wrt how to treat update() as a whole.

* @return A new `BearerDid` instance with the updated DID Document.
*/
public fun deleteService(serviceId: String): BearerDid {
val updatedServices = document.service?.filter { it.id != serviceId } ?: emptyList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i don't find the serviceId, i nuke the whole list of services?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, i'm blind. if service is null then i get an empty list

dids/src/test/kotlin/web5/sdk/dids/did/BearerDidTest.kt Outdated Show resolved Hide resolved
@angiejones
Copy link
Member

i like this approach

@michaelneale
Copy link
Author

ok, let me tighten it up to just have add - as per @jiyoontbd comment as that keeps it focussed, I like it.

@michaelneale
Copy link
Author

@jiyoontbd PTAL again

Comment on lines +65 to +76
/**
* Adds a new service to the DID Document and returns a new `BearerDid` instance with the updated document.
*
* @param service The service to add to the DID Document.
* @return A new `BearerDid` instance with the updated DID Document.
*/
public fun addService(service: Service): BearerDid {
val updatedServices = document.service?.toMutableList() ?: mutableListOf()
updatedServices.add(service)
val updatedDocument = createUpdatedDocument(updatedServices)
return BearerDid(uri, did, keyManager, updatedDocument)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense for addService to be a method on DidDocument? that's what we've done in go and dart.

this method is helpful for building did docs in general. examples here and here. same usage exists in go as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would only work if the service was mutable (like it is in other places) - otherwise currently, has to return a new did (with it added to the doc) OR you need to return a new doc and then update the doc in the did (which returns a new did) if sticking with immutable approach in kotlin (correct me if wrong).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie, you would do blah.document.addService()... but it wouldn't change document in place but return a new document as List is immutable (can extend to other things that may want to mutate).

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so - we could change them to be mutable lists?

@jiyoontbd
Copy link
Contributor

hey @michaelneale !

ok, so after some discussion, i'd like to propose that we close this PR for now, and address the issue #310 once we hold some design discussions on how exactly one performs a DID update operation.

the reason being is that even if we have addService() implemented, this method would become tech debt quickly because it isn't considering how each did method handles updates.

the core issue here is that we're only mutating our own BearerDid abstraction by using this method. however, adding service (or updating any part of a did) should have downstream actions that we need to consider for each did method (did:dht handles updates differently than did:jwk, for example)

i've written about this a bit more as an issue in web5-spec. let me know if you have any questions! TBD54566975/web5-spec#157

@michaelneale
Copy link
Author

makes sense to me @jiyoontbd! - will close this (maybe keep the branch around temporarily just in case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants