Show dependency-closed model prefixes before full canvas loading
This commit is contained in:
@@ -34,6 +34,17 @@ export function commonCanvas(document: Document, left: Id, right: Id): Id {
|
||||
if (!result) throw fault('no_common_canvas', [left, right]);
|
||||
return result;
|
||||
}
|
||||
/** Validate one record before its graph dependencies have arrived. This does not
|
||||
* prove owner membership, endpoint existence or connection common ownership. */
|
||||
export function validateElementRecord(element: ElementRecord, registry: Registry, tombstones: ReadonlyMap<Id,number> = new Map(), componentData = true): void {
|
||||
if (!element || !validJson(element) || typeof element.id !== 'string' || !element.id || typeof element.ownerCanvasId !== 'string' || !element.ownerCanvasId || typeof element.componentId !== 'string' || !element.componentId || !['node','connection'].includes(element.structure) || !Number.isSafeInteger(element.incarnation) || element.incarnation < 1 || !Number.isSafeInteger(element.dataVersion) || element.dataVersion < 1 || !element.data || typeof element.data !== 'object' || Array.isArray(element.data) || !validJson(element.data)) throw fault('invalid_element', [element?.id]);
|
||||
const dead=tombstones.get(element.id);if(dead!==undefined&&element.incarnation<=dead)throw fault('stale_incarnation',[element.id]);
|
||||
const definition=registry.components.get(element.componentId);
|
||||
if(componentData&®istry.resolve(element)==='known'&&(!definition||definition.structure!==element.structure||!definition.validate(element.data)))throw fault('invalid_component_data',[element.id]);
|
||||
if(element.structure==='node'){if(!geometryValid(element.geometry))throw fault('invalid_geometry',[element.id]);}
|
||||
else if(!element.source||!element.target||typeof element.source.elementId!=='string'||!element.source.elementId||typeof element.target.elementId!=='string'||!element.target.elementId||[element.source,element.target].some(endpoint=>endpoint.portId!==undefined&&(typeof endpoint.portId!=='string'||!endpoint.portId))||!validJson(element.path))throw fault('invalid_endpoint',[element.id]);
|
||||
}
|
||||
|
||||
/** Cooperative validation over an immutable document; synchronous callers drain the same checks. */
|
||||
function* validateDocumentChecks(document: Document, registry: Registry, componentData:boolean): Generator<void, void> {
|
||||
if (!document.canvases.size) throw fault('missing_root');
|
||||
@@ -52,15 +63,9 @@ function* validateDocumentChecks(document: Document, registry: Registry, compone
|
||||
if (roots !== 1) throw fault('invalid_roots');
|
||||
for (const element of document.elements.values()) {
|
||||
yield;
|
||||
if (typeof element.id !== 'string' || !element.id || typeof element.componentId !== 'string' || !element.componentId || !['node','connection'].includes(element.structure) || !document.canvases.has(element.ownerCanvasId) || !Number.isSafeInteger(element.incarnation) || element.incarnation < 1 || !Number.isSafeInteger(element.dataVersion) || element.dataVersion < 1 || !element.data || typeof element.data !== 'object' || Array.isArray(element.data) || !validJson(element.data)) throw fault('invalid_element', [element.id]);
|
||||
const dead = document.tombstones.get(element.id);
|
||||
if (dead !== undefined && element.incarnation <= dead) throw fault('stale_incarnation', [element.id]);
|
||||
const definition = registry.components.get(element.componentId);
|
||||
if (componentData && registry.resolve(element) === 'known' && (!definition || definition.structure !== element.structure || !definition.validate(element.data))) throw fault('invalid_component_data', [element.id]);
|
||||
if (element.structure === 'node') {
|
||||
if (!geometryValid(element.geometry)) throw fault('invalid_geometry', [element.id]);
|
||||
} else {
|
||||
if (!element.source || !element.target || typeof element.source.elementId !== 'string' || typeof element.target.elementId !== 'string' || [element.source,element.target].some(endpoint => endpoint.portId !== undefined && (typeof endpoint.portId !== 'string' || !endpoint.portId))) throw fault('invalid_endpoint', [element.id]);
|
||||
validateElementRecord(element, registry, document.tombstones, componentData);
|
||||
if (!document.canvases.has(element.ownerCanvasId)) throw fault('invalid_element', [element.id]);
|
||||
if (element.structure === 'connection') {
|
||||
const source = document.elements.get(element.source.elementId), target = document.elements.get(element.target.elementId);
|
||||
if (!source || !target || source.structure !== 'node' || target.structure !== 'node' || !validJson(element.path)) throw fault('invalid_endpoint', [element.id]);
|
||||
if (commonCanvas(document, source.ownerCanvasId, target.ownerCanvasId) !== element.ownerCanvasId) throw fault('invalid_connection_owner', [element.id]);
|
||||
|
||||
Reference in New Issue
Block a user