Files
Jyotisha/frontend/src/lib/chart-view-client.ts
T
jesse-ux 5a8328e591
Independent Staging Quality Gate / validate (push) Successful in 27m22s
Independent Staging Quality Gate / publish (push) Canceled after 47s
fix(web): paint the chart page shell before engine calls
BUG-715/716/717: typed engine failures with logs and split copy, natal-only open, on-demand tabs, 10s timeout, in-memory cache, no speed-promise eyebrow.
2026-09-15 22:51:15 +08:00

26 lines
1.0 KiB
TypeScript

import { chartViewResponseSchema, type ChartViewResponse } from "./chart-view-contract.ts";
import type { ChartViewLayer } from "./chart-view-engine.ts";
export async function fetchChartView(input: {
layers?: readonly ChartViewLayer[];
signal?: AbortSignal;
}): Promise<{ httpStatus: number; body: ChartViewResponse | null }> {
const query = input.layers?.length ? `?layers=${input.layers.join(",")}` : "";
const response = await fetch(`/api/chart-view${query}`, {
credentials: "same-origin",
headers: { Accept: "application/json" },
cache: "no-store",
signal: input.signal,
});
let json: unknown = null;
try {
json = await response.json();
} catch (error) {
const errorName = error instanceof Error ? error.name : "Error";
console.warn("chart_view_client_bad_payload", { errorName, httpStatus: response.status });
return { httpStatus: response.status, body: null };
}
const parsed = chartViewResponseSchema.safeParse(json);
return { httpStatus: response.status, body: parsed.success ? parsed.data : null };
}