// Research's addresses, one builder per URL shape (the lib/hrefs.ts rule: // a literal link is one P-phase has to find by hand). In their own module // because lib/hrefs.ts belongs to P3 while R1 runs beside it. // // The page's state is in its query, so a search is a link: // /research?q=…&source=…&channels=a,b&from=YYYY-MM-DD&to=…&states=…&media=…&posts=1 import { withQuery } from "../hrefs"; import type { Scope } from "./types"; export type ResearchQuery = Partial & { q?: string; /** The case a pin goes to (R2). */ case?: string }; function scopeQuery(s: Partial) { return { source: s.source, channels: s.channels?.length ? s.channels.join(",") : undefined, from: s.dateFrom, to: s.dateTo, states: s.states?.length ? s.states.join(",") : undefined, media: s.mediaType, posts: s.posts === true, }; } /** The Research page, with a query and a scope when given. */ export function researchHref(q: ResearchQuery = {}): string { return withQuery("/research", { q: q.q, ...scopeQuery(q), case: q.case }); } // ── R2: the boards (cases) ── const enc = encodeURIComponent; /** A case's board. */ export function researchCaseHref(id: string): string { return `/research/${enc(id)}`; } /** A case's pipeline (release 38): its stages beside the board. */ export function researchCasePipelineHref(id: string, stage?: string): string { return `/research/${enc(id)}/pipeline${stage ? `#stage-${stage}` : ""}`; } /** The pipeline's API (app/api/research/cases/[id]/pipeline/[op]/route.ts documents it). */ export const researchCasePipelineApi = (id: string, op?: string) => `/api/research/cases/${enc(id)}/pipeline${op ? `/${enc(op)}` : ""}`; /** Research with a case's scope and query, pins going to the case. */ export function researchFromCaseHref(c: { id: string; scope: Partial & { query?: string } }): string { const { query, ...scope } = c.scope; return researchHref({ ...scope, q: query, case: c.id }); } /** The case API (app/api/research/cases/route.ts documents it). */ export const researchCasesApi = () => "/api/research/cases"; export const researchCaseApi = (id: string) => `/api/research/cases/${enc(id)}`; export const researchCaseQuotesApi = (id: string) => `/api/research/cases/${enc(id)}/quotes`; export const researchCaseQuoteApi = (id: string, qid: string) => `/api/research/cases/${enc(id)}/quotes/${enc(qid)}`; export const researchCaseVerifyApi = (id: string) => `/api/research/cases/${enc(id)}/verify`; export const researchCaseHandoffApi = (id: string) => `/api/research/cases/${enc(id)}/handoff`; export function researchCaseExportApi(id: string, opts: { download?: boolean } = {}): string { return withQuery(`/api/research/cases/${enc(id)}/export.md`, { download: opts.download === true }); } /** The archive inventory (channels × years). */ export function researchArchiveHref(q: Partial = {}): string { return withQuery("/research/archive", scopeQuery(q)); } /** GET /api/research/scope for a scope. */ export function researchScopeApi(s: Partial): string { return withQuery("/api/research/scope", scopeQuery(s)); } /** GET /api/research/coverage for a scope. */ export function researchCoverageApi(s: Partial, opts: { fresh?: boolean } = {}): string { return withQuery("/api/research/coverage", { ...scopeQuery(s), fresh: opts.fresh === true }); } /** GET /api/research/window: the transcript ±span around a cue. */ export function researchWindowApi(w: { source: string; channel: string; video: string; t: number; span?: number; track?: string; kind?: "video" | "post"; }): string { return withQuery("/api/research/window", { source: w.source, channel: w.channel, video: w.video, t: w.t, span: w.span, track: w.track, kind: w.kind === "post" ? "post" : undefined, }); } /** GET /api/research/media: one local file the reader offered. */ export function researchMediaApi(m: { source: string; channel: string; video: string; file: string }): string { return withQuery("/api/research/media", m); }