fix: relink rust web tree editor runtime
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::app::AppConfig;
|
||||
use crate::context::RequestContext;
|
||||
use crate::error::WebError;
|
||||
use base64::Engine;
|
||||
use bridge_runtime::{
|
||||
build_runtime_command_artifact_plan, RuntimeBridgeContextWire, RuntimeCommandArtifactPlan,
|
||||
RuntimeCommandEnvelopeWire, RuntimeCommandExecutionPlan, RuntimeQueryExecutionPlan,
|
||||
@@ -9,7 +10,6 @@ use serde_json::{json, Value};
|
||||
use std::fs;
|
||||
use std::time::Duration;
|
||||
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||
use base64::Engine;
|
||||
|
||||
const HEADER_REQUEST_ID: &str = "x-request-id";
|
||||
const HEADER_TRACE_ID: &str = "x-trace-id";
|
||||
@@ -98,8 +98,8 @@ fn build_authorization(config: &AppConfig, context: &RequestContext) -> Result<S
|
||||
"name": config.dev_user_name,
|
||||
"email": config.dev_user_email,
|
||||
});
|
||||
let identity_encoded = base64::engine::general_purpose::STANDARD
|
||||
.encode(identity.to_string().as_bytes());
|
||||
let identity_encoded =
|
||||
base64::engine::general_purpose::STANDARD.encode(identity.to_string().as_bytes());
|
||||
Ok(format!("Convex {admin_key}:{identity_encoded}"))
|
||||
}
|
||||
|
||||
@@ -332,6 +332,26 @@ pub async fn execute_sidebar_dataset_query(
|
||||
execute_convex_query_plan(config, context, plan).await
|
||||
}
|
||||
|
||||
fn convex_command_args_for_plan(plan: &RuntimeCommandExecutionPlan) -> Value {
|
||||
let mut args = plan.args_json.clone();
|
||||
if matches!(
|
||||
plan.command_name.as_str(),
|
||||
"documents.save" | "page.body.save"
|
||||
) {
|
||||
if let Value::Object(map) = &mut args {
|
||||
// 当前自托管 Convex 的 documents:updateContent 仍是 legacy validator。
|
||||
// Rust plan 保留正式事件契约,但发送给 legacy mutation 时只传它实际接受的字段。
|
||||
map.remove("editorDocument");
|
||||
map.remove("tiptapDocument");
|
||||
map.remove("streamDeltaHint");
|
||||
map.remove("domainEventHint");
|
||||
map.remove("domainEventPlan");
|
||||
map.remove("domainEventPlans");
|
||||
}
|
||||
}
|
||||
args
|
||||
}
|
||||
|
||||
pub async fn execute_convex_command_plan(
|
||||
config: &AppConfig,
|
||||
context: &RequestContext,
|
||||
@@ -356,7 +376,7 @@ pub async fn execute_convex_command_plan(
|
||||
let payload = json!({
|
||||
"path": plan.function_name,
|
||||
"format": "convex_encoded_json",
|
||||
"args": [plan.args_json.clone()],
|
||||
"args": [convex_command_args_for_plan(plan)],
|
||||
});
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
@@ -712,11 +732,13 @@ pub async fn execute_convex_command_plan_with_artifacts(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::build_authorization;
|
||||
use super::{build_authorization, convex_command_args_for_plan};
|
||||
use crate::app::AppConfig;
|
||||
use crate::context::RequestContext;
|
||||
use axum::http::{HeaderMap, HeaderValue, Method, Uri};
|
||||
use base64::Engine;
|
||||
use bridge_runtime::RuntimeCommandExecutionPlan;
|
||||
use serde_json::json;
|
||||
|
||||
fn config() -> AppConfig {
|
||||
AppConfig {
|
||||
@@ -750,6 +772,45 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convex_command_args_strips_editor_runtime_fields_for_legacy_document_save() {
|
||||
let plan = RuntimeCommandExecutionPlan {
|
||||
command_name: "documents.save".into(),
|
||||
command_id: "cmd_1".into(),
|
||||
function_name: "documents:updateContent".into(),
|
||||
workspace_id: Some("ws_1".into()),
|
||||
request_id: "req_1".into(),
|
||||
trace_id: "trace_1".into(),
|
||||
actor_id: "actor_1".into(),
|
||||
idempotency_key: None,
|
||||
payload_json: "{}".into(),
|
||||
args_json: json!({
|
||||
"id": "doc_1",
|
||||
"content": [],
|
||||
"expectedRevision": 0,
|
||||
"conflictDetectionKey": "doc_1:0",
|
||||
"editorDocument": {"rootBlockIds": []},
|
||||
"tiptapDocument": {"type": "doc", "content": []},
|
||||
"streamDeltaHint": {"family": "tree"},
|
||||
"domainEventHint": {"eventType": "page.body.saved"},
|
||||
"domainEventPlan": {"eventType": "page.body.saved"},
|
||||
"domainEventPlans": [{"eventType": "page.body.saved"}],
|
||||
}),
|
||||
};
|
||||
|
||||
let args = convex_command_args_for_plan(&plan);
|
||||
|
||||
assert_eq!(
|
||||
args,
|
||||
json!({
|
||||
"id": "doc_1",
|
||||
"content": [],
|
||||
"expectedRevision": 0,
|
||||
"conflictDetectionKey": "doc_1:0",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_authorization_prefers_forwarded_authorization() {
|
||||
let mut headers = HeaderMap::new();
|
||||
|
||||
Reference in New Issue
Block a user