module Drasil.Database.Dump (
ChunkType, DumpedChunkDB, dumpChunkDB, dumpChunkDeps
) where
import Drasil.Database.UID (UID)
import Drasil.Database.ChunkDB (findAll', typesRegistered, ChunkDB, allDependants)
import Drasil.Database.Maps (invert)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as SM
type ChunkType = String
type DumpedChunkDB = Map ChunkType [UID]
dumpChunkDB :: ChunkDB -> DumpedChunkDB
dumpChunkDB :: ChunkDB -> DumpedChunkDB
dumpChunkDB ChunkDB
cdb = [(ChunkType, [UID])] -> DumpedChunkDB
forall k a. Ord k => [(k, a)] -> Map k a
SM.fromList ([(ChunkType, [UID])] -> DumpedChunkDB)
-> [(ChunkType, [UID])] -> DumpedChunkDB
forall a b. (a -> b) -> a -> b
$ (SomeTypeRep -> (ChunkType, [UID]))
-> [SomeTypeRep] -> [(ChunkType, [UID])]
forall a b. (a -> b) -> [a] -> [b]
map (\SomeTypeRep
ty -> (SomeTypeRep -> ChunkType
forall a. Show a => a -> ChunkType
show SomeTypeRep
ty, SomeTypeRep -> ChunkDB -> [UID]
findAll' SomeTypeRep
ty ChunkDB
cdb)) (ChunkDB -> [SomeTypeRep]
typesRegistered ChunkDB
cdb)
type Dependencies = Map UID [UID]
type Dependants = Map UID [UID]
dumpChunkDeps :: ChunkDB -> (Dependants, Dependencies)
dumpChunkDeps :: ChunkDB -> (Dependants, Dependants)
dumpChunkDeps ChunkDB
db = (Dependants -> Dependants
forall v k. Ord v => Map k [v] -> Map v [k]
invert Dependants
allDeps, Dependants
allDeps)
where allDeps :: Dependants
allDeps = ChunkDB -> Dependants
allDependants ChunkDB
db