/* PLAN 298-1 헬퍼 — B06 [추가]가 적은 「높이 기다림」을 배수유역도 판이 같은 표(`fordWaitsOf`)로 보고 * 다시 나눈 유량으로 빈 월류 높이를 채움(126-1) · 프로젝트마다 따로 · 실패 = 토스트 한 줄(`analyzeFailed`). * TS 로더는 `helper_126_ford_fill.cjs` 와 같다 · 결과 = 표준출력 JSON 한 벌. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); const cache = new Map(); const toasts = []; const STUBS = { "@ui/ui_template_elements": { showToast: (message, kind) => toasts.push([message, kind]) }, }; function loadTs(file) { const full = path.resolve(file); if (cache.has(full)) return cache.get(full); const js = ts.transpileModule(fs.readFileSync(full, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(full, box.exports); const localRequire = (request) => { if (STUBS[request]) return STUBS[request]; if (request === "@config/config_frontend") return loadTs(path.join(ROOT, "config", "config_frontend.ts")); if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`)); if (request.startsWith("@")) return new Proxy({}, { get: () => () => {} }); return require(request); }; new Function("exports", "module", "require", js)(box.exports, box, localRequire); cache.set(full, box.exports); return box.exports; } const B05 = path.join(ROOT, "B05_Profile"); const fill = loadTs(path.join(B05, "B05_Profile_UI_Drainage_Ford_Fill.ts")); const { fordHeightM } = loadTs( path.join(ROOT, "A00_Common", "design", "design_structure_ford_calc.ts"), ); const flow = 8.0; const points = () => [ { chainage_m: 185, facility: "ford_bridge", options: { ford_width_m: 10 } }, { chainage_m: 300, facility: "ford_pavement", options: {} }, ]; const basins = [ { chainage_m: 185, design_flow_m3s: flow }, { chainage_m: 300, design_flow_m3s: flow }, ]; // ① B06 [추가] — 그 프로젝트 표에 측점을 적음(판과 같은 표) const b06Wants = fill.waitsFordHeight("ford_bridge", { ford_width_m: 10 }); if (b06Wants) fill.fordWaitsOf("p1").add(185); const same = fill.fordWaitsOf("p1") === fill.fordWaitsOf("p1"); // ② 판의 다시 나눔 응답 — 같은 표로 채움 · 기다리지 않던 300 은 빈칸 그대로 const p1 = points(); const filled = fill.fillFordHeights(p1, basins, fill.fordWaitsOf("p1")); // ③ 다른 프로젝트 같은 측점은 안 채움 const p2 = points(); const otherFilled = fill.fillFordHeights(p2, basins, fill.fordWaitsOf("p2")); let failed = null; try { const parts = loadTs(path.join(B05, "B05_Profile_UI_Drainage_Parts.ts")); failed = { status: parts.analyzeFailed(new Error("502 Bad Gateway"), "세부유역 산정에 실패했습니다."), plain: parts.analyzeFailed("x", "세부유역 산정에 실패했습니다."), toasts: [...toasts], }; } catch (error) { failed = { error: String(error) }; } process.stdout.write( JSON.stringify({ b06Wants, same, filled, heights: p1.map((p) => p.options.ford_height_m ?? null), left: [...fill.fordWaitsOf("p1")], otherFilled, otherHeights: p2.map((p) => p.options.ford_height_m ?? null), need: fordHeightM(flow, 10), failed, }), );