Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
type Value = string | number | boolean | null | undefined | object | Value[]; // Possible value types
|
|
type Changes = { [key: string]: { before: Value; after: Value } | Changes }; // Recursive changes type
|
|
|
|
function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): Changes {
|
|
// Helper function to check if a value is an object (excluding arrays)
|
|
function isObject(obj: any): obj is Record<string, any> {
|
|
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
|
}
|
|
|
|
// Recursive function to compare two objects and return the differences
|
|
function compareObjects(o1: Record<string, any>, o2: Record<string, any>): Changes {
|
|
const changes: Changes = {};
|
|
|
|
// Iterate over keys in the first object (o1)
|
|
for (const key in o1) {
|
|
if (isObject(o1[key]) && isObject(o2[key])) {
|
|
// Recursively compare nested objects
|
|
const nestedChanges = compareObjects(o1[key], o2[key]);
|
|
if (Object.keys(nestedChanges).length > 0) {
|
|
changes[key] = nestedChanges; // Add nested changes if any
|
|
}
|
|
} else if (Array.isArray(o1[key]) && Array.isArray(o2[key])) {
|
|
// Compare arrays
|
|
if (o1[key].length !== o2[key].length || o1[key].some((val, index) => val !== o2[key][index])) {
|
|
changes[key] = { before: o1[key], after: o2[key] };
|
|
}
|
|
} else {
|
|
// Compare primitive values (or any non-object, non-array values)
|
|
if (o1[key] !== o2[key]) {
|
|
changes[key] = { before: o1[key], after: o2[key] };
|
|
}
|
|
}
|
|
}
|
|
|
|
// Iterate over keys in the second object (o2) to detect new keys
|
|
for (const key in o2) {
|
|
if (!(key in o1)) {
|
|
changes[key] = { before: undefined, after: o2[key] };
|
|
}
|
|
}
|
|
|
|
return changes; // Return the collected changes
|
|
}
|
|
|
|
return compareObjects(obj1, obj2); // Compare the two input objects
|
|
}
|
|
|
|
export default findDifferences; |