papertrail/lib/ingest/sourcesByEntity.schemas.ts
caelum0x 4bb067d5d5 feat: Phase 2 multi-source ingest — evidence integrator (FAERS/ClinVar/ChEMBL/OpenTargets/PubTator)
- 0063 migrations: sources provenance columns (variant_id/compound_id/adverse_event_cui/
  source_version/source_snapshot_id/snapshot_date) + document_entities + source_access_log;
  dropped the sources.source_type CHECK so new providers can cache
- lib/ingest/multiSourcePipeline.ts + drivers/{faers,clinvar,chembl,openTargets,pubtator}.ts
  (cache-once, wraps existing bio engines) + provenance.ts (recordAccess, deterministic snapshot id)
- lib/ingest/entityCanonicalization.ts: ingest-time NER -> deterministic canonicalize -> document_entities
- backend/engines/{faers,clinvar,chembl}/run.py: PaperTrail-native ingest bridges (in-place)
- /api/ingest/multi-source, /api/sources/by-entity, /api/entities/[curie]/sources,
  /api/sources/quality-report + /console/sources/ingest page

tsc + build green; 0063 migrations applied to Neon.
2026-07-10 23:53:39 +03:00

41 lines
1.5 KiB
TypeScript

import { z } from "zod";
// Request validation for the "sources tagged with a canonical entity" routes.
//
// A CURIE is a compact URI of the form <prefix>:<local-id> (HGNC:6024, EFO:0000756,
// CHEMBL:CHEMBL1201585, ...). We validate the SHAPE at the trust boundary (never trust a
// raw query param): a non-empty prefix, a colon, and a non-empty local id, length-capped
// so a pathological string can't reach the DB. limit/offset are coerced from their string
// query-param form and bounded; the queries layer clamps again defensively.
const CURIE_RE = /^[A-Za-z0-9._]+:[A-Za-z0-9._-]+$/;
export const SourcesByEntityQuerySchema = z.object({
curie: z
.string()
.trim()
.min(3)
.max(128)
.regex(CURIE_RE, "curie must be a CURIE of the form PREFIX:LOCAL_ID (e.g. HGNC:6024)"),
limit: z.coerce.number().int().min(1).max(100).optional(),
offset: z.coerce.number().int().min(0).optional(),
});
export type SourcesByEntityQuery = z.infer<typeof SourcesByEntityQuerySchema>;
// The path-param variant (/api/entities/[curie]/sources) validates only the CURIE from the
// path; limit/offset still come from the query string.
export const CurieParamSchema = z
.string()
.trim()
.min(3)
.max(128)
.regex(CURIE_RE, "curie must be a CURIE of the form PREFIX:LOCAL_ID (e.g. HGNC:6024)");
export const PaginationQuerySchema = z.object({
limit: z.coerce.number().int().min(1).max(100).optional(),
offset: z.coerce.number().int().min(0).optional(),
});
export type PaginationQuery = z.infer<typeof PaginationQuerySchema>;