Links, Wikipedia and the replica: duplicates merged, dead fields and caches out
- One failure(res) in api.ts for every fetch that can fail (session,
remote and the libraries calls each had their own; the error's
attached body was never read). Session's lost() and vanished() were
the same but for the hook: stop("foreign" | "gone").
- linker: place() locates the words with locate() instead of a copy;
the scan reply's type is written once; LinkRow.at was never read; the
"import" origin is never passed.
- wiki.ts: cleanHtml's cache could never hit (its only caller,
articleText, is cached on the same key and evicts the same way);
known() returned an article nobody read.
- Gone: currentLibrary and idbKeys (no callers), useWikiSuggest's q,
a node's link flag spelled out where isLink says it. Exports used only
in their own file are not exported.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
3aa8778427
commit
52cb7c2065
11 files changed
+58
-99
No files matched your search
+11
-9
@@ -11,9 +11,6 @@ export function setLibrary(id: string) {
|
||||
library = id;
|
||||
}
|
||||
|
||||
/** The library this page holds, once boot has chosen it. */
|
||||
export const currentLibrary = () => library;
|
||||
|
||||
/**
|
||||
* A path under this library's API: libApi("/links/jobs") → /api/l/<id>/links/jobs. Before a library
|
||||
* is chosen (only in the tests: the page chooses one before anything asks) the unprefixed route,
|
||||
@@ -33,16 +30,21 @@ export interface LibraryInfo {
|
||||
branches: string[];
|
||||
}
|
||||
|
||||
async function call<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(path, init);
|
||||
let body: Record<string, unknown> = {};
|
||||
/** A failed answer as an error: the server's `error`, else its status. */
|
||||
export async function failure(res: Response): Promise<Error> {
|
||||
let message = `${res.status} ${res.statusText}`;
|
||||
try {
|
||||
body = await res.json();
|
||||
message = String((await res.json())?.error ?? message);
|
||||
} catch {
|
||||
/* not JSON */
|
||||
}
|
||||
if (!res.ok) throw new Error(String(body.error ?? `${res.status} ${res.statusText}`));
|
||||
return body as T;
|
||||
return new Error(message);
|
||||
}
|
||||
|
||||
async function call<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(path, init);
|
||||
if (!res.ok) throw await failure(res);
|
||||
return res.json().catch(() => ({})) as Promise<T>;
|
||||
}
|
||||
const send = (method: string, body?: unknown): RequestInit => ({ method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
|
||||
|
||||
Reference in new issue
Block a user