Implement the in-process structured entry editor

Closes #21
This commit is contained in:
Hermes Agent
2026-08-10 07:22:55 +00:00
parent cf7a6216ac
commit b503de8b2e
14 changed files with 1547 additions and 37 deletions

View File

@@ -262,6 +262,33 @@ impl EntryDocument {
.ok_or(DocumentError::UnknownField { id })
}
/// Replace only a structured field's value while preserving its storage-
/// supplied name and syntax.
pub fn replace_field_value(
&mut self,
id: EntryFieldId,
value: Vec<u8>,
) -> Result<(), DocumentError> {
let field = self.field(id).ok_or(DocumentError::UnknownField { id })?;
let draft = match field.metadata().kind() {
EntryFieldKind::OtpUri => EntryFieldDraft::otp_uri(value)?,
EntryFieldKind::Password | EntryFieldKind::Note | EntryFieldKind::Blank => {
EntryFieldDraft::line(value)?
}
EntryFieldKind::Username
| EntryFieldKind::Email
| EntryFieldKind::Url
| EntryFieldKind::Field => EntryFieldDraft::field(
field
.metadata()
.name()
.ok_or(DocumentError::InvalidFieldName)?,
value,
)?,
};
self.update(id, draft)
}
pub fn conflict_token(&self) -> DocumentConflictToken {
self.conflict_token
}
@@ -424,6 +451,26 @@ impl<'a> EntryDocumentService<'a> {
committer,
)?)
}
/// Save without consuming the document, allowing an in-process editor to
/// present a conflict or encryption failure and retain the user's draft.
pub fn save_recoverable(
&self,
document: &EntryDocument,
signing: Option<&SigningPolicy>,
committer: &mut impl EntryCommitter,
) -> Result<WriteOutcome, DocumentError> {
let replacement = document.serialize();
Ok(
VaultWriter::new(self.repository, self.keys).finish_edit_recoverable(
&document.session,
replacement,
"IronStorage structured editor",
signing,
committer,
)?,
)
}
}
#[derive(Debug)]