// WHERE A WATCH'S LEARNED SPELLINGS LIVE (umtool R6.3), and their read. // Server-only (node:fs). // // series, watch reports/.series//learned.json beside series.json // living reports/
/learned.json beside schedule.json // // Beside the schedule, so it goes where the schedule goes (a series' delete // removes its directory; a living schedule's delete removes it with // schedule.json). ONE WRITER: controller/learnedSpellings.ts, under the // article store's lock, atomically. Reads are lock-free (a write replaces the // file whole). import path from "node:path"; import type { Paths } from "../../../paths"; import { readJsonFile } from "../../../jsonFile-server"; import { livingFile, seriesDir } from "../../schedule/store"; import { parseLearned, type LearnedFile } from "./learned"; export const LEARNED_FILENAME = "learned.json"; export type LearnedPaths = Pick; /** learned.json of a schedule (its shape decides where). */ export function learnedFilePath(paths: LearnedPaths, s: { shape: string; id: string }): string { return s.shape === "living" ? path.join(path.dirname(livingFile(paths, s.id)), LEARNED_FILENAME) : path.join(seriesDir(paths, s.id), LEARNED_FILENAME); } /** A schedule's learned spellings, or null (none yet, or not a learned file). */ export async function readLearned(paths: LearnedPaths, s: { shape: string; id: string }): Promise { const r = await readJsonFile(learnedFilePath(paths, s)); return r.ok ? parseLearned(r.value, s.id) : null; }