feat: cut over rust web main shell
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
type SidebarDatasetListQueryResult,
|
||||
} from "@/lib/sidebar-data";
|
||||
|
||||
export type TreeStreamKind = "snapshot" | "delta" | "resync";
|
||||
export type TreeStreamKind = "snapshot" | "delta" | "resync" | "heartbeat";
|
||||
|
||||
export interface TreeStreamEnvelope {
|
||||
stream: string;
|
||||
@@ -16,7 +16,7 @@ export interface TreeStreamEnvelope {
|
||||
data: unknown;
|
||||
}
|
||||
|
||||
const TREE_STREAM_KINDS = new Set<TreeStreamKind>(["snapshot", "delta", "resync"]);
|
||||
const TREE_STREAM_KINDS = new Set<TreeStreamKind>(["snapshot", "delta", "resync", "heartbeat"]);
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||
@@ -69,7 +69,7 @@ export function buildWorkspaceTreeStreamUrl(
|
||||
): string {
|
||||
const baseOrigin =
|
||||
typeof window !== "undefined" ? window.location.origin : "http://127.0.0.1:3000";
|
||||
const url = new URL("/api/mnote-web/stream", baseOrigin);
|
||||
const url = new URL("/api/tree/events", baseOrigin);
|
||||
url.searchParams.set("workspaceId", workspaceId.trim());
|
||||
if (typeof cursor === "string" && cursor.trim()) {
|
||||
url.searchParams.set("cursor", cursor.trim());
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("tree-stream/protocol", () => {
|
||||
expect(
|
||||
buildWorkspaceTreeStreamUrl(" ws_1 ", "evt_9"),
|
||||
).toBe(
|
||||
"http://127.0.0.1:3000/api/mnote-web/stream?workspaceId=ws_1&cursor=evt_9",
|
||||
"http://127.0.0.1:3000/api/tree/events?workspaceId=ws_1&cursor=evt_9",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ describe("tree-stream/protocol", () => {
|
||||
});
|
||||
expect(
|
||||
buildWorkspaceTreeStreamUrl("ws_1", null),
|
||||
).toBe("http://127.0.0.1:3000/api/mnote-web/stream?workspaceId=ws_1");
|
||||
).toBe("http://127.0.0.1:3000/api/tree/events?workspaceId=ws_1");
|
||||
});
|
||||
|
||||
it("解析 snapshot / delta / resync 协议消息", () => {
|
||||
@@ -85,6 +85,21 @@ describe("tree-stream/protocol", () => {
|
||||
projection: "sidebar_tree",
|
||||
});
|
||||
|
||||
expect(
|
||||
parseTreeStreamMessage({
|
||||
eventType: "heartbeat",
|
||||
rawData: JSON.stringify({
|
||||
kind: "heartbeat",
|
||||
workspaceId: "ws_1",
|
||||
cursor: "evt_3",
|
||||
}),
|
||||
}),
|
||||
).toMatchObject({
|
||||
kind: "heartbeat",
|
||||
workspaceId: "ws_1",
|
||||
cursor: "evt_3",
|
||||
});
|
||||
|
||||
expect(
|
||||
parseTreeStreamMessage({
|
||||
eventType: "delta",
|
||||
|
||||
Reference in New Issue
Block a user