-
Notifications
You must be signed in to change notification settings - Fork 10
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
add update for did #311
add update for did #311
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
==========================================
- Coverage 73.58% 73.20% -0.39%
==========================================
Files 45 45
Lines 2162 2191 +29
Branches 402 413 +11
==========================================
+ Hits 1591 1604 +13
- Misses 376 383 +7
- Partials 195 204 +9
|
.serviceEndpoint(listOf("https://example.com/")) | ||
.build() | ||
|
||
val newServiceList = existingBearerDid.document.service.orEmpty() + serviceToAdd |
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.
So I think with the current impl you'll add the existing service again with this line, because you add whatever is passed in options to the existing service list? did I read the impl wrong
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.
hrm - I think that is my mistake, intention wasn't to only add but replace - let me add better tests and fix if needed before merging
This is great thanks @michaelneale ! one thing I'm wondering is if we should just make service list mutable if that is expected usage instead of trying to preserve immutability which is typical in Kotlin. @angiejones what other things inside a did are expected to be liable to mutation after initial creation, besides service? |
@jiyoontbd yeah - I wasn't sure about idioms around mutability (as a rule immutable is ideal as long as DX is good enough as it eliminates a whole class of bugs). |
PTAL @jiyoontbd again regarding your pertinent comments |
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.
One smol comment
* publishing during the update. | ||
* @return The updated [BearerDid] instance. | ||
*/ | ||
public fun update(bearerDid: BearerDid, options: CreateDidDhtOptions): BearerDid { |
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.
Thoughts on calling the option type passed in here UpdateDidDhtOptions
?
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.
@jiyoontbd great idea - added a public typealias for that reason (it is the same type) but with its own docs to make semantics clear. PTAL
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.
Cool. If we can call .Create() with CreateOptions and .Update with UpdateOptions that would be ideal
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.
yep, done
val updatedServices = options.services ?: existingDidDocument.service | ||
val updatedControllers = options.controllers ?: existingDidDocument.controller | ||
val updatedAlsoKnownAses = options.alsoKnownAses ?: existingDidDocument.alsoKnownAs |
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 you might have a bug here with how you're using the Elvis operator (👑 🎸) (?:
). The UpdateDidDhtOptions
has docs:
* @property services A list of [Service]s to add to the DID Document.
// ...
* @property controllers A list of controller DIDs to add to the DID Document.
* @property alsoKnownAses A list of also known as identifiers to add to the DID Document.
As in, those values are additive, but the Elvis operator is a null coalescing operation, so imagine the existingDidDocument.service
has service A, and then options.services
has service B & C, then this would update the did:dht's DID Document to now have only services B & C (and not A), but the expected behavior according to the doc comments would be to have services A, B & C.
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.
@KendallWeihe ah - that is a bug in the docs, it isn't adding now, but replacing (ie code is right, comments are not). will fix. thanks!
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.
Hmm, is the desired behavior to replace completely or add a new service to an existing list?
If it's the former, is this because you are prioritizing immutability?
I am not certain that going with former approach is a good dx. If I just want to add a service, shouldn't the update method do the work internally of:
- check if service method is empty
- if not empty, turn list mutable
- add to list
- make the list immutable again
?
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.
yeah desired is to entirely replace it (at least as it stands currently) which preserves immutability but keeps it relatively simple (but alternative means having add/remove etc things explicitly in there for things that are lists, perhaps add/remove for each thing you may want to change and separate methods?)
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.
yeah desired is to entirely replace it
I agree with this approach, if only for the sake of pragmatism ("crawl before walk")
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.
one comment with respect to a bug, but I trust your judgement to merge once addressed, everything else lgtm!
good to merge this one yet, @michaelneale? |
@angiejones I think @jiyoontbd wanted to have a think over it and if we go this approach or move to a mutable approach or perhaps specific functions for everything we want to update (vs an Update/Create options class). |
@jiyoontbd would you like me to (seperately) try a mutable take on this change that lets add/remove services? (and other things, perhaps) to see what it feels like? |
hmm so thinking about this a bit: ultimately, publishing updates to a pre-existing Given ^, i see where you were headed with your If we take an if if tbh, both seem a bit painful to use. Would be helpful to think through 1 use-case for this feature to help guide the design. here's one
^ requires:
if we take the patching approach or even a subset thereof (
|
either way, if there is a need for updating generally speaking, updating did docs is certainly something we'll want to consider broadly as the need will inevitably arise for us and others |
@mistermoe no not blocking, so can iterate here. I like the update + patch approach (this one is close to that but does require you to pass in full things to replace it with). |
It already has. fortunately it was easier for the PFI to do so in JS. |
I think I will close this once #313 is blessed (as it is minimalist and doesn't block off any future patterns but solves the issue). |
Overview
For bug: #310
need a way to easily modify a did or document. This uses the (I believe) idiomatic kotlin way which keeps the data objects immutable.