Files
Aislo/resources/tester/helper_836_1_machine_cover.cjs
T
eomsangdonandClaude Opus 5.5 c261fee9b7 feat(836-1): 기계 덮음 꼴 · 계산기 짝 규칙 · 서버 저장 정리 — SK 수식 문서 칸 기계덮음
- 자리 = SK 수식.문서.기계덮음 {기계 입력 글: {값 · 조종원 줄 · 잡품 줄}} · 사본 줄 그대로
- 계산기(파이썬 · TS 짝)가 기계 식 부를 때 그 기계 덮음을 얹음 · 덮음 없음 = 문서 그대로
- 서버 저장 · 미리 셈 = 몸 검사 + 원본과 같은 칸 · 안 부르는 기계 뺌
- 거울 · 손셈(굴착기 1.0㎥ 108,958) · 저장 길 지킴 시험 test_836_1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 13:30:57 +09:00

64 lines
2.7 KiB
JavaScript

/* 836-1 기계 덮음 거울 헬퍼 — common_util_formula_doc_cover.ts · calc 를 그 자리에서 트랜스파일해 Node 로 돌림.
* stdin = {문서들: {키: 문서}, 대상: [{문서, 덮음?}], 기록: {열쇠: {값 | 빈 | 끊김}}, 짜임: [{문서, 입력, 덮음, 값}]}
* stdout = {답: [calcDoc 답], 짜임: [{얹음: coverDoc, 기본: defaultsOf, 정리: prune}]}
* 기록 열쇠 = 갈래 + "|" + 값 글(파이썬 `_canon` 과 같은 꼴 · helper_802_1 과 같음). */
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const cache = new Map();
function load(at) {
if (cache.has(at)) return cache.get(at);
const js = ts.transpileModule(fs.readFileSync(at, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(at, box.exports);
const need = (p) =>
p.startsWith(".") ? load(path.resolve(path.dirname(at), `${p}.ts`)) : require(p);
new Function("exports", "module", "require", js)(box.exports, box, need);
return box.exports;
}
const root = path.join(__dirname, "..", "..", "common_util");
const calc = load(path.join(root, "common_util_formula_doc_calc.ts"));
const cover = load(path.join(root, "common_util_formula_doc_cover.ts"));
function canon(v) {
if (typeof v === "number") return calc.plainText(v);
if (Array.isArray(v)) return v.map(canon);
if (v && typeof v === "object") {
const out = {};
for (const k of Object.keys(v).sort()) out[k] = canon(v[k]);
return out;
}
return v;
}
const input = JSON.parse(fs.readFileSync(0, "utf8"));
const record = input.기록 || {};
function answer(kind, p) {
const k = `${kind}|${JSON.stringify(canon(p))}`;
if (!(k in record)) throw new calc.Broken(`기록 없음 ${k}`);
const got = record[k];
if ("빈" in got) throw new calc.Gap(got.빈);
if ("끊김" in got) throw new calc.Broken(got.끊김);
return got.값;
}
const links = {
element: (p) => answer("요소", p),
table: (p) => answer("표", p),
doc: (key) => (input.문서들 || {})[key] || null,
};
const out = { 답: [], 짜임: [] };
for (const one of input.대상 || [])
out.답.push(calc.calcDoc(one.덮음 ? { ...one.문서, 기계덮음: one.덮음 } : one.문서, links));
for (const one of input.짜임 || []) {
const base = cover.defaultsOf(one.문서, one.값);
const key = cover.machineKey(one.입력);
out.짜임.push({
얹음: cover.coverDoc(one.문서, one.입력, one.덮음),
기본: base,
정리: one.덮음[key] ? cover.prune(one.덮음[key], base) : null,
});
}
process.stdout.write(JSON.stringify(out));