var E=(e=>(e.node="node",e.link="link",e.backdrop="backdrop",e))(E||{}),l=(e=>(e.black="black",e.red="labels.red",e.orange="labels.orange",e.purple="labels.purple",e.blueShade1="labels.blueShade1",e.yellow="labels.yellow",e.yellowLight="labels.yellowShade2",e.green="labels.green",e.blue="labels.blue",e.redShade3="labels.redShade2",e.orangeShade3="labels.orangeShade2",e))(l||{}),u=(e=>(e.current="current",e.deleted="deleted",e.shared="shared",e.notAccessible="not accessible",e.faulty="faulty",e))(u||{}),o=(e=>(e.storageConnector="storage connector",e.featureGroup="feature group",e.externalFeatureGroup="external feature group",e.featureView="feature view",e.trainingDataset="training dataset",e.model="model",e.experiment="experiment",e.link="link",e))(o||{});function h(e){const r={id:e.id,type:e.type};return JSON.stringify(r)}const S={EXTERNAL_FEATURE_GROUP:o.externalFeatureGroup,FEATURE_GROUP:o.featureGroup,FEATURE_VIEW:o.featureView,TRAINING_DATASET:o.trainingDataset,MODEL:o.model,STORAGE_CONNECTOR:o.storageConnector},y={[o.storageConnector]:l.black,[o.featureGroup]:l.orange,[o.externalFeatureGroup]:l.blue,[o.featureView]:l.purple,[o.trainingDataset]:l.green,[o.model]:l.blueShade1,[o.experiment]:l.red,[o.link]:l.black},A=e=>{const r=p(e),c=[],n=[],a=new Set;m(r,e.upstream,c,n,a);const s=[],t=[],i=new Set;k(r,e.downstream,s,t,i);const d={nodes:c,links:b(n)},f={nodes:s,links:b(t)},w=d.nodes.length+f.nodes.length;return{root:r,upstream:d,downstream:f,count:w}},b=e=>{const r=new Map;e.forEach(({source:n,target:a})=>{r.has(n)||r.set(n,new Set),r.get(n).add(a)});const c=(n,a)=>{const s=[...r.get(n)??[]].filter(i=>i!==a),t=new Set;for(;s.length;){const i=s.pop();if(i===a)return!0;t.has(i)||(t.add(i),(r.get(i)??[]).forEach(d=>s.push(d)))}return!1};return e.filter(({source:n,target:a})=>!c(n,a))},g=(e,r)=>({source:h(e),target:h(r),type:o.link,metaType:u.current}),p=e=>{var n,a;const r=s=>s.deleted?u.deleted:s.accessible?s.shared?u.shared:s.exceptionCause?u.faulty:u.current:u.notAccessible,c={id:e.node.artifact.id,name:e.node.artifact.name,deprecated:(n=e.node.artifact)==null?void 0:n.deprecated,version:e.node.artifact.version,project:"unknown",type:S[e.node.artifactType],metaType:r(e.node),artifact:{href:(a=e.node.artifact)==null?void 0:a.href},deleted:e.node.deleted,traversed:e.node.traversed};return e.node.accessible?c.project=e.node.artifact.featurestoreName:c.project=e.node.artifact.project,c},m=(e,r,c,n,a)=>{r.forEach(s=>{const t=p(s);a.has(`${t.id}_${t.type}`)||(a.add(`${t.id}_${t.type}`),c.push(t)),n.push(g(e,t)),m(t,s.upstream,c,n,a)})},k=(e,r,c,n,a)=>{r.forEach(s=>{const t=p(s);a.has(`${t.id}_${t.type}`)||(a.add(`${t.id}_${t.type}`),c.push(t));const i=g(e,t);n.push(i),k(t,s.downstream,c,n,a)})};export{E,u as N,o as a,A as b,y as c,h as n};
