- 지움(부르는 곳 0 — 저장소 TS · cjs · py · html 다시 찾음): UI_Logic_Drive.ts(driveRun · autoFill) · UI_Logic_CalcPick.ts · UI_LogicLab_Pill.ts · .css - Logic_Api: runCalc · runText · fetchAuto · searchPrice · CalcAnswer · TextAnswer · TextLine · TextPiece 걷음 - LogicLab_Modal: 옛 재료 · 표 · 참조 · 글 모달 걷음 — 로직 열기 · headWord 만 남김(−550 줄) - Logic_Note.explain · Side.hasMasterJump · 죽은 CSS 다섯 · 글 키 29(옛 시험 계산 · 모달 · 알약) 걷음 - 시험: 지운 파일 글자만 보던 test_750_2(빈 파일 됨) · test_799_2 구동 시험 · test_734 알약 · 풍선 시험 지움 · helper_717_1 · test_717_1 의 /calc · /text · /logic/auto 화면 길 줄 걷음 - typecheck 0 · 관련 50 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
/* =============================================================================
|
|
* M01_MasterData_UI_Logic_Note.ts
|
|
* 원문 표 읽기(`loadTable`) — 식 쉬운 말 풀이는 옛 상세 몸과 같이 걷음(855 2-E1).
|
|
*
|
|
* 순수 읽기 — `/elements` 로 표 파일을 찾고 `/table` 로 통째 읽음.
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import { logicApiPaths, type ElementBrief } from "./M01_MasterData_UI_Logic_Api";
|
|
|
|
/* ── 원문 표(소요량·계수) 읽기 ─────────────────────────────────────────── */
|
|
|
|
export interface TableRow {
|
|
file: string;
|
|
키: string;
|
|
이름?: string;
|
|
원문번호?: string;
|
|
출처?: string;
|
|
용도?: { 공종?: string; 대상?: string[]; 로직키?: string[] };
|
|
조건?: Record<string, string>;
|
|
값칸?: Record<string, string>;
|
|
줄?: Record<string, unknown>[];
|
|
}
|
|
|
|
const tableCache = new Map<string, Promise<TableRow | null>>();
|
|
|
|
async function getJson<T>(path: string): Promise<T | null> {
|
|
try {
|
|
const res = await fetch(`${API_BASE_URL}${logicApiPaths().read}${path}`);
|
|
if (!res.ok) return null;
|
|
return (await res.json()) as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function loadTable(key: string): Promise<TableRow | null> {
|
|
const cached = tableCache.get(key);
|
|
if (cached) return cached;
|
|
const job = (async (): Promise<TableRow | null> => {
|
|
for (const group of ["소요량", "계수"]) {
|
|
const found = await getJson<{ items: ElementBrief[] }>(
|
|
`/elements?group=${encodeURIComponent(group)}&q=${encodeURIComponent(key)}&limit=5`,
|
|
);
|
|
const file = found?.items?.find((i) => i.ref === key)?.file;
|
|
if (!file) continue;
|
|
const got = await getJson<{ table: TableRow }>(
|
|
`/table?file=${encodeURIComponent(file)}&key=${encodeURIComponent(key)}`,
|
|
);
|
|
if (got?.table) return { ...got.table, file };
|
|
}
|
|
return null;
|
|
})();
|
|
tableCache.set(key, job);
|
|
return job;
|
|
}
|