Docs per the docs-files-api skill: a 1–2 line @file; what a declaration is or does in JSDoc on it, not in // comments or the file header. Generated-by: Claude Opus 5.5
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
/** @file the diigo bookmark generator over a fluent handle (not used by the worker today). */
|
|
|
|
export type PagedGet = {
|
|
pathjoin(ref: string): PagedGet;
|
|
query(params: Record<string, string | number>): PagedGet;
|
|
get(): Promise<string>;
|
|
};
|
|
|
|
export type DumpOptions = {
|
|
/** fluent handle for the diigo account, cookie attached upstream */
|
|
diigoAPI: PagedGet;
|
|
pages?: number;
|
|
count?: number;
|
|
log?: (event: Record<string, unknown>) => void;
|
|
};
|
|
|
|
/** yield diigo bookmarks, most-recently-updated first, `pages * count` at
|
|
* most. `diigoAPI` is attenuated authority; over RPC the generator runs in
|
|
* the caller's address space against a stub. */
|
|
export async function* dumpBookmarks({
|
|
diigoAPI,
|
|
pages = 2,
|
|
count = 24,
|
|
log = () => {},
|
|
}: DumpOptions): AsyncGenerator<Record<string, unknown>> {
|
|
const getUserItems = (page: number) =>
|
|
diigoAPI
|
|
.pathjoin("load_user_items")
|
|
.query({ sort: "updated", count, page_num: page })
|
|
.get()
|
|
.then(JSON.parse) as Promise<{ total: number; items: Record<string, unknown>[] }>;
|
|
|
|
const first = await getUserItems(1);
|
|
const totalPages = Math.ceil(first.total / count);
|
|
log({ event: "start", total: first.total, pages, totalPages });
|
|
|
|
let got = 0;
|
|
for (let page = 1; page <= Math.min(pages, totalPages); page += 1) {
|
|
const data = page === 1 ? first : await getUserItems(page);
|
|
yield* data.items;
|
|
got += data.items.length;
|
|
log({ event: "page", page, of: pages, got });
|
|
}
|
|
} |