Certify loaded canvas scopes and publish completeness with runtime queries

This commit is contained in:
2026-11-09 03:42:08 +08:00
parent ef08222915
commit cabf2ec667
26 changed files with 209 additions and 48 deletions
+12
View File
@@ -0,0 +1,12 @@
import type {Id} from '../canvas-core/types.ts';
import {fault} from '../canvas-core/values.ts';
/** Snapshot-bound direct membership counts, including nodes and connections. */
export type CanvasElementCounts=Readonly<Record<Id,number>>;
export function validateCanvasElementCounts(value:unknown,canvasIds:readonly Id[],total:number):asserts value is CanvasElementCounts {
if(!value||typeof value!=='object'||Array.isArray(value))throw fault('invalid_model_coverage');
const counts=value as Record<Id,unknown>,keys=Object.keys(counts);let sum=0;
if(keys.length!==canvasIds.length||canvasIds.some(id=>!Object.hasOwn(counts,id)))throw fault('invalid_model_coverage');
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');
}