Show the edition statement on cards and in the library
The edition comes only from a record for this exact edition: the Library of Congress record's edition statement first, then Open Library's edition name when it is a well-formed statement. Existing books are filled in at startup without changing anything else about them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
e83774adbd
commit
bb46d343a8
26 files changed
+455
-34
No files matched your search
@@ -47,6 +47,12 @@ export interface Resolver {
|
||||
* [] when there is none; throws TemporaryError when the catalogue cannot be asked.
|
||||
*/
|
||||
tail(input: TailInput, opts?: { onTailSource?: (s: TailSource) => void }): Promise<string[]>;
|
||||
/**
|
||||
* Only the edition statement of a book already in the library, from records for this exact edition (see
|
||||
* editionOf). '' when there is none; throws TemporaryError when a catalogue could not be asked, so the caller
|
||||
* can try again later. Same rate limit and cache as a lookup.
|
||||
*/
|
||||
edition(input: { isbn13?: string | null; lccn?: string | null }): Promise<string>;
|
||||
}
|
||||
|
||||
type Partials = (Partial<BookMeta> | null | undefined)[];
|
||||
@@ -160,6 +166,14 @@ export function createResolver(deps: {
|
||||
lccnOtherCands = lccOf(others);
|
||||
}
|
||||
|
||||
// The edition statement may only come from a record for this exact edition: the record fetched by the ISBN, or
|
||||
// the LCCN record that lists this ISBN (or any LCCN record when the book has no ISBN). Never from a title match,
|
||||
// a work-level record, another edition or the similar-books search. The Library of Congress first, then Open
|
||||
// Library's edition record. null (unknown, asked again later) when the Library of Congress failed and had none.
|
||||
let edit: string | null = locRecs.find((r) => r.edition)?.edition ?? null;
|
||||
if (edit === null && isbn && !locError) edit = (await ol.editionName(isbn)) ?? '';
|
||||
else if (edit === null && !isbn && !locError) edit = '';
|
||||
|
||||
const olEditionCands: Candidate[] = edition?.lcc ?? [];
|
||||
const metaOf = (extra: Partials = []): BookMeta | null =>
|
||||
mergeMeta([edition?.meta, locRecs[0]?.meta, ...extra, input.title ? { title: input.title } : null]);
|
||||
@@ -294,14 +308,14 @@ export function createResolver(deps: {
|
||||
if (chosen) {
|
||||
return {
|
||||
meta, callNumber: chosen.callNumber, sortKey: chosen.sortKey,
|
||||
confidence: chosen.confidence, source: chosen.source, dewey, tail, reason: null,
|
||||
confidence: chosen.confidence, source: chosen.source, dewey, tail, edition: edit, reason: null,
|
||||
};
|
||||
}
|
||||
// Open Library had nothing and the LoC could not be asked: report that, not "no number found".
|
||||
if (locError) throw locError;
|
||||
if (olError) throw olError;
|
||||
return {
|
||||
meta, callNumber: null, sortKey: null, confidence: null, source: null, dewey, tail,
|
||||
meta, callNumber: null, sortKey: null, confidence: null, source: null, dewey, tail, edition: edit,
|
||||
reason: meta ? 'No Library of Congress number found' : 'Not found in Open Library or the Library of Congress',
|
||||
};
|
||||
}
|
||||
@@ -363,5 +377,18 @@ export function createResolver(deps: {
|
||||
}, (fn) => fn(), opts?.onTailSource);
|
||||
}
|
||||
|
||||
return { resolve, tail, search: (title, author) => ol.search(title, author) };
|
||||
async function edition(input: { isbn13?: string | null; lccn?: string | null }): Promise<string> {
|
||||
const isbn = input.isbn13 ? (normalizeIsbn(input.isbn13) ?? input.isbn13) : undefined;
|
||||
if (!isbn && !input.lccn) return '';
|
||||
let found: string | null = null;
|
||||
if (isbn) found = (await loc.byIsbn(isbn)).find((r) => r.edition)?.edition ?? null;
|
||||
if (found === null && input.lccn) {
|
||||
// Same edition only if the book has no ISBN or the record lists this ISBN.
|
||||
found = (await loc.byLccn(input.lccn)).filter((r) => !isbn || r.isbns.includes(isbn)).find((r) => r.edition)?.edition ?? null;
|
||||
}
|
||||
if (found === null && isbn) found = await ol.editionName(isbn);
|
||||
return found ?? '';
|
||||
}
|
||||
|
||||
return { resolve, tail, edition, search: (title, author) => ol.search(title, author) };
|
||||
}
|
||||
Reference in new issue
Block a user