Add local document JSON state commands
This commit is contained in:
parent
b102e07204
commit
e039a4f81f
11 changed files with 153 additions and 10 deletions
|
|
@ -9,7 +9,7 @@ use geth_control::{
|
|||
};
|
||||
use geth_crypto::AgentKey;
|
||||
use geth_db::DbResource;
|
||||
use geth_document::DocumentResource;
|
||||
use geth_document::{DocumentResource, DocumentState};
|
||||
use geth_iroh::{EndpointStatus, GethIrohConfig, GethIrohEndpoint, GethRelayMode};
|
||||
use geth_keychain::{KeychainOp, KeychainOpKind};
|
||||
use geth_kv::{KvEntry, KvResource};
|
||||
|
|
@ -72,6 +72,8 @@ pub enum NodeError {
|
|||
InvalidDocumentName(String),
|
||||
#[error("document not found: {0}")]
|
||||
DocumentNotFound(String),
|
||||
#[error("document error: {0}")]
|
||||
Document(#[from] geth_document::DocumentError),
|
||||
#[error("resource not found: {0}")]
|
||||
ResourceNotFound(String),
|
||||
#[error("secrets error: {0}")]
|
||||
|
|
@ -826,6 +828,29 @@ pub fn handle_request(
|
|||
document: document_resource_from_stored(&stored),
|
||||
})
|
||||
}
|
||||
ControlRequest::DocumentSet { name, state_json } => {
|
||||
geth_document::validate_document_name(&name)
|
||||
.map_err(|_| NodeError::InvalidDocumentName(name.clone()))?;
|
||||
let mut stored = store
|
||||
.get_document_resource_by_name(&name)?
|
||||
.ok_or_else(|| NodeError::DocumentNotFound(name.clone()))?;
|
||||
stored.state_json = geth_document::normalize_document_state(&state_json)?;
|
||||
stored.updated_at_ms = geth_store::now_ms();
|
||||
store.insert_document_resource(&stored)?;
|
||||
Ok(ControlResponse::DocumentSet {
|
||||
state: document_state_from_stored(&stored),
|
||||
})
|
||||
}
|
||||
ControlRequest::DocumentGet { name } => {
|
||||
geth_document::validate_document_name(&name)
|
||||
.map_err(|_| NodeError::InvalidDocumentName(name.clone()))?;
|
||||
let stored = store
|
||||
.get_document_resource_by_name(&name)?
|
||||
.ok_or_else(|| NodeError::DocumentNotFound(name.clone()))?;
|
||||
Ok(ControlResponse::DocumentGet {
|
||||
state: document_state_from_stored(&stored),
|
||||
})
|
||||
}
|
||||
ControlRequest::PubsubPub { topic, message } => {
|
||||
geth_pubsub::validate_topic(&topic)?;
|
||||
geth_pubsub::validate_message(&message)?;
|
||||
|
|
@ -938,6 +963,14 @@ fn document_resource_from_stored(stored: &StoredDocumentResource) -> DocumentRes
|
|||
}
|
||||
}
|
||||
|
||||
fn document_state_from_stored(stored: &StoredDocumentResource) -> DocumentState {
|
||||
DocumentState {
|
||||
document: document_resource_from_stored(stored),
|
||||
state_json: stored.state_json.clone(),
|
||||
updated_at: UnixMillis(stored.updated_at_ms),
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_resource_exists(store: &Store, resource_id: &str) -> Result<(), NodeError> {
|
||||
if store
|
||||
.list_resources()?
|
||||
|
|
|
|||
Loading…
Reference in a new issue