feat: 完成 rust cutover phase 8 收口
This commit is contained in:
@@ -96,7 +96,36 @@ export type DocumentBridgeMutationRequest<
|
||||
args: TArgs;
|
||||
};
|
||||
|
||||
export type DocumentBridgeQueryRequest<
|
||||
TArgs extends Record<string, unknown> = Record<string, unknown>,
|
||||
> = {
|
||||
functionName: string;
|
||||
deploymentId: string | null;
|
||||
projectId: string | null;
|
||||
workspaceId: string | null;
|
||||
requestId: string;
|
||||
traceId: string;
|
||||
actorId: string;
|
||||
payloadJson: string;
|
||||
args: TArgs;
|
||||
};
|
||||
|
||||
const DOCUMENT_BRIDGE_QUERY_FUNCTIONS = {
|
||||
"documents.content.get": "documents:getContent",
|
||||
"documents.meta.get": "documents:getMeta",
|
||||
"blocks.get": "documents:getContent",
|
||||
} as const satisfies Record<string, string>;
|
||||
|
||||
const DOCUMENT_BRIDGE_MUTATION_FUNCTIONS = {
|
||||
"documents.create": "documents:createWithParentReference",
|
||||
"documents.move": "documents:move",
|
||||
"documents.delete": "documents:softDelete",
|
||||
"documents.restore": "documents:restore",
|
||||
"documents.duplicate": "documents:duplicateWithMindmaps",
|
||||
"documents.copy_tree": "documents:copyTree",
|
||||
"blocks.patch": "documents:updateContent",
|
||||
"blocks.move": "documents:updateContent",
|
||||
"blocks.embed": "documents:updateContent",
|
||||
"documents.title.update": "documents:updateTitle",
|
||||
"documents.stats.update": "documents:updateStats",
|
||||
"documents.options.update": "documents:updateOptions",
|
||||
@@ -303,6 +332,28 @@ function buildDocumentCommandPayloadJson(input: {
|
||||
});
|
||||
}
|
||||
|
||||
function buildDocumentQueryPayloadJson(input: {
|
||||
context: BridgeContext;
|
||||
queryName: string;
|
||||
workspaceId: string | null;
|
||||
}): string {
|
||||
return JSON.stringify({
|
||||
kind: "query",
|
||||
name: input.queryName,
|
||||
request_id: input.context.requestId,
|
||||
trace_id: input.context.traceId,
|
||||
deployment_id: input.context.deploymentId,
|
||||
project_id: input.context.projectId,
|
||||
workspace_id: input.workspaceId,
|
||||
tenant_id: input.context.tenantId,
|
||||
actor_id: input.context.actor.actorId,
|
||||
source: {
|
||||
channel: input.context.source.channel,
|
||||
client: input.context.source.client,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function buildDocumentBridgeMutationRequest<
|
||||
TPayload,
|
||||
TArgs extends Record<string, unknown>,
|
||||
@@ -333,6 +384,47 @@ export function buildDocumentBridgeMutationRequest<
|
||||
};
|
||||
}
|
||||
|
||||
function getDocumentBridgeQueryFunctionName(queryName: string): string {
|
||||
const functionName =
|
||||
DOCUMENT_BRIDGE_QUERY_FUNCTIONS[
|
||||
queryName as keyof typeof DOCUMENT_BRIDGE_QUERY_FUNCTIONS
|
||||
];
|
||||
if (!functionName) {
|
||||
throw new DocumentBridgeError(
|
||||
`未注册文档 bridge query: ${queryName}`,
|
||||
500,
|
||||
"TRANSPORT_ERROR",
|
||||
);
|
||||
}
|
||||
return functionName;
|
||||
}
|
||||
|
||||
export function buildDocumentBridgeQueryRequest<
|
||||
TPayload,
|
||||
TArgs extends Record<string, unknown>,
|
||||
>(input: {
|
||||
context: BridgeContext;
|
||||
envelope: QueryEnvelope<TPayload>;
|
||||
mapConvexArgs: (payload: TPayload) => TArgs;
|
||||
}): DocumentBridgeQueryRequest<TArgs> {
|
||||
const workspaceId = input.context.workspaceId ?? null;
|
||||
return {
|
||||
functionName: getDocumentBridgeQueryFunctionName(input.envelope.name),
|
||||
deploymentId: input.context.deploymentId,
|
||||
projectId: input.context.projectId,
|
||||
workspaceId,
|
||||
requestId: input.context.requestId,
|
||||
traceId: input.context.traceId,
|
||||
actorId: input.context.actor.actorId,
|
||||
payloadJson: buildDocumentQueryPayloadJson({
|
||||
context: input.context,
|
||||
queryName: input.envelope.name,
|
||||
workspaceId,
|
||||
}),
|
||||
args: input.mapConvexArgs(input.envelope.payload),
|
||||
};
|
||||
}
|
||||
|
||||
export async function executeDocumentBridgeMutationRequest<
|
||||
TArgs extends Record<string, unknown>,
|
||||
TResult,
|
||||
|
||||
Reference in New Issue
Block a user