


MAXI HEAVY INDUSTRIESSOURCE STUDIES / 04
01 / LOGIC
const visited=new Set<string>();
function visit(id:string){
if(visited.has(id)){fail('Cycles and shared children are not allowed');return;} visited.add(id);TYPESCRIPT04
The shape of a boundary
app/src/schema.ts
Source code, selected fragment.
Read complete excerpt +
if(s.elements[s.root]?.type!=='Workspace')fail('Root must be Workspace');
const visited=new Set<string>();
const fields=new Set<string>();
function visit(id:string){
if(visited.has(id)){fail('Cycles and shared children are not allowed');return;} visited.add(id);
const e=s.elements[id];if(!e){fail('Missing element '+id);return;}
if(!components[e.type].props.safeParse(e.props).success)fail('Invalid props: '+id);
if(e.type!=='Workspace'&&e.children?.length)fail('Only Workspace accepts children');
if(id!==s.root&&e.type==='Workspace')fail('Only one root Workspace is allowed');
if(typeof e.props.field==='string'){if(fields.has(e.props.field))fail('Duplicate input field');fields.add(e.props.field);}
if(e.type==='Table'&&Array.isArray(e.props.rows)&&Array.isArray(e.props.columns)&&e.props.rows.some((row)=>Array.isArray(row)&&row.length!==(e.props.columns as unknown[]).length))fail('Table rows must match columns');
for(const child of e.children??[])visit(child);
}
visit(s.root);if(visited.size!==Object.keys(s.elements).length)fail('Unreachable elements');
});