@@ -15,19 +15,17 @@ import Data.Tuple.Nested (type (/\), (/\))
15
15
import Debug.Trace (spy )
16
16
import Record as Record
17
17
18
- import Data.Diagram.FromNLL as FromNLL
19
- import Data.Diagram.FromNLL (ErrDiagramEncoding )
20
- import Data.Petrinet.Representation.NLL as Net
21
18
import Data.Petrinet.Representation.PNPRO as PNPRO
22
19
import Data.Petrinet.Representation.PNPROtoDict as PNPRO
23
- import Statebox.Core.Types (Diagram , PathElem )
20
+ import Statebox.Core.Types (Diagram )
24
21
import Statebox.Core.Transaction (HashStr , TxSum , FiringTx , WiringTx )
25
22
import Statebox.Core.Lenses (_wiringTx , _firingTx )
26
23
import View.Diagram.Model (DiagramInfo )
27
24
import View.Model (Project , ProjectName , NetInfoWithTypesAndRoles )
28
25
import View.Petrinet.Model (NetInfo )
29
- import View.Petrinet.Model.NLL as NLL
30
- import View.Studio.Model.Route (Route , RouteF (..), ResolvedRouteF (..), NetName , DiagramName , NodeIdent (..), ExecutionTrace )
26
+ import View.Studio.Model.Route (ApiRoute (..), Route , RouteF (..), ResolvedRouteF (..), NetName , DiagramName , NodeIdent (..))
27
+ import View.Studio.Model.TxCache as TxCache
28
+ import View.Studio.Model.TxCache (ExecutionTrace )
31
29
32
30
-- deps needed for Action, for now
33
31
import View.Petrinet.Model as PetrinetEditor
@@ -59,29 +57,33 @@ type State =
59
57
-- ------------------------------------------------------------------------------
60
58
61
59
resolveRoute :: RouteF ProjectName DiagramName NetName -> State -> Maybe (ResolvedRouteF Project DiagramInfo NetInfoWithTypesAndRoles )
62
- resolveRoute route {projects, hashSpace} = case route of
60
+ resolveRoute route state = case route of
63
61
Home -> pure ResolvedHome
64
- Types projectName -> ResolvedTypes <$> findProject projects projectName
65
- Auths projectName -> ResolvedAuths <$> findProject projects projectName
66
- Net projectName name -> do project <- findProject projects projectName
62
+ Types projectName -> ResolvedTypes <$> findProject state. projects projectName
63
+ Auths projectName -> ResolvedAuths <$> findProject state. projects projectName
64
+ Net projectName name -> do project <- findProject state. projects projectName
67
65
net <- findNetInfoWithTypesAndRoles project name
68
66
pure $ ResolvedNet net
69
- Diagram projectName name nodeId -> do project <- findProject projects projectName
67
+ Diagram projectName name nodeId -> do project <- findProject state. projects projectName
70
68
diagram <- findDiagramInfo project name
71
69
let node = nodeId >>= case _ of
72
70
DiagramNode dn -> DiagramNode <$> findDiagramInfo project dn
73
71
NetNode nn -> NetNode <$> findNetInfoWithTypesAndRoles project nn
74
72
pure $ ResolvedDiagram diagram node
73
+ ApiThing x -> resolveApiRoute x state.hashSpace
74
+
75
+ resolveApiRoute :: ApiRoute -> AdjacencySpace HashStr TxSum -> Maybe (ResolvedRouteF Project DiagramInfo NetInfoWithTypesAndRoles )
76
+ resolveApiRoute route hashSpace = case route of
75
77
UberRootR url -> pure $ ResolvedUberRoot url
76
78
NamespaceR hash -> pure $ ResolvedNamespace hash
77
- WiringR x -> ResolvedWiring x <$> findWiringTx hashSpace x.hash
79
+ WiringR x -> ResolvedWiring x <$> TxCache . findWiringTx hashSpace x.hash
78
80
FiringR x -> ResolvedFiring x <$> firingTxM <*> pure execTrace
79
81
where
80
- firingTxM = findFiringTx hashSpace x.hash
81
- execTrace = findExecutionTrace hashSpace x.hash execHash
82
+ firingTxM = TxCache . findFiringTx hashSpace x.hash
83
+ execTrace = TxCache . findExecutionTrace hashSpace x.hash execHash
82
84
execHash = firingTxM >>= _.firing.execution # fromMaybe x.hash
83
- DiagramR wiringHash ix name -> (\d -> ResolvedDiagram d Nothing ) <$> findDiagramInfoInWirings hashSpace wiringHash ix
84
- NetR wiringHash ix name -> (\n -> ResolvedNet n) <$> findNetInfoInWirings hashSpace wiringHash ix
85
+ DiagramR wiringHash ix name -> (\d -> ResolvedDiagram d Nothing ) <$> TxCache .findDiagramInfo hashSpace wiringHash ix
86
+ NetR wiringHash ix name -> (\n -> ResolvedNet n) <$> TxCache .findNetInfo hashSpace wiringHash ix
85
87
86
88
findProject :: Array Project -> ProjectName -> Maybe Project
87
89
findProject projects projectName = find (\p -> p.name == projectName) projects
@@ -106,42 +108,6 @@ modifyDiagramInfo diagramName fn diagrams = do
106
108
ix <- findIndex (\d -> d.name == diagramName) diagrams
107
109
modifyAt ix fn diagrams
108
110
109
- findWiringTx :: AdjacencySpace HashStr TxSum -> HashStr -> Maybe WiringTx
110
- findWiringTx hashSpace wiringHash = preview _wiringTx =<< AdjacencySpace .lookup wiringHash hashSpace
111
-
112
- findFiringTx :: AdjacencySpace HashStr TxSum -> HashStr -> Maybe FiringTx
113
- findFiringTx hashSpace firingHash = preview _firingTx =<< AdjacencySpace .lookup firingHash hashSpace
114
-
115
- findNetInfoInWirings :: AdjacencySpace HashStr TxSum -> HashStr -> PathElem -> Maybe NetInfoWithTypesAndRoles
116
- findNetInfoInWirings hashSpace wiringHash ix = do
117
- wiring <- findWiringTx hashSpace wiringHash
118
- netW <- spy " findNetInfoInWirings: netW" $ wiring.wiring.nets `index` ix
119
- netTopo <- spy " findNetInfoInWirings: netTopo" $ Net .fromNLLMaybe 0 netW.partition
120
- let
121
- placeNames = NLL .defaultPlaceNames netTopo
122
- netInfo = spy " findNetInfoInWirings: netInfo" $ NLL .toNetInfoWithDefaults netTopo netW.name placeNames netW.names
123
- pure $ Record .merge { types: [] , roleInfos: [] } netInfo
124
-
125
- findDiagramInfoInWirings :: AdjacencySpace HashStr TxSum -> HashStr -> PathElem -> Maybe DiagramInfo
126
- findDiagramInfoInWirings hashSpace wiringHash ix =
127
- hush =<< diagramEitherMaybe
128
- where
129
- diagramEitherMaybe :: Maybe (ErrDiagramEncoding \/ DiagramInfo )
130
- diagramEitherMaybe = (\d -> FromNLL .fromNLL d.name (toNLL d)) <$> diagramMaybe
131
-
132
- diagramMaybe :: Maybe Diagram
133
- diagramMaybe = (flip index ix <<< _.wiring.diagrams) =<< findWiringTx hashSpace wiringHash
134
-
135
- toNLL d = [d.width] <> d.pixels
136
-
137
- findExecutionTrace :: AdjacencySpace HashStr TxSum -> HashStr -> HashStr -> String \/ ExecutionTrace
138
- findExecutionTrace s firingHash executionHash =
139
- hashChainE # bimap (const " Failed to resolve execution trace, probably because a parent hash was missing from the space." )
140
- (map (\hash -> hash /\ AdjacencySpace .lookup hash s))
141
- where
142
- hashChainE :: Array HashStr \/ Array HashStr
143
- hashChainE = AdjacencySpace .unsafeAncestorsBetween s firingHash executionHash
144
-
145
111
-- ------------------------------------------------------------------------------
146
112
147
113
fromPNPROProject :: PNPRO.Project -> Project
0 commit comments