app/db/publications.ts
101 lines and 12 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| listPublishedPublications | 14 to 20 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| <anonymous:19> | 19 to 19 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| listPublishedPublicationSources | 23 to 29 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| <anonymous:28> | 28 to 28 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| getPublishedPublication | 32 to 41 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| getPublishedPublicationMarkdown | 44 to 53 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| listPublishedPublicationTwins | 56 to 62 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| listPublishedCslRecords | 65 to 73 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| <anonymous:71> | 71 to 71 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| <anonymous:72> | 72 to 72 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| listPublicationIdentities | 76 to 92 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| getPublicationRow | 95 to 111 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
Imports
It imports app/db/client.ts, app/db/schema.ts, app/lib/publications/record.mjs, app/lib/publications/types.ts, app/lib/search/visibility.mjs. Imported by app/db/cv.ts, app/kb/procedures/proof.server.ts, app/lib/carrel/publication-handler.server.ts, app/lib/cv/save.server.ts, app/lib/llms/save.server.ts, app/lib/operator/api.server.ts, app/lib/publications/by-slug.ts, app/lib/publications/save.server.ts, app/lib/publications/sources.server.ts, app/lib/search/ask.server.ts, app/lib/site-urls.server.ts, app/routes/home.tsx, app/routes/publications.$slug[.md].ts, app/routes/publications.tsx, app/routes/publications[.bib].ts, app/routes/publications[.json].ts, app/routes/publications[.ris].ts.
Source
// The publications and publication_citations tables: read by the paper pages, the exports, the sitemap,
// the home page and the operator API. Written only by app/lib/publications/write.server.ts, from a compile
// (app/lib/publications/compile.mjs).
import { and, asc, eq } from "drizzle-orm";
import type { Publication } from "~/lib/publications/types";
import { sortPublications } from "~/lib/publications/record.mjs";
import { PUBLISHED_STATUS } from "~/lib/search/visibility.mjs";
import { getDb } from "./client";
import { publications } from "./schema";
/** Every published paper, newest first: the order the index, the exports and the CSL file all follow. */
export async function listPublishedPublications(env: Env): Promise<Publication[]> {
const rows = await getDb(env)
.select({ record: publications.record })
.from(publications)
.where(eq(publications.status, PUBLISHED_STATUS));
return sortPublications(rows.map((row) => JSON.parse(row.record) as Publication));
}
/** For the sitemap's dates (app/lib/site-urls.server.ts): every published paper's source file, by slug. */
export async function listPublishedPublicationSources(env: Env) {
const rows = await getDb(env)
.select({ slug: publications.slug, sourcePath: publications.sourcePath })
.from(publications)
.where(eq(publications.status, PUBLISHED_STATUS));
return new Map(rows.map((row) => [row.slug, row.sourcePath]));
}
/** The paper a `/research/publications/<slug>` URL names, or null. A draft is not public: it answers as absent. */
export async function getPublishedPublication(env: Env, slug: string): Promise<Publication | null> {
const row = (
await getDb(env)
.select({ record: publications.record })
.from(publications)
.where(and(eq(publications.slug, slug), eq(publications.status, PUBLISHED_STATUS)))
.limit(1)
)[0];
return row ? (JSON.parse(row.record) as Publication) : null;
}
/** The twin, published rows only: a draft's twin answers 404 like its page. */
export async function getPublishedPublicationMarkdown(env: Env, slug: string): Promise<string | null> {
const row = (
await getDb(env)
.select({ markdown: publications.markdown })
.from(publications)
.where(and(eq(publications.slug, slug), eq(publications.status, PUBLISHED_STATUS)))
.limit(1)
)[0];
return row?.markdown ?? null;
}
/** Each published twin by slug, for the Ask index to upload. */
export async function listPublishedPublicationTwins(env: Env): Promise<Array<{ slug: string; markdown: string }>> {
return getDb(env)
.select({ slug: publications.slug, markdown: publications.markdown })
.from(publications)
.where(eq(publications.status, PUBLISHED_STATUS))
.orderBy(asc(publications.slug));
}
/** The raw Crossref records of the published papers that carry one, in the index's order, for the .json export. */
export async function listPublishedCslRecords(env: Env): Promise<unknown[]> {
const rows = await getDb(env)
.select({ title: publications.title, year: publications.year, csl: publications.csl })
.from(publications)
.where(eq(publications.status, PUBLISHED_STATUS));
return sortPublications(rows)
.filter((row) => row.csl !== null)
.map((row) => JSON.parse(row.csl as string) as unknown);
}
/** Every row's identity, any status, for the save's uniqueness checks and the operator's list. */
export async function listPublicationIdentities(env: Env) {
return getDb(env)
.select({
slug: publications.slug,
doiKey: publications.doiKey,
status: publications.status,
stage: publications.stage,
type: publications.type,
title: publications.title,
year: publications.year,
record: publications.record,
sourceBlobSha: publications.sourceBlobSha,
syncedAt: publications.syncedAt,
})
.from(publications)
.orderBy(asc(publications.slug));
}
/** The stored row for a slug, any status, or null. */
export async function getPublicationRow(env: Env, slug: string) {
return (
(
await getDb(env)
.select({
slug: publications.slug,
status: publications.status,
sourceBlobSha: publications.sourceBlobSha,
syncedAt: publications.syncedAt,
record: publications.record,
})
.from(publications)
.where(eq(publications.slug, slug))
.limit(1)
)[0] ?? null
);
}