feat: Update API versioning and parser handling for improved schedule updates and error management

This commit is contained in:
2026-10-19 23:29:35 +03:00
parent 85c5baa3e5
commit 68f9b95090
10 changed files with 32 additions and 18 deletions

2
shared/updates.d.ts vendored
View File

@@ -16,7 +16,7 @@ interface SavedLike {
export function namesGroup(fileName: string, group: string): boolean;
export function scheduleUpdate<F extends CatalogFileLike>(
saved: SavedLike | null | undefined,
catalog: { files: F[]; stale?: boolean } | null | undefined,
catalog: { files: F[]; stale?: boolean; parserVersion?: number } | null | undefined,
group: string,
options?: { dismissed?: string[]; schemaVersion?: number },
): { changed: F | null; newer: F | null; missing: boolean } | null;

View File

@@ -15,12 +15,15 @@ export function namesGroup(fileName, group) {
}
/**
* changed: the same document was republished (or parsed by an older version) — reload it quietly.
* changed: the same document was republished, or parsed by an older parser than the server's
* (`catalog.parserVersion`, from API version 10) — reload it quietly.
* newer: another document for this group appeared later, e.g. the next semester — offer it.
* missing: the document left the catalog, e.g. a new academic year began.
*/
export function scheduleUpdate(saved, catalog, group, options = {}) {
const { dismissed = [], schemaVersion = 0 } = options;
// A server without parserVersion never asks for a re-read: comparing with a guess could
// reload the same document on every check.
const { dismissed = [], schemaVersion = catalog?.parserVersion ?? 0 } = options;
const fileId = saved?.source?.fileId;
if (!fileId || !catalog?.files || catalog.stale) return null;
const current = catalog.files.find((f) => f.id === fileId) || null;