Skip to the content

Capsid menu

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

The functions of publications.ts
FunctionLinesComplexityCoveredCRAPMutation
listPublishedPublications14 to 201No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
<anonymous:19>19 to 191No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
listPublishedPublicationSources23 to 291No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
<anonymous:28>28 to 281No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
getPublishedPublication32 to 412No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
getPublishedPublicationMarkdown44 to 532No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
listPublishedPublicationTwins56 to 621No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
listPublishedCslRecords65 to 731No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
<anonymous:71>71 to 711No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
<anonymous:72>72 to 721No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
listPublicationIdentities76 to 921No data: no coverage report in this mapNo data: no coverage report in this mapNo data: no mutants in this code
getPublicationRow95 to 1112No data: no coverage report in this mapNo data: no coverage report in this mapNo 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
  );
}