Integrate the app end to end, add class outline, browser check and README

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 10:02:55 -07:00
1 parent bdfdf581f3
commit 468cafc6db
17 files changed
+702 -16

No files matched your search

+5 -5
View File
@@ -5,12 +5,12 @@ import { normalizeIsbn } from '../shared/isbn.ts';
import { formatCallNumber, parseCallNumber, sortKeyOfRaw } from '../shared/callnumber.ts';
import type { Db, Filter, NewBook } from './db.ts';
import type { Jobs, ResolverLike } from './jobs.ts';
import type { renderCalibrationPdf, renderCardsPdf } from './pdf/render.ts';
import type { classNames } from '../shared/lcc-outline.ts';
// Structural matches for pdf/render.ts (Task 4).
export type RenderCardsPdf = (cards: CardData[], opts: Settings & { startPosition: 1 | 2 | 3 }) => Promise<Uint8Array>;
export type RenderCalibrationPdf = (s: Settings) => Promise<Uint8Array>;
// Matches classNames in shared/lcc-outline.ts (Task 1b).
export type ClassNames = (letters: string) => { className: string | null; subclassName: string | null };
export type RenderCardsPdf = typeof renderCardsPdf;
export type RenderCalibrationPdf = typeof renderCalibrationPdf;
export type ClassNames = typeof classNames;
export interface EventBus {
on(listener: (event: string, data: unknown) => void): () => void;
+2 -2
View File
@@ -3,8 +3,8 @@ import { mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
import type { Book, Confidence, Settings, Source, Status } from '../shared/types.ts';
// Structural match for SourceCache in resolve/resolver.ts (Task 2).
export interface SourceCache { get(key: string): string | null; set(key: string, body: string): void }
import type { SourceCache } from './sources/http.ts';
export type { SourceCache };
export interface NewBook {
isbn13?: string | null; lccn?: string | null; title: string; subtitle?: string | null;
+3 -6
View File
@@ -1,11 +1,8 @@
import type { Book, BookMeta, ResolveInput, Resolution, SearchResult } from '../shared/types.ts';
import type { Book, BookMeta, ResolveInput } from '../shared/types.ts';
import type { Db } from './db.ts';
import type { Resolver } from './resolve/resolver.ts';
// Structural match for Resolver in resolve/resolver.ts (Task 2).
export interface ResolverLike {
resolve(input: ResolveInput, opts?: { onMeta?: (meta: BookMeta) => void }): Promise<Resolution>;
search(title: string, author: string): Promise<SearchResult[]>;
}
export type ResolverLike = Resolver;
export interface Jobs { enqueue(id: number): void; resume(): void; idle(): Promise<void> }
+7
View File
@@ -154,3 +154,10 @@ test('search by title and author', async () => {
assert.ok(out.length > 0);
assert.ok(out[0]!.title);
});
test('lccn.loc.gov "Record not found" (HTTP 200) is an empty result, not a block page', async () => {
const { createLoc } = await import('../sources/loc.ts');
const fetchStub = (async () => new Response('<?xml version="1.0" encoding="UTF-8"?><error>Record not found for LCCN: 2003054578.</error>', { status: 200 })) as typeof fetch;
const loc = createLoc({ fetch: fetchStub, cache: memCache(), intervalMs: 0, sleep: noSleep });
assert.deepEqual(await loc.byLccn('2003054578'), []);
});
+2 -1
View File
@@ -75,7 +75,8 @@ export function createLoc(deps: {
if (hit !== null) return parseMarcXml(hit);
await throttle();
const res = await getText(deps.fetch, `https://lccn.loc.gov/${encodeURIComponent(lccn)}/marcxml`);
if (res.status === 404) return [];
// lccn.loc.gov answers an unknown number with 200 and a short <error>Record not found</error> body.
if (res.status === 404 || /<error>\s*Record not found/i.test(res.body)) { ok(); return []; }
if (res.status >= 400 || !isLocXml(res.body)) blocked();
ok();
deps.cache.set(key, res.body);
+9
View File
@@ -44,3 +44,12 @@ test('single datafield/subfield objects, several 050s, other prefixes, 082, 264'
test('garbage is no records', () => {
assert.deepEqual(parseMarcXml('<html><body>nope</body></html>'), []);
});
test('non-text records (a DVD of the book) contribute no call number', () => {
const rec = (type: string) => `<record xmlns="http://www.loc.gov/MARC21/slim"><leader>01234c${type}m a2200337 a 4500</leader>
<datafield tag="050" ind1=" " ind2="4"><subfield code="a">DVE9004.R69</subfield><subfield code="b">(viewing copy)</subfield></datafield>
<datafield tag="245" ind1="1" ind2="0"><subfield code="a">Harry Potter</subfield></datafield></record>`;
assert.deepEqual(parseMarcXml(rec('g'))[0]!.lcc, []);
assert.equal(parseMarcXml(rec('g'))[0]!.meta.title, 'Harry Potter');
assert.equal(parseMarcXml(rec('a'))[0]!.lcc.length, 1);
});
+5 -1
View File
@@ -64,8 +64,12 @@ export function parseMarcRecord(rec: Node): MarcFields {
const fields = fieldsOf(rec);
const all = (tag: string) => fields.filter((f) => f.tag === tag);
// Leader position 6 is the record type. Videos, sound recordings and the like carry their own
// classification (a DVD of a novel is not the novel's shelf number), so only text records count.
const leader = text(rec['leader']);
const isText = leader.length < 7 || 'at'.includes(leader[6]);
const lcc: Candidate[] = [];
for (const f of all('050')) {
for (const f of isText ? all('050') : []) {
const a = sub(f, 'a');
if (!a) continue;
const b = sub(f, 'b');
+39
View File
@@ -0,0 +1,39 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { MAIN_CLASSES, SUBCLASSES, classNames } from './lcc-outline.ts';
test('known classes', () => {
assert.deepEqual(classNames('QA'), { className: 'Science', subclassName: 'Mathematics' });
assert.equal(classNames('Q').subclassName, 'Science (General)');
assert.equal(classNames('PS').subclassName, 'American literature');
assert.equal(classNames('TX').subclassName, 'Home economics');
assert.equal(classNames('BX').subclassName, 'Christian denominations');
assert.equal(classNames('DS').subclassName, 'Asia');
assert.ok(classNames('TK').subclassName?.startsWith('Electrical engineering'));
});
test('edge cases', () => {
const zz = classNames('ZZ');
assert.ok(zz.className?.startsWith('Bibliography'));
assert.equal(zz.subclassName, null);
assert.deepEqual(classNames('I'), { className: null, subclassName: null });
const kf = classNames('KF');
assert.equal(kf.className, 'Law');
assert.ok(kf.subclassName);
const e = classNames('E');
assert.ok(e.className?.includes('America'));
assert.equal(e.subclassName, null);
assert.deepEqual(classNames('qa'), classNames('QA'));
assert.ok(classNames('KFC').subclassName);
assert.ok(classNames('DAW').subclassName);
});
test('table sanity', () => {
assert.ok(Object.keys(SUBCLASSES).length >= 200);
for (const c of 'ABCDEFGHJKLMNPQRSTUVZ') assert.ok(MAIN_CLASSES[c], c);
for (const n of [...Object.values(MAIN_CLASSES), ...Object.values(SUBCLASSES)]) {
assert.ok(n.length > 0 && n.length <= 120, n);
assert.ok(!/ {2}/.test(n), n);
assert.ok(!/[A-Z]{1,3}\d+(\.\d+)?-\d*\s*$/.test(n), n);
}
});
+259
View File
@@ -0,0 +1,259 @@
// GENERATED by scripts/gen-lcc-outline.ts -- do not edit by hand.
// Source: Library of Congress Classification Outline, https://www.loc.gov/catdir/cpso/lcco/
// (a US government publication). Re-run: node scripts/gen-lcc-outline.ts
export const MAIN_CLASSES: Record<string, string> = {
A: "General works",
B: "Philosophy. Psychology. Religion",
C: "Auxiliary sciences of history",
D: "World history and history of Europe, Asia, Africa, Australia, New Zealand, etc.",
E: "History of the Americas",
F: "History of the Americas",
G: "Geography. Anthropology. Recreation",
H: "Social sciences",
J: "Political science",
K: "Law",
L: "Education",
M: "Music",
N: "Fine arts",
P: "Language and literature",
Q: "Science",
R: "Medicine",
S: "Agriculture",
T: "Technology",
U: "Military science",
V: "Naval science",
Z: "Bibliography. Library science. Information resources (General)",
};
export const SUBCLASSES: Record<string, string> = {
AC: "Collections. Series. Collected works",
AE: "Encyclopedias",
AG: "Dictionaries and other general reference works",
AI: "Indexes",
AM: "Museums. Collectors and collecting",
AN: "Newspapers",
AP: "Periodicals",
AS: "Academies and learned societies",
AY: "Yearbooks. Almanacs. Directories",
AZ: "History of scholarship and learning. The humanities",
B: "Philosophy (General)",
BC: "Logic",
BD: "Speculative philosophy",
BF: "Psychology",
BH: "Aesthetics",
BJ: "Ethics",
BL: "Religions. Mythology. Rationalism",
BM: "Judaism",
BP: "Islam. Bahaism. Theosophy, etc",
BQ: "Buddhism",
BR: "Christianity",
BS: "The Bible",
BT: "Doctrinal Theology",
BV: "Practical Theology",
BX: "Christian denominations",
C: "Auxiliary Sciences of History (General)",
CB: "History of Civilization",
CC: "Archaeology",
CD: "Diplomatics. Archives. Seals",
CE: "Technical Chronology. Calendar",
CJ: "Numismatics",
CN: "Inscriptions. Epigraphy",
CR: "Heraldry",
CS: "Genealogy",
CT: "Biography",
D: "History (General)",
DA: "Great Britain",
DAW: "Central Europe",
DB: "Austria - Liechtenstein - Hungary - Czechoslovakia",
DC: "France - Andorra - Monaco",
DD: "Germany",
DE: "Greco-Roman World",
DF: "Greece",
DG: "Italy - Malta",
DH: "Low Countries - Benelux Countries",
DJ: "Netherlands (Holland)",
DJK: "Eastern Europe (General)",
DK: "Russia. Soviet Union. Former Soviet Republics - Poland",
DL: "Northern Europe. Scandinavia",
DP: "Spain - Portugal",
DQ: "Switzerland",
DR: "Balkan Peninsula",
DS: "Asia",
DT: "Africa",
DU: "Oceania (South Seas)",
DX: "Romanies",
G: "Geography (General). Atlases. Maps",
GA: "Mathematical geography. Cartography",
GB: "Physical geography",
GC: "Oceanography",
GE: "Environmental Sciences",
GF: "Human ecology. Anthropogeography",
GN: "Anthropology",
GR: "Folklore",
GT: "Manners and customs (General)",
GV: "Recreation. Leisure",
H: "Social sciences (General)",
HA: "Statistics",
HB: "Economic theory. Demography",
HC: "Economic history and conditions",
HD: "Industries. Land use. Labor",
HE: "Transportation and communications",
HF: "Commerce",
HG: "Finance",
HJ: "Public finance",
HM: "Sociology (General)",
HN: "Social history and conditions. Social problems. Social reform",
HQ: "The family. Marriage. Women",
HS: "Societies: secret, benevolent, etc",
HT: "Communities. Classes. Races",
HV: "Social pathology. Social and public welfare. Criminology",
HX: "Socialism. Communism. Anarchism",
J: "General legislative and executive papers",
JA: "Political science (General)",
JC: "Political theory",
JF: "Political institutions and public administration",
JJ: "Political institutions and public administration (North America)",
JK: "Political institutions and public administration (United States)",
JL: "Political institutions and public administration (Canada, Latin America, etc.)",
JN: "Political institutions and public administration (Europe)",
JQ: "Political institutions and public administration (Asia, Africa, Australia, Pacific Area, etc.)",
JS: "Local government. Municipal government",
JV: "Colonies and colonization. Emigration and immigration. International migration",
JX: "International law, see JZ and KZ",
JZ: "International relations",
K: "Law in general. Comparative and uniform law. Jurisprudence",
KB: "Religious law in general. Comparative religious law. Jurisprudence",
KBM: "Jewish law",
KBP: "Islamic law",
KBR: "History of canon law",
KBU: "Law of the Roman Catholic Church. The Holy See",
KDZ: "America. North America",
KE: "Canada",
KF: "United States",
KG: "Latin America - Mexico and Central America - West Indies. Caribbean area",
KH: "South America",
KZ: "Law of nations",
L: "Education (General)",
LA: "History of education",
LB: "Theory and practice of education",
LC: "Special aspects of education",
LD: "Individual institutions - United States",
LE: "Individual institutions - America (except United States)",
LF: "Individual institutions - Europe",
LG: "Individual institutions - Asia, Africa, Indian Ocean islands, Australia, New Zealand, Pacific islands",
LH: "College and school magazines and papers",
LJ: "Student fraternities and societies, United States",
LT: "Textbooks",
M: "Music",
ML: "Literature on music",
MT: "Instruction and study",
N: "Visual arts",
NA: "Architecture",
NB: "Sculpture",
NC: "Drawing. Design. Illustration",
ND: "Painting",
NE: "Print media",
NK: "Decorative arts",
NX: "Arts in general",
P: "Philology. Linguistics",
PA: "Greek language and literature. Latin language and literature",
PB: "Modern languages. Celtic languages",
PC: "Romance languages",
PD: "Germanic languages. Scandinavian languages",
PE: "English language",
PF: "West Germanic languages",
PG: "Slavic languages. Baltic languages. Albanian language",
PH: "Uralic languages. Basque language",
PJ: "Oriental languages and literatures",
PK: "Indo-Iranian languages and literatures",
PL: "Languages and literatures of Eastern Asia, Africa, Oceania",
PM: "Hyperborean, Indian, and artificial languages",
PN: "Literature (General)",
PQ: "French literature - Italian literature - Spanish literature - Portuguese literature",
PR: "English literature",
PS: "American literature",
PT: "German literature - Dutch literature - Flemish literature since 1830 Afrikaans literature - Scandinavian literature",
PZ: "Fiction and juvenile belles lettres",
Q: "Science (General)",
QA: "Mathematics",
QB: "Astronomy",
QC: "Physics",
QD: "Chemistry",
QE: "Geology",
QH: "Natural history - Biology",
QK: "Botany",
QL: "Zoology",
QM: "Human anatomy",
QP: "Physiology",
QR: "Microbiology",
R: "Medicine (General)",
RA: "Public aspects of medicine",
RB: "Pathology",
RC: "Internal medicine",
RD: "Surgery",
RE: "Ophthalmology",
RF: "Otorhinolaryngology",
RG: "Gynecology and obstetrics",
RJ: "Pediatrics",
RK: "Dentistry",
RL: "Dermatology",
RM: "Therapeutics. Pharmacology",
RS: "Pharmacy and materia medica",
RT: "Nursing",
RV: "Botanic, Thomsonian, and eclectic medicine",
RX: "Homeopathy",
RZ: "Other systems of medicine",
S: "Agriculture (General)",
SB: "Plant culture",
SD: "Forestry",
SF: "Animal culture",
SH: "Aquaculture. Fisheries. Angling",
SK: "Hunting sports",
T: "Technology (General)",
TA: "Engineering (General). Civil engineering",
TC: "Hydraulic engineering. Ocean engineering",
TD: "Environmental technology. Sanitary engineering",
TE: "Highway engineering. Roads and pavements",
TF: "Railroad engineering and operation",
TG: "Bridge engineering",
TH: "Building construction",
TJ: "Mechanical engineering and machinery",
TK: "Electrical engineering. Electronics. Nuclear engineering",
TL: "Motor vehicles. Aeronautics. Astronautics",
TN: "Mining engineering. Metallurgy",
TP: "Chemical technology",
TR: "Photography",
TS: "Manufactures",
TT: "Handicrafts. Arts and crafts",
TX: "Home economics",
U: "Military science (General)",
UA: "Armies: Organization, distribution, military situation",
UB: "Military administration",
UC: "Maintenance and transportation",
UD: "Infantry",
UE: "Cavalry. Armor",
UF: "Artillery",
UG: "Military engineering. Air forces",
UH: "Other services",
V: "Naval science (General)",
VA: "Navies: Organization, distribution, naval situation",
VB: "Naval administration",
VC: "Naval maintenance",
VD: "Naval seamen",
VE: "Marines",
VF: "Naval ordnance",
VG: "Minor services of navies",
VK: "Navigation. Merchant marine",
VM: "Naval architecture. Shipbuilding. Marine engineering",
Z: "Books (General). Writing. Paleography. Book industries and trade. Libraries. Bibliography",
ZA: "Information resources (General)",
};
export function classNames(letters: string): { className: string | null; subclassName: string | null } {
const l = letters.trim().toUpperCase();
if (!/^[A-Z]{1,3}$/.test(l)) return { className: null, subclassName: null };
const className = MAIN_CLASSES[l[0]!] ?? null;
const subclassName = SUBCLASSES[l] ?? (l.length === 3 ? (SUBCLASSES[l.slice(0, 2)] ?? null) : null);
return { className, subclassName };
}
+1
View File
@@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Booksorter</title>
<link rel="icon" href="data:,">
<link rel="stylesheet" href="/styles.css">
</head>
<body>
+7 -1
View File
@@ -20,6 +20,12 @@ function prepare(): void {
});
}
/** The one detector configuration the scanner uses; also used by scripts/browser-check.ts. */
export function makeDetector(): BarcodeDetector {
prepare();
return new BarcodeDetector({ formats: ['ean_13'] });
}
const INTERVAL_MS = 150;
export async function startScanner(
@@ -54,7 +60,7 @@ export async function startScanner(
throw e;
}
const detector = new BarcodeDetector({ formats: ['ean_13'] });
const detector = makeDetector();
let state = newReadState();
// Sequential loop: the next round is scheduled only after the previous detection finished,
+1
View File
@@ -52,6 +52,7 @@ video.mirror { transform: scaleX(-1); }
.item.column { flex-direction: column; align-items: stretch; gap: 8px; }
.item-btn { display: flex; gap: 14px; align-items: flex-start; width: 100%; text-align: left; border: 0; padding: 0; background: none; }
.item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.item-main .chip { align-self: flex-start; margin-top: 4px; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.title { overflow-wrap: anywhere; }
.callno { display: inline-flex; flex-direction: column; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; white-space: pre; min-width: 9.5em; font-size: .92rem; line-height: 1.35; }