Admit scoped structural edits with snapshot identity manifests and replay proofs

This commit is contained in:
2026-11-09 04:40:03 +08:00
parent 6c0a421f59
commit 945aaea504
24 changed files with 292 additions and 74 deletions
+9
View File
@@ -10,3 +10,12 @@ export function validateCanvasElementCounts(value:unknown,canvasIds:readonly Id[
for(const count of Object.values(counts)){if(typeof count!=='number'||!Number.isSafeInteger(count)||count<0)throw fault('invalid_model_coverage');sum+=count;if(!Number.isSafeInteger(sum))throw fault('invalid_model_coverage');}
if(sum!==total)throw fault('invalid_model_coverage');
}
/** All active IDs in the capture, including records not yet received. */
export type ElementOwners=Readonly<Record<Id,Id>>;
export function validateElementOwners(value:unknown,counts:CanvasElementCounts,total:number):asserts value is ElementOwners {
if(!value||typeof value!=='object'||Array.isArray(value)||Object.keys(value).length!==total)throw fault('invalid_model_identity');
const actual:Record<Id,number>=Object.create(null);
for(const [id,owner]of Object.entries(value)){if(!id||typeof owner!=='string'||!Object.hasOwn(counts,owner))throw fault('invalid_model_identity');actual[owner]=(actual[owner]??0)+1;}
if(Object.keys(counts).some(id=>(actual[id]??0)!==counts[id]))throw fault('invalid_model_identity');
}