/* PLAN 323-6 바꿈 한 길 헬퍼 — 진짜 `B05_Profile_Api_Structures.ts`(구조물 초안) · `design_store.ts`(바뀜 신호)를 * 그 자리에서 트랜스파일해 Node 로 돌림(세션만 흉내) · 결과 = 표준출력 JSON. 짝 = `test_323_6_change.py`. */ const fs = require("fs"); const path = require("path"); const ROOT = path.join(__dirname, "..", ".."); const ts = require(path.join(ROOT, "config", "node_modules", "typescript")); const CATALOG = require("./helper_322_catalog_module.cjs"); const memory = new Map(); const store = { getItem: (k) => (memory.has(k) ? memory.get(k) : null), setItem: (k, v) => memory.set(k, String(v)), removeItem: (k) => memory.delete(k), key: (i) => [...memory.keys()][i] ?? null, get length() { return memory.size; }, }; globalThis.window = { sessionStorage: store, localStorage: store, addEventListener: () => {} }; globalThis.sessionStorage = store; globalThis.localStorage = store; const cache = new Map(); function load(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 need = (spec) => { if (CATALOG.isCatalogRequest(spec)) return CATALOG; if (spec.startsWith("@ui/")) return new Proxy({}, { get: () => () => {} }); if (spec.startsWith("@config/")) return load(path.join(ROOT, "config", `${spec.slice(8)}.ts`)); if (spec.startsWith(".")) return load(path.join(path.dirname(full), `${spec}.ts`)); return require(spec); }; new Function("exports", "module", "require", js)(box.exports, box, need); return box.exports; } const api = load(path.join(ROOT, "B05_Profile", "B05_Profile_Api_Structures.ts")); const { useDesignStore } = load(path.join(ROOT, "A00_Common", "design", "design_store.ts")); const heard = { structures: [], pipes: [] }; const shop = useDesignStore("P", null); for (const key of ["structures", "pipes"]) shop.subscribe(key, (value) => heard[key].push(value)); const wall = { structure_id: "w1", type_id: "retaining_wall", chainage_m: 10 }; api.writePendingStructures("P", [wall]); api.writePendingStructures("P", null); api.writePendingStructures("P", [wall]); // 바뀜 신호 거르기 — 구조물 = 늘 · 관 = 자리 · 종류 · 구간 · 잇기가 바뀔 때만(옵션만 = 폼 길이 그 카드) const status = load(path.join(ROOT, "A00_Common", "design", "design_structure_status.ts")); let fired = 0; const off = status.watchDrafts("Q", () => (fired += 1)); const shopQ = useDesignStore("Q", null); shopQ.set("pipes", [{ chainage_m: 10, source: "user", options: { a: 1 } }]); shopQ.set("pipes", [{ chainage_m: 10, source: "user", options: { a: 2 } }]); shopQ.set("pipes", [{ chainage_m: 12, source: "user", options: { a: 2 } }]); shopQ.set("pipes", [{ chainage_m: 12, source: "user", facility: "box_culvert" }]); shopQ.set("structures", []); off(); shopQ.set("structures", null); process.stdout.write( JSON.stringify({ watch: fired, heard: heard.structures.map((v) => (v ? v.length : null)), pipesHeard: heard.pipes.length, read: api.readPendingStructures("P"), key: memory.has("aislo:draft:structures:P"), swaps: [ "mirror>curb", "mirror>guardrail", "refuge>work_yard", "pipe>box_culvert", "pipe>revetment", "cross_underdrain>pipe", ].map((pair) => [pair, CATALOG.swapsInPlace(...pair.split(">"))]), }), );