A module keeping a checkout of a repository of decisions, designs and issues from the git seat, current on every announced merge and on a timer, answering records_search / records_read / records_list / records_status / records_sync at the commit it read (novox/hq ADR 0025, ADR 0153). The repository is a setting; it names no mesh.
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
// records' consumer: keep the checkout current (novox/hq ADR 0153).
|
|
//
|
|
// Synced when the runtime binds the broker, on every merge the forge announces, and on a timer for
|
|
// the merges it did not hear about — a restart during a merge, a repository the forge does not emit
|
|
// for. The timer is unhurried: the record changes when thinking changes, not by the minute.
|
|
import { on } from "@novox/mesh-sdk/events";
|
|
import { recordsFromEnv, type Records } from "./records.js";
|
|
|
|
let records: Records | null = null;
|
|
try {
|
|
records = await recordsFromEnv();
|
|
} catch (err) {
|
|
console.log(`[records] not reading — ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
|
|
if (records) {
|
|
const reader = records;
|
|
void reader.sync().then(async () => {
|
|
const s = await reader.standing();
|
|
console.log(`[records] ${s.repository} at ${s.commit.slice(0, 8) || "(no commit)"}, ${s.documents} document(s)${s.lastError ? ` — ${s.lastError}` : ""}`);
|
|
});
|
|
setInterval(() => void reader.sync(), 10 * 60 * 1000).unref();
|
|
|
|
// A merge on the forge into the repository this reads: pull now. The event names the repository
|
|
// by owner and name (gitea's `pull.merged`); anything else is somebody else's merge.
|
|
await on<{ owner?: string; repo?: string; base?: string }>("gitea.pull.merged", async (event) => {
|
|
const merged = `${event.body.owner ?? ""}/${event.body.repo ?? ""}`;
|
|
if (merged !== reader.repository) return;
|
|
console.log(`[records] ${merged} merged; syncing`);
|
|
await reader.sync();
|
|
});
|
|
}
|
|
|
|
export { records };
|