41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
function cloneJsonSafe(value) {
|
|
if (value == null) return value;
|
|
return JSON.parse(JSON.stringify(value));
|
|
}
|
|
|
|
export function normaliseAnalysisResponse(input) {
|
|
const normalised = cloneJsonSafe(input);
|
|
const changesApplied = [];
|
|
const warnings = [];
|
|
|
|
if (!normalised || typeof normalised !== "object") {
|
|
return { normalised: input, changesApplied, warnings };
|
|
}
|
|
|
|
if (Array.isArray(normalised.evidence)) {
|
|
normalised.evidence = normalised.evidence.map((record, index) => {
|
|
if (!record || typeof record !== "object") return record;
|
|
|
|
if (record.source === null) {
|
|
changesApplied.push({
|
|
path: ["evidence", index, "source"],
|
|
change: "Converted null source to undefined",
|
|
});
|
|
|
|
const { source: _removed, ...rest } = record;
|
|
return rest;
|
|
}
|
|
|
|
return record;
|
|
});
|
|
}
|
|
|
|
if (changesApplied.length > 0) {
|
|
warnings.push(
|
|
"Applied deterministic reconstruction compatibility normalisation",
|
|
);
|
|
}
|
|
|
|
return { normalised, changesApplied, warnings };
|
|
}
|