export type Depth = 0 | 1 | 2 | 3; export type Status = "planned" | "in-progress" | "completed" | "archived"; export type Artifact = { kind: "source" | "demo" | "notes" | "test"; title: string; href: string; }; export type PortfolioObject = { slug: string; title: string; category: string; status: Status; summary: string; question: string; overview: string; contribution: string; limitation: string; tools: string[]; anchorId: string; availableDepths: Depth[]; caseStudy?: "constellation" | "hidden-path"; artifacts: Artifact[]; role?: string; image?: { file: string; alt: string; caption: string }; }; export type Profile = { name: string; location: string; email: string; discipline: string; focus: string; introduction: string; background: string; resumePdf: string | null; featuredSlug: string; }; // Deliberately review a new public destination before exposing it through content. export const artifactKinds = new Map([ ["/constellation-proof.ts", "source"], ["/observatory#proof-lab", "demo"], ["/proof-notes.txt", "notes"], ["/proof-vector.json", "test"], ["/hidden-path/circuit.circom", "source"], ["/work/hidden-path?d=3", "demo"], ["/hidden-path/v1/example.json", "test"], ["/hidden-path/v1/manifest.json", "notes"], ]); function record(value: unknown): value is Record { return value !== null && typeof value === "object" && !Array.isArray(value); } function hasText(value: unknown): value is string { return typeof value === "string" && value.trim().length > 0; } const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/; export function validateContent(profile: unknown, projects: unknown): void { if ( !record(profile) || ![ "name", "location", "email", "discipline", "focus", "introduction", "background", "featuredSlug", ].every((key) => hasText(profile[key])) ) { throw new Error( "The profile requires a name, professional summary and contact details.", ); } if ( !/^[^\s@<>?&#]+@[^\s@<>?&#]+\.[^\s@<>?&#]+$/.test(String(profile.email)) ) { throw new Error("Invalid contact email."); } if ( profile.resumePdf !== null && !/^\/approved-media\/[a-z\d-]+\.pdf$/.test(String(profile.resumePdf)) ) { throw new Error("The résumé PDF must be a reviewed local document."); } if (!Array.isArray(projects) || !projects.length) throw new Error("Missing work index."); const slugs = new Set(); const anchors = new Set(); for (const project of projects) { if ( !record(project) || ![ "title", "category", "summary", "question", "overview", "contribution", "limitation", ].every((key) => hasText(project[key])) ) { throw new Error( "Project overview, contribution and limitations are required.", ); } for (const [id, seen] of [ [project.slug, slugs], [project.anchorId, anchors], ] as const) { if (!hasText(id) || !slugPattern.test(id) || seen.has(id)) throw new Error("Invalid or duplicate project identifier."); seen.add(id); } if ( !["planned", "in-progress", "completed", "archived"].includes( String(project.status), ) ) { throw new Error("Unknown project status."); } const layers = project.availableDepths; if ( !Array.isArray(layers) || layers[0] !== 0 || !layers.every( (depth, i) => Number.isInteger(depth) && depth >= 0 && depth <= 3 && (!i || layers[i - 1] < depth), ) ) { throw new Error( "Published layers must start at Surface and have distinct, ascending depths.", ); } if ( project.caseStudy !== undefined && project.caseStudy !== "constellation" && project.caseStudy !== "hidden-path" ) throw new Error("Unknown case-study renderer."); if (layers.length > 1 && !project.caseStudy) throw new Error("A published layer needs a registered case study."); if ( !Array.isArray(project.tools) || !project.tools.length || !project.tools.every(hasText) ) { throw new Error("Project tools must be named."); } if ( !Array.isArray(project.artifacts) || !project.artifacts.length || !project.artifacts.every( (item: unknown) => record(item) && hasText(item.title) && hasText(item.href) && artifactKinds.has(item.href) && artifactKinds.get(item.href) === item.kind, ) ) throw new Error("Missing or unreviewed project artifact."); if ( project.caseStudy === "hidden-path" && (project.slug !== "hidden-path" || ![ "/hidden-path/circuit.circom", "/hidden-path/v1/example.json", "/hidden-path/v1/manifest.json", ].every((href) => (project.artifacts as Artifact[]).some((item) => item.href === href), )) ) throw new Error( "Hidden Path requires its circuit, receipt and pinned manifest.", ); if ( project.caseStudy === "constellation" && ![ "/constellation-proof.ts", "/proof-vector.json", "/proof-notes.txt", ].every((href) => (project.artifacts as Artifact[]).some((item) => item.href === href), ) ) throw new Error( "The Constellation layers require their implementation, vector and protocol notes.", ); } if (!slugs.has(String(profile.featuredSlug))) throw new Error("Unknown featured project."); }