feat: 收口 tree-first graph 主链与前端测试修复
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
use crate::app::{AppConfig, AppState};
|
||||
use crate::app::AppState;
|
||||
use crate::context::RequestContext;
|
||||
use crate::error::WebError;
|
||||
use crate::routes::query_support::{
|
||||
execute_runtime_query_against_data, fetch_query_data_via_convex, resolve_effective_workspace_id,
|
||||
resolve_effective_workspace_id,
|
||||
};
|
||||
use crate::routes::snapshot_support::{
|
||||
execute_kernel_query, load_projection_snapshot, load_sidebar_dataset, subtree_query,
|
||||
ProjectionSnapshotSpec,
|
||||
};
|
||||
use axum::extract::{Extension, Query, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::Json;
|
||||
use bridge_runtime::RuntimeQueryEnvelopeWire;
|
||||
use core_protocol::{KernelGraphDirection, KernelNodeType, KernelProjectionKind};
|
||||
use core_protocol::{KernelGraphDirection, KernelProjectionKind};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@@ -43,38 +47,6 @@ pub struct KernelGraphQuery {
|
||||
pub max_depth: Option<u32>,
|
||||
}
|
||||
|
||||
fn sidebar_dataset_query(workspace_id: &str) -> RuntimeQueryEnvelopeWire {
|
||||
RuntimeQueryEnvelopeWire {
|
||||
name: "sidebar.dataset.list".into(),
|
||||
payload: json!({
|
||||
"workspaceId": workspace_id,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_sidebar_dataset(
|
||||
config: &AppConfig,
|
||||
context: &RequestContext,
|
||||
workspace_id: &str,
|
||||
) -> Result<Value, WebError> {
|
||||
fetch_query_data_via_convex(
|
||||
config,
|
||||
context,
|
||||
Some(workspace_id),
|
||||
sidebar_dataset_query(workspace_id),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn execute_kernel_query(
|
||||
context: &RequestContext,
|
||||
workspace_id: &str,
|
||||
query: RuntimeQueryEnvelopeWire,
|
||||
dataset: Value,
|
||||
) -> Result<Value, WebError> {
|
||||
execute_runtime_query_against_data(context, Some(workspace_id), query, dataset)
|
||||
}
|
||||
|
||||
fn ok_response(context: &RequestContext, result: Value) -> (StatusCode, Json<Value>) {
|
||||
(
|
||||
StatusCode::OK,
|
||||
@@ -95,26 +67,19 @@ pub async fn project_sidebar(
|
||||
let effective_workspace_id =
|
||||
resolve_effective_workspace_id(&context, query.workspace_id.as_deref(), true)?
|
||||
.expect("workspace_required 已确保存在");
|
||||
let dataset = load_sidebar_dataset(state.config(), &context, &effective_workspace_id).await?;
|
||||
let result = execute_kernel_query(
|
||||
let snapshot = load_projection_snapshot(
|
||||
state.config(),
|
||||
&context,
|
||||
&effective_workspace_id,
|
||||
RuntimeQueryEnvelopeWire {
|
||||
name: "kernel.project_view".into(),
|
||||
payload: json!({
|
||||
"projection": KernelProjectionKind::SidebarTree,
|
||||
"workspaceId": effective_workspace_id,
|
||||
"rootNodeId": query.root_node_id,
|
||||
"depth": query.depth,
|
||||
"includeEdges": true,
|
||||
"includeContent": false,
|
||||
"nodeTypes": [KernelNodeType::Page],
|
||||
}),
|
||||
&ProjectionSnapshotSpec {
|
||||
workspace_id: &effective_workspace_id,
|
||||
root_node_id: query.root_node_id.as_deref(),
|
||||
depth: query.depth,
|
||||
projection: KernelProjectionKind::SidebarTree,
|
||||
},
|
||||
dataset,
|
||||
)?;
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(ok_response(&context, result))
|
||||
Ok(ok_response(&context, snapshot.projection))
|
||||
}
|
||||
|
||||
pub async fn subtree(
|
||||
@@ -129,16 +94,7 @@ pub async fn subtree(
|
||||
let result = execute_kernel_query(
|
||||
&context,
|
||||
&effective_workspace_id,
|
||||
RuntimeQueryEnvelopeWire {
|
||||
name: "kernel.subtree.get".into(),
|
||||
payload: json!({
|
||||
"workspaceId": effective_workspace_id,
|
||||
"rootNodeId": query.root_node_id,
|
||||
"depth": query.depth,
|
||||
"includeEdges": true,
|
||||
"nodeTypes": [KernelNodeType::Page],
|
||||
}),
|
||||
},
|
||||
subtree_query(&effective_workspace_id, &query.root_node_id, query.depth),
|
||||
dataset,
|
||||
)?;
|
||||
Ok(ok_response(&context, result))
|
||||
|
||||
Reference in New Issue
Block a user