Files
Aislo/resources/tester/helper_273_2_preview_stations.cjs
T
eomsangdonandClaude Opus 5.5 dfd7427c46 feat(b06): 횡단도 바로 반영 — 새로 놓거나 옮긴 관 · 구조물의 횡단 카드를 [저장] 전에 보임 (273-2)
- 서버: 읽기 전용 미리 뜨기 POST /section/preview-stations — 로그인 · 회사 · 프로젝트 권한 그대로 · 한 번에 60곳 · 파일 · DB 안 씀 · 저장과 같은 길(sample_structure_sections · compute_default_designs crosses)
- 화면: 초안이 심는 자리 중 횡단 없는 곳만 묻고 한 번 뜬 자리는 기억(B06_Section_Section_Drafts) · 카드 이름 · 관 그림 얹음 · 늦은 옛 응답 무시 · 배수 재계산이 관경을 정하면 카드 다시 얹음 · B06 관 옮김도 카드 다시
- [저장]은 지금처럼 서버가 같은 계산으로 정본에 씀 — 미리 본 카드와 같은 값
- 알림 글: 횡단도는 바로 보이고 세부 배수유역만 저장 뒤 다시 셈
- 시험: test_273_2 새로 · 177-3 헬퍼에 revealPick 자리 채움

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LLCk2y5xE8YGVgjbTntWsY
2026-10-11 20:48:32 +09:00

114 lines
4.1 KiB
JavaScript

/* 273-2 초안 측점 — 진짜 `B06_Section_Section_Drafts.ts` + 진짜 측점 규칙(`common_util_structure_station`)을
* 가짜 서버 · 초안으로 돌림. 표준출력 JSON 한 벌.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
function loadTs(file, stubs = {}) {
const js = ts.transpileModule(fs.readFileSync(path.join(ROOT, file), "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
new Function("exports", "module", "require", js)(box.exports, box, (name) => {
if (!stubs[name]) throw new Error(`stub 없음: ${name} (${file})`);
return stubs[name];
});
return box.exports;
}
const station = loadTs("common_util/common_util_structure_station.ts");
let draftPipes = null;
const asked = [];
let slow = false;
const types = [
{
type_id: "pipe",
group: "A",
placement: "point",
managed_by: "pipe_points",
name: "배관",
options: [],
},
];
const drafts = loadTs("B06_Section/B06_Section_Section_Drafts.ts", {
"../B04_PreProcess/B04_PreProcess_Api_Fetch": {
fetchDetailPipePoints: async () => ({ pipe_points: [{ chainage_m: 95.38, facility: "pipe" }] }),
},
"../B05_Profile/B05_Profile_Api_Structures": {
fetchStructures: async () => ({ structures: [] }),
fetchStructureTypes: async () => types,
readPendingStructures: () => null,
},
"../B05_Profile/B05_Profile_Api_Pipes_Draft": { readPendingPipes: () => draftPipes },
"@util/common_util_culvert_sets": {
registryDefaults: () => ({ pipe: { pipe_kind: "파형강관", pipe_diameter_mm: 800 } }),
buildCulvertSets: (points) => new Map(points.map((p) => [p.chainage_m, { kind: "pipe" }])),
attachCulvertSets: (sections, sets) => {
for (const [at] of sets) {
const hit = sections.find((s) => Math.abs(s.chainage_m - at) < 0.005);
if (hit) hit.culvert = true;
}
},
},
"../common_util/common_util_structure_station": station,
"./B06_Section_Api_Fetch": {
previewStructureSections: async (_projectId, chainages) => {
asked.push(chainages);
if (slow) await new Promise((resolve) => setTimeout(resolve, 50));
return chainages.map((c) => ({
chainage_m: c,
kind: "irregular",
station_id: `s${c}`,
samples: [],
}));
},
},
});
/** 서버 상세 — 격자 0 · 20 · 40 · 100 + 옛 관 측점 95.38. */
const detailOf = () => ({
cross_sections: [0, 20, 40, 95.38, 100].map((c) => ({
chainage_m: c,
kind: c === 95.38 ? "irregular" : c === 0 ? "bp" : "regular",
station_id: `s${c}`,
samples: [],
})),
});
const chainages = (detail) => detail.cross_sections.map((s) => s.chainage_m);
(async () => {
const out = {};
const detail = detailOf();
draftPipes = [{ chainage_m: 95, facility: "pipe", source: "user" }]; // 95.38 → 95
await drafts.withDraftStations(detail, "P", 1);
const preview = detail.cross_sections.find((s) => s.chainage_m === 95);
out.moved = {
chainages: chainages(detail),
asked: asked.splice(0),
preview: { preview: preview.preview, structure: preview.structure, culvert: preview.culvert },
};
await drafts.withDraftStations(detail, "P", 1);
out.again = { chainages: chainages(detail), asked: asked.splice(0) };
draftPipes = null;
await drafts.withDraftStations(detail, "P", 1);
out.cleared = { chainages: chainages(detail) };
const race = detailOf();
slow = true;
draftPipes = [{ chainage_m: 96, facility: "pipe", source: "user" }];
const first = drafts.withDraftStations(race, "P", 1); // 늦게 끝남
await new Promise((resolve) => setTimeout(resolve, 5));
slow = false;
draftPipes = [{ chainage_m: 120, facility: "pipe", source: "user" }];
await drafts.withDraftStations(race, "P", 1);
await first;
out.race = { chainages: chainages(race) };
process.stdout.write(JSON.stringify(out));
})().catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});