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

Change document metadata created, updated to be optional #753

Merged
merged 8 commits into from
Mar 29, 2022

Conversation

abdulmth
Copy link
Contributor

@abdulmth abdulmth commented Mar 22, 2022

Description of change

Make the created and updated timestamps in the DID Document Metadata optional fields.

Links to any relevant issues

fixes issue #731

Type of change

Add an x to the boxes that are relevant to your changes.

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

@abdulmth abdulmth self-assigned this Mar 22, 2022
@abdulmth abdulmth added Wasm Related to Wasm bindings. Becomes part of the Wasm changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog labels Mar 22, 2022
@abdulmth abdulmth added this to the v0.5 Features milestone Mar 22, 2022
@abdulmth abdulmth linked an issue Mar 22, 2022 that may be closed by this pull request
@abdulmth abdulmth force-pushed the chore/make-created-and-updated-optional branch from 6a2fd8c to d3c80ea Compare March 28, 2022 15:24
Abdulrahim Al Methiab added 5 commits March 28, 2022 17:39
…-updated-optional

# Conflicts:
#	examples/low-level-api/diff_chain.rs
#	examples/low-level-api/resolve_history.rs
@abdulmth abdulmth requested a review from cycraig March 28, 2022 16:27
Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

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

Looks good but a unit test or two for the null -> None deserialization behaviour would be appreciated in diff_iota_document_metadata, since that could easily break in the future with no-one noticing.

Edit: PR changelog title suggestion

Change document metadata `created`, `updated` to be optional

Comment on lines 24 to 35
#[serde(
skip_serializing_if = "Option::is_none",
deserialize_with = "double_option",
default = "Default::default"
)]
created: Option<DiffOption<Timestamp>>,
#[serde(
skip_serializing_if = "Option::is_none",
deserialize_with = "double_option",
default = "Default::default"
)]
updated: Option<DiffOption<Timestamp>>,
Copy link
Contributor

@cycraig cycraig Mar 28, 2022

Choose a reason for hiding this comment

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

Nit: Default::default is redundant for two reasons: serde(default) calls Default::default if unspecified, and Option is a special case in serde which defaults to None regardless.

Edit: updated to just omit Default::default rather than entirely.

Suggested change
#[serde(
skip_serializing_if = "Option::is_none",
deserialize_with = "double_option",
default = "Default::default"
)]
created: Option<DiffOption<Timestamp>>,
#[serde(
skip_serializing_if = "Option::is_none",
deserialize_with = "double_option",
default = "Default::default"
)]
updated: Option<DiffOption<Timestamp>>,
#[serde(
default,
deserialize_with = "deserialize_double_option_diif",
skip_serializing_if = "Option::is_none",
)]
created: Option<DiffOption<Timestamp>>,
#[serde(
default,
deserialize_with = "deserialize_double_option_diif",
skip_serializing_if = "Option::is_none",
)]
updated: Option<DiffOption<Timestamp>>,

Copy link
Contributor

Choose a reason for hiding this comment

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

I stand corrected. default is required here (likely because of deserialize_with?) but the Default::default can be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, without default a diff message without an update to both created and updated will not deserialize correctly. I added a unit test for this case.

Comment on lines 42 to 43
// Workaround for deserialize 'null' as `Some(DiffOption::None)` instead of `None`.
fn double_option<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: name and comment.

Suggested change
// Workaround for deserialize 'null' as `Some(DiffOption::None)` instead of `None`.
fn double_option<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error>
// Workaround for deserializing 'null' as `Some(DiffOption::None)` instead of `None`,
// otherwise it's impossible to unset the option. Only works if `Option::None` is
// skipped during serialization.
fn deserialize_double_option_diif<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error>

@abdulmth abdulmth changed the title [WIP] Make created, updated optional Change document metadata created, updated to be optional Mar 28, 2022
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the changes.

identity-iota-core/src/diff/diff_iota_document_metadata.rs Outdated Show resolved Hide resolved
Co-authored-by: Craig Bester <craig.bester@iota.org>
@abdulmth abdulmth merged commit 0d68cdf into dev Mar 29, 2022
@abdulmth abdulmth deleted the chore/make-created-and-updated-optional branch March 29, 2022 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request] Make created, updated optional
3 participants