Remove dead currentSnapshot, sendJson, readJsonBody helpers

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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-13 14:18:01 +02:00
commit d16cff519f

View file

@ -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;