fix: normalise compatible live reconstruction responses
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user