Files
Aislo/B06_Section/B06_Section_Api_Context.ts
T
eomsangdonandClaude Opus 5.5 a6a1b92132 refactor(472-2 2-B 걷어내기): B06 안 쓰는 길 지움 · 서버 Node 묶음 화면 · 세션 끌림 정리
- POST /sections/{r}/cross-design 엔드포인트 · CrossDesignResponse(파이썬 · TS) · CrossDesignRequest(TS) · TS computeCrossDesign 지움 — 부름 0(파이썬 CrossDesignRequest 는 test_316 이 써서 둠)
- 바깥 부름 0 export 지움 — readCrossDesignChoice · currentStationScope · culvertRequiredHalfWidth · calculateYScale · mountSectionStructureMenu · Culvert_Const 다섯 · outletSlopeFactory
- PIPE_DISPLAY_NAME = common_util_structure_catalog 로 — Section_Common 이 IrregularStations(화면) 안 끔
- Api_Fetch 세션 · 사진첩 창구 = 새 B06_Section_Api_Context.ts(fetchSectionContext · fetchCurrentRouteId · seedStandardCross) — Api_Fetch 가 b_page_state · Profile_History 안 끔
- 시험 경로 따라 고침(seedStandardCross 글 검사 · 헬퍼 흉내 모듈 이름 · 라우터 목록 시험)
- 위키 줄 번호 · 지운 엔드포인트 줄

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 08:54:41 +09:00

59 lines
3.1 KiB
TypeScript

/* =============================================================================
* B06_Section_Api_Context.ts
* 종횡단 설정값(`GET …/sections/context`)의 **세션 캐시 창구** — 화면 쪽.
*
* `B06_Section_Api_Fetch.ts` 에서 갈라냄(472-2) — 서버 Node 묶음이 Api_Fetch 를 끌어도
* 세션(`b_page_state`) · 되돌리기 사진첩(`Profile_History`)을 함께 끌지 않게.
* ========================================================================== */
import { clearState, readState, stateKey, writeState } from "../A00_Common/b_page_state";
import { seedPageHistory } from "../B05_Profile/B05_Profile_UI_Profile_History";
import { requestSectionContext } from "./B06_Section_Api_Fetch";
import type { SectionContextResponse } from "./B06_Section_Api_Types";
/** 최신 확정 경로와 B04 확정값, config 기반 생성 기본값을 조회한다. */
/** 종횡단 설정값 — ④ 계산 결과라 세션에 담아 두고 화면을 오갈 때마다 다시 묻지 않는다
* (2026-09-06 호출 정리). 노선이 바뀌면 `clearSectionContextCache` 로 버린다. */
export async function fetchSectionContext(projectId: string): Promise<SectionContextResponse> {
const cached = readState<SectionContextResponse>("section-context", projectId);
if (cached) return seedStandardCross(projectId, cached);
const fresh = await requestSectionContext(projectId);
writeState("section-context", fresh, projectId);
return seedStandardCross(projectId, fresh);
}
/** 서버가 지금 보는 노선 id — 세션 캐시를 건너뛰고 묻는다. [저장] · [확정] 앞에서 화면이 쥔
* 노선과 대조한다(PLAN 76-1). 받은 설정값으로 캐시도 새로 둔다. */
export async function fetchCurrentRouteId(projectId: string): Promise<number | null> {
const fresh = await requestSectionContext(projectId);
writeState("section-context", fresh, projectId);
return fresh.route_id;
}
/**
* 저장된 표준 횡단면을 **세션이 비어 있을 때만** 채운다(2026-09-07).
*
* 브라우저 횡단 계산은 `세션 ?? config 기본값` 으로 서는데, 표준단면 세션값은 그 탭에서만
* 산다. 그래서 **탭을 새로 열면** 화면은 config 기본값으로, 서버는 저장분으로 계산해
* 같은 측점이 갈렸다(실측 — 용화 route 169 저장분은 암반 횡단경사 **5%**·측구 상단폭
* **0.9m**, config 기본값은 **3%**·**0.69m**).
*
* 여기가 두 화면(B05·B06)이 함께 지나는 유일한 자리라 이 한 곳에서 채운다. 사용자가
* 그 탭에서 고친 값이 있으면 **건드리지 않는다** — 초안이 언제나 우선이다.
*/
function seedStandardCross(
projectId: string,
context: SectionContextResponse,
): SectionContextResponse {
const stored = context.stored_standard_cross_section;
if (stored && readState<unknown>("std-cross", projectId) === null) {
writeState("std-cross", stored, projectId);
seedPageHistory(stateKey("std-cross", projectId)); // 씨앗 — 되돌리기 걸음 아님(364-1)
}
return context;
}
export function clearSectionContextCache(projectId: string): void {
clearState("section-context", projectId);
}