A small module builds a signature for a message draft from the response of a remote source. After a recent change, the module sometimes started accepting invalid data as successful and behaving unstably when the result is reused.
loadDraftLabel function accepts a string draftId and an asynchronous fetcher.draftId or one consisting only of spaces must result in the error Draft id is required before calling fetcher.{ id, title, labels }, where:
id is a non-empty string,title is a non-empty string,labels is an array of strings without empty or whitespace-only elements.Invalid draft payload.import { loadDraftLabel, createMemoryFetcher } from "./draftLabel";
const fetcher = createMemoryFetcher({
"draft-7": { id: "draft-7", title: "Reply", labels: ["inbox", 42] }
});
await loadDraftLabel("draft-7", fetcher);
Note that the call must not be considered successful.
Then verify result reuse:
const fetcher = createMemoryFetcher({
"draft-9": { id: "draft-9", title: "Follow up", labels: ["vip"] }
});
const first = await loadDraftLabel("draft-9", fetcher);
first.labels.push("local-only");
const second = await loadDraftLabel("draft-9", fetcher);
console.log(second.labels);
labels must not pass validation.first.labels, a subsequent call for the same draftId must return the original data without the added element.22.x5.8ES modulesstrict=truenode --loader ts-node/esm src/repro.ts or any equivalent way to run ESM TypeScriptUse line comments to explain the problem, its impact, the fix and how to test it.