From d16cff519f4aa5c8cd46d711017a78ef2f69c88d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 13 Sep 2026 14:18:01 +0200 Subject: [PATCH] Remove dead currentSnapshot, sendJson, readJsonBody helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REC-122: - `currentSnapshot()` had no caller (the `cachedSnapshot` variable it wrapped is still legitimately read directly by `refreshWitnesses`'s overlap-skip branch, so only the unused wrapper function was removed, not the variable). - `sendJson` and `readJsonBody` are remnants of a removed HTTP ingress; neither has a caller. `httpError`, which `readJsonBody` called internally, is kept — it is used by 13 other call sites throughout the file. Kill attempts that failed: none. - `rg -n '\bcurrentSnapshot\b' scripts/weksa-daemon.mjs` -> only its now-removed declaration (repeated the census command against current HEAD before editing). - `rg -n '\bsendJson\b|\breadJsonBody\b' scripts/weksa-daemon.mjs` -> only the two now-removed definitions. - Not exported from the file and no other file requires/imports scripts/weksa-daemon.mjs as a module, so no cross-repo consumer is possible for these unexported local functions. Checks run: `node --check scripts/weksa-daemon.mjs` -> syntax OK. No package.json/test suite exists in this repo to run beyond that. Co-Authored-By: Claude Sonnet 5 --- scripts/weksa-daemon.mjs | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/scripts/weksa-daemon.mjs b/scripts/weksa-daemon.mjs index 8377b21..ef65385 100644 --- a/scripts/weksa-daemon.mjs +++ b/scripts/weksa-daemon.mjs @@ -174,13 +174,6 @@ async function publishWitnesses() { return snapshot; } -async function currentSnapshot() { - if (!cachedSnapshot) { - await refreshWitnesses("snapshot-demand"); - } - return cachedSnapshot; -} - async function refreshWitnesses(reason) { if (witnessRefreshRunning) { await appendLog(`skipped overlapping witness refresh reason=${reason}`); @@ -1108,32 +1101,6 @@ async function writeJson(path, value) { await writeFile(path, `${JSON.stringify(value, null, 2)}\n`, "utf8"); } -function sendJson(response, statusCode, value) { - response.writeHead(statusCode, { "content-type": "application/json; charset=utf-8" }); - response.end(`${JSON.stringify(value, null, 2)}\n`); -} - -async function readJsonBody(request) { - const chunks = []; - let byteLength = 0; - for await (const chunk of request) { - byteLength += chunk.length; - if (byteLength > 1_000_000) { - throw httpError(413, "request body is too large"); - } - chunks.push(chunk); - } - const text = Buffer.concat(chunks).toString("utf8").trim(); - if (!text) { - throw httpError(400, "request body is empty"); - } - try { - return JSON.parse(text); - } catch (error) { - throw httpError(400, `invalid JSON body: ${error.message}`); - } -} - function httpError(statusCode, message) { const error = new Error(message); error.statusCode = statusCode;