/* 종단도 한 벌(계획서 24-2c) 단위검증 헬퍼 — 계획고 초안이 등록부 칸(`alignment-draft`)으로 * 옮겨졌는지 · 옛 키 값을 옮겨 받는지 · 되돌리기 사진이 새 칸을 찍는지를 Node 로 돌린다. * `A00_Common/design/design_store.ts` · `B05_Profile_UI_Profile_History.ts` 를 그 자리에서 * 트랜스파일한다. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); function memoryStorage() { const map = new Map(); return { getItem: (key) => (map.has(key) ? map.get(key) : null), setItem: (key, value) => map.set(key, String(value)), removeItem: (key) => map.delete(key), key: (index) => [...map.keys()][index] ?? null, get length() { return map.size; }, keys: () => [...map.keys()], }; } const session = memoryStorage(); const local = memoryStorage(); globalThis.window = { sessionStorage: session, localStorage: local }; globalThis.sessionStorage = session; const cache = new Map(); 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 (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`)); return require(request); }; new Function("exports", "module", "require", js)(box.exports, box, localRequire); cache.set(full, box.exports); return box.exports; } const { useDesignStore } = loadTs(path.join(ROOT, "A00_Common", "design", "design_store.ts")); const history = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_Profile_History.ts")); const out = {}; // ① 옛 키에 남은 초안 — 처음 읽을 때 새 칸으로 옮겨 받고 옛 키는 지운다. local.setItem("frd_current_project_id", "p-1"); session.setItem( "b05-profile-alignment-draft:7", JSON.stringify({ station_offsets: { "20.000": 0.3 }, curve_radii: {} }), ); out.adopted = useDesignStore(null, 7).get("alignmentDraft"); out.keysAfterAdopt = session.keys(); // ② 쓰기는 새 칸으로 — 프로젝트를 준 가게와 안 준 가게가 같은 칸. useDesignStore("p-1", 7).set("alignmentDraft", { station_offsets: { "40.000": 0.1 }, curve_radii: {}, }); out.sameSlot = useDesignStore(null, 7).get("alignmentDraft"); // ③ 되돌리기가 새 칸을 사진 찍는다 — 편집 한 걸음을 쌓고 되돌리면 앞 값이 돌아온다. const undoStack = history.createProfileHistory(() => undefined); useDesignStore("p-1", 7).set("alignmentDraft", { station_offsets: { "40.000": 0.2 }, curve_radii: {}, }); undoStack.record(); out.beforeUndo = useDesignStore("p-1", 7).get("alignmentDraft"); out.undone = undoStack.undo(); out.afterUndo = useDesignStore("p-1", 7).get("alignmentDraft"); process.stdout.write(JSON.stringify(out));