module PGIP.GraphQL.Resolver.ToResult where
import PGIP.GraphQL.Result.Axiom as GraphQLResultAxiom
import PGIP.GraphQL.Result.Action as GraphQLResultAction
import PGIP.GraphQL.Result.Conjecture as GraphQLResultConjecture
import PGIP.GraphQL.Result.ConservativityStatus as GraphQLResultConservativityStatus
import PGIP.GraphQL.Result.DocumentLink as GraphQLResultDocumentLink
import PGIP.GraphQL.Result.FileRange as GraphQLResultFileRange
import PGIP.GraphQL.Result.IdReference (IdReference (..))
import PGIP.GraphQL.Result.Language as GraphQLResultLanguage
import PGIP.GraphQL.Result.LanguageMapping as GraphQLResultLanguageMapping
import PGIP.GraphQL.Result.Library as GraphQLResultLibrary
import PGIP.GraphQL.Result.LocIdReference (LocIdReference (..))
import PGIP.GraphQL.Result.Logic as GraphQLResultLogic
import PGIP.GraphQL.Result.LogicMapping as GraphQLResultLogicMapping
import PGIP.GraphQL.Result.Mapping as GraphQLResultMapping
import PGIP.GraphQL.Result.NativeDocument as GraphQLResultNativeDocument
import PGIP.GraphQL.Result.OMS as GraphQLResultOMS
import PGIP.GraphQL.Result.OMSSimple as GraphQLResultOMSSimple
import PGIP.GraphQL.Result.PremiseSelection as GraphQLResultPremiseSelection
import PGIP.GraphQL.Result.Reasoner as GraphQLResultReasoner
import PGIP.GraphQL.Result.ReasonerConfiguration as GraphQLResultReasonerConfiguration
import PGIP.GraphQL.Result.ReasonerOutput as GraphQLResultReasonerOutput
import PGIP.GraphQL.Result.ReasoningAttempt as GraphQLResultReasoningAttempt
import PGIP.GraphQL.Result.Sentence as GraphQLResultSentence
import PGIP.GraphQL.Result.Serialization as GraphQLResultSerialization
import PGIP.GraphQL.Result.Signature as GraphQLResultSignature
import PGIP.GraphQL.Result.SignatureMorphism as GraphQLResultSignatureMorphism
import PGIP.GraphQL.Result.StringReference (StringReference (..))
import PGIP.GraphQL.Result.Symbol as GraphQLResultSymbol
import PGIP.GraphQL.Result.SymbolMapping as GraphQLResultSymbolMapping
import Persistence.Schema as DatabaseSchema
import qualified Data.Text as Text
import Database.Esqueleto
actionToResult :: Entity DatabaseSchema.Action
actionToResult (Entity _ actionValue) =
show $ actionEvaluationState actionValue
, GraphQLResultAction.message = fmap Text.unpack $ actionMessage actionValue
}
axiomToResult :: Entity DatabaseSchema.Sentence
-> Entity DatabaseSchema.LocIdBase
-> Maybe (Entity DatabaseSchema.FileRange)
axiomToResult (Entity _ sentenceValue) (Entity _ locIdBaseValue) fileRangeM symbolResults =
{ GraphQLResultAxiom.__typename = "Axiom"
, GraphQLResultAxiom.fileRange = fmap fileRangeToResult fileRangeM
, GraphQLResultAxiom.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultAxiom.name = sentenceName sentenceValue
, GraphQLResultAxiom.symbols = symbolResults
, GraphQLResultAxiom.text = Text.unpack $ sentenceText sentenceValue
}
conjectureToResult :: Entity DatabaseSchema.Sentence
-> Entity DatabaseSchema.LocIdBase
-> Maybe (Entity DatabaseSchema.FileRange)
-> Entity DatabaseSchema.Conjecture
conjectureToResult (Entity _ sentenceValue) (Entity _ locIdBaseValue) fileRangeM
(Entity _ conjectureValue) actionResult symbolResults proofAttemptResults =
{ GraphQLResultConjecture.__typename = "Conjecture"
, GraphQLResultConjecture.fileRange = fmap fileRangeToResult fileRangeM
, GraphQLResultConjecture.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultConjecture.name = sentenceName sentenceValue
, GraphQLResultConjecture.symbols = symbolResults
, GraphQLResultConjecture.text = Text.unpack $ sentenceText sentenceValue
, GraphQLResultConjecture.action = actionResult
, GraphQLResultConjecture.proofAttempts = proofAttemptResults
}
conservativityStatusToResult :: Entity DatabaseSchema.ConservativityStatus
conservativityStatusToResult (Entity _ conservativityStatusValue) =
conservativityStatusRequired conservativityStatusValue
conservativityStatusProved conservativityStatusValue
}
documentLinkToResult :: Entity DatabaseSchema.LocIdBase
-> Entity DatabaseSchema.LocIdBase
documentLinkToResult sourceLocId targetLocId =
LocIdReference $ locIdBaseLocId $ entityVal sourceLocId
LocIdReference $ locIdBaseLocId $ entityVal targetLocId
}
fileRangeToResult :: Entity DatabaseSchema.FileRange
fileRangeToResult (Entity _ fileRangeValue) =
{ GraphQLResultFileRange.startLine = fileRangeStartLine fileRangeValue
, GraphQLResultFileRange.startColumn = fileRangeStartColumn fileRangeValue
, GraphQLResultFileRange.endLine = fileRangeEndLine fileRangeValue
, GraphQLResultFileRange.endColumn = fileRangeEndColumn fileRangeValue
, GraphQLResultFileRange.path = fileRangePath fileRangeValue
}
languageToResult :: Entity DatabaseSchema.Language
languageToResult (Entity _ languageValue) =
{ GraphQLResultLanguage.id = languageSlug languageValue
, GraphQLResultLanguage.name = languageName languageValue
, GraphQLResultLanguage.description = languageDescription languageValue
}
languageMappingToResult :: Entity DatabaseSchema.LanguageMapping
-> Entity DatabaseSchema.Language
-> Entity DatabaseSchema.Language
languageMappingToResult languageMappingEntity languageSource languageTarget =
fromIntegral $ fromSqlKey $ entityKey languageMappingEntity
StringReference $ DatabaseSchema.languageSlug $ entityVal languageSource
StringReference $ DatabaseSchema.languageSlug $ entityVal languageTarget
}
libraryToResult :: Entity DatabaseSchema.Document
-> Entity DatabaseSchema.LocIdBase
libraryToResult (Entity _ documentValue) (Entity _ locIdBaseValue)
documentLinksSourceResults documentLinksTargetResults omsResults =
{ GraphQLResultLibrary.__typename = "Library"
, GraphQLResultLibrary.displayName = documentDisplayName documentValue
, GraphQLResultLibrary.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultLibrary.name = documentName documentValue
, GraphQLResultLibrary.version = documentVersion documentValue
, GraphQLResultLibrary.documentLinksSource = documentLinksSourceResults
, GraphQLResultLibrary.documentLinksTarget = documentLinksTargetResults
, GraphQLResultLibrary.omsList = omsResults
}
logicToResult :: Entity DatabaseSchema.Logic
logicToResult (Entity _ logicValue) =
{ GraphQLResultLogic.id = logicSlug logicValue
, GraphQLResultLogic.name = logicName logicValue
}
logicMappingToResult :: Entity DatabaseSchema.LogicMapping
-> Entity DatabaseSchema.Logic
-> Entity DatabaseSchema.Logic
logicMappingToResult (Entity _ logicMappingValue) logicSource logicTarget languageMappingResult =
{ GraphQLResultLogicMapping.id = DatabaseSchema.logicMappingSlug logicMappingValue
, GraphQLResultLogicMapping.languageMapping = languageMappingResult
StringReference $ DatabaseSchema.logicSlug $ entityVal logicSource
StringReference $ DatabaseSchema.logicSlug $ entityVal logicTarget
}
mappingToResult :: Entity DatabaseSchema.Mapping
-> Entity DatabaseSchema.LocIdBase
-> Entity DatabaseSchema.SignatureMorphism
-> Maybe (Entity DatabaseSchema.ConservativityStatus)
-> Entity DatabaseSchema.LocIdBase -- The source OMS
-> Entity DatabaseSchema.LocIdBase -- The target OMS
-> Maybe (Entity DatabaseSchema.LocIdBase)
-> Maybe (Entity DatabaseSchema.Language)
mappingToResult (Entity _ mappingValue) mappingLocIdBase (Entity signatureMorphismKey _)
conservativityStatusM locIdBaseSource locIdBaseTarget
freenesParameterOMSLocIdM freenessParameterLanguageM =
let conservativityStatusResult = fmap conservativityStatusToResult conservativityStatusM
freenessParameterLanguageResult = fmap languageToResult freenessParameterLanguageM
{ GraphQLResultMapping.conservativityStatus = conservativityStatusResult
, GraphQLResultMapping.displayName = mappingDisplayName mappingValue
fmap (LocIdReference . locIdBaseLocId . entityVal)
freenesParameterOMSLocIdM
freenessParameterLanguageResult
, GraphQLResultMapping.locId = locIdBaseLocId $ entityVal mappingLocIdBase
, GraphQLResultMapping.name = mappingName mappingValue
, GraphQLResultMapping.origin = show $ mappingOrigin mappingValue
, GraphQLResultMapping.pending = mappingPending mappingValue
IdReference $ fromIntegral $ fromSqlKey signatureMorphismKey
LocIdReference $ locIdBaseLocId $ entityVal locIdBaseSource
LocIdReference $ locIdBaseLocId $ entityVal locIdBaseTarget
show $ DatabaseSchema.mappingType mappingValue
}
nativeDocumentToResult :: Entity DatabaseSchema.Document
-> Entity DatabaseSchema.LocIdBase
nativeDocumentToResult (Entity _ documentValue) (Entity _ locIdBaseValue)
documentLinksSourceResults documentLinksTargetResults omsResult =
{ GraphQLResultNativeDocument.__typename = "NativeDocument"
, GraphQLResultNativeDocument.displayName = documentDisplayName documentValue
, GraphQLResultNativeDocument.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultNativeDocument.name = documentName documentValue
, GraphQLResultNativeDocument.version = documentVersion documentValue
, GraphQLResultNativeDocument.documentLinksSource = documentLinksSourceResults
, GraphQLResultNativeDocument.documentLinksTarget = documentLinksTargetResults
, GraphQLResultNativeDocument.oms = omsResult
}
omsToResult :: Entity DatabaseSchema.OMS
-> Entity DatabaseSchema.LocIdBase
-> Entity DatabaseSchema.ConservativityStatus
-> Maybe (Entity DatabaseSchema.FileRange)
-> Maybe (Entity DatabaseSchema.LocIdBase)
-> Maybe (Entity DatabaseSchema.SignatureMorphism)
-> Entity DatabaseSchema.Language
-> Entity DatabaseSchema.Logic
-> Maybe (Entity DatabaseSchema.LocIdBase)
-> Maybe (Entity DatabaseSchema.SignatureMorphism)
-> Maybe StringReference
omsToResult (Entity _ omsValue) locIdBaseOMS conservativityStatusEntity
fileRangeM freeNormalFormLocIdBaseM freeNormalFormSignatureMorphismM
languageEntity logicEntity
normalFormLocIdBaseM normalFormSignatureMorphismM
consistencyCheckAttemptResults mappingSourceResults mappingTargetResults sentenceResults
serializationResult =
let conservativityStatusResult = conservativityStatusToResult conservativityStatusEntity
fileRangeResult = fmap fileRangeToResult fileRangeM
{ GraphQLResultOMS.conservativityStatus = conservativityStatusResult
, GraphQLResultOMS.consistencyCheckAttempts = consistencyCheckAttemptResults
, GraphQLResultOMS.description = Nothing
, GraphQLResultOMS.displayName = oMSDisplayName omsValue
fmap (LocIdReference . locIdBaseLocId . entityVal) freeNormalFormLocIdBaseM
fmap (IdReference . fromIntegral . fromSqlKey . entityKey)
freeNormalFormSignatureMorphismM
, GraphQLResultOMS.labelHasFree = oMSLabelHasFree omsValue
, GraphQLResultOMS.labelHasHiding = oMSLabelHasHiding omsValue
, GraphQLResultOMS.language = languageToResult languageEntity
, GraphQLResultOMS.locId = locIdBaseLocId $ entityVal locIdBaseOMS
, GraphQLResultOMS.logic = logicToResult logicEntity
, GraphQLResultOMS.mappingsSource = mappingSourceResults
, GraphQLResultOMS.mappingsTarget = mappingTargetResults
, GraphQLResultOMS.name = oMSName omsValue
, GraphQLResultOMS.nameExtension = oMSNameExtension omsValue
, GraphQLResultOMS.nameExtensionIndex = oMSNameExtensionIndex omsValue
, GraphQLResultOMS.nameFileRange = fileRangeResult
fmap (LocIdReference . locIdBaseLocId . entityVal) normalFormLocIdBaseM
fmap (IdReference . fromIntegral . fromSqlKey . entityKey)
normalFormSignatureMorphismM
, GraphQLResultOMS.origin = show $ oMSOrigin omsValue
, GraphQLResultOMS.sentences = sentenceResults
, GraphQLResultOMS.serialization = serializationResult
IdReference $ fromIntegral $ fromSqlKey $ oMSSignatureId omsValue
}
omsToResultSimple :: Entity DatabaseSchema.OMS
-> Entity DatabaseSchema.LocIdBase
omsToResultSimple (Entity _ omsValue) (Entity _ locIdBaseValue) =
{ GraphQLResultOMSSimple.description = Nothing
, GraphQLResultOMSSimple.displayName = oMSDisplayName omsValue
, GraphQLResultOMSSimple.labelHasFree = oMSLabelHasFree omsValue
, GraphQLResultOMSSimple.labelHasHiding = oMSLabelHasHiding omsValue
, GraphQLResultOMSSimple.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultOMSSimple.name = oMSName omsValue
, GraphQLResultOMSSimple.nameExtension = oMSNameExtension omsValue
, GraphQLResultOMSSimple.nameExtensionIndex = oMSNameExtensionIndex omsValue
, GraphQLResultOMSSimple.origin = show $ oMSOrigin omsValue
}
premiseSelectionToResult :: [Entity DatabaseSchema.LocIdBase] -- Of Sentence
premiseSelectionToResult premises =
map (LocIdReference . locIdBaseLocId . entityVal) premises
}
reasonerToResult :: Entity DatabaseSchema.Reasoner
reasonerToResult (Entity _ reasonerValue) =
{ GraphQLResultReasoner.id = reasonerSlug reasonerValue
, GraphQLResultReasoner.displayName = reasonerDisplayName reasonerValue
}
reasonerConfigurationToResult :: Entity DatabaseSchema.ReasonerConfiguration
-> Maybe (Entity DatabaseSchema.Reasoner)
reasonerConfigurationToResult (Entity reasonerConfigurationKey
reasonerConfigurationValue) reasonerM premiseSelectionResults =
fmap reasonerToResult reasonerM
fromIntegral $ fromSqlKey reasonerConfigurationKey
premiseSelectionResults
reasonerConfigurationTimeLimit reasonerConfigurationValue
}
reasonerOutputToResult :: Entity DatabaseSchema.ReasonerOutput
reasonerOutputToResult (Entity _ reasonerOutputValue) =
Text.unpack $ reasonerOutputText reasonerOutputValue
}
reasoningAttemptToResult :: Entity DatabaseSchema.ReasoningAttempt
-> Maybe (Entity DatabaseSchema.ReasonerOutput)
-> Maybe (Entity DatabaseSchema.Reasoner)
reasoningAttemptToResult (Entity _ reasoningAttemptValue) reasonerOutputEntity
reasonerEntityM actionResult reasonerConfigurationResult =
{ GraphQLResultReasoningAttempt.action = actionResult
fmap reasonerOutputToResult reasonerOutputEntity
reasonerConfigurationResult
reasoningAttemptTimeTaken reasoningAttemptValue
fmap reasonerToResult reasonerEntityM
}
serializationToResult :: Entity DatabaseSchema.Serialization
-> Entity DatabaseSchema.Language
serializationToResult (Entity _ serializationValue) languageEntity =
let languageResult = languageToResult languageEntity
{ GraphQLResultSerialization.id = serializationSlug serializationValue
, GraphQLResultSerialization.language = languageResult
, GraphQLResultSerialization.name = serializationName serializationValue
}
signatureToResult :: Entity DatabaseSchema.Signature
-> [Entity DatabaseSchema.LocIdBase] -- Of the OMS with this signature
-> [Entity DatabaseSchema.SignatureMorphism]
-> [Entity DatabaseSchema.SignatureMorphism]
-> [( Entity DatabaseSchema.LocIdBase
, Entity DatabaseSchema.Symbol
, Maybe (Entity DatabaseSchema.FileRange)
)]
signatureToResult (Entity signatureKey _) omsL signatureMorphismsAsSourceL
signatureMorphismsAsTargetL symbolsWithFileRanges =
{ GraphQLResultSignature.id = fromIntegral $ fromSqlKey signatureKey
map (LocIdReference . locIdBaseLocId . entityVal) omsL
map (IdReference . fromIntegral . fromSqlKey . entityKey)
signatureMorphismsAsSourceL
map (IdReference . fromIntegral . fromSqlKey . entityKey)
signatureMorphismsAsTargetL
map symbolToResultUncurried symbolsWithFileRanges
}
signatureMorphismToResult :: Entity DatabaseSchema.SignatureMorphism
-> Entity DatabaseSchema.Signature
-> Entity DatabaseSchema.Signature
signatureMorphismToResult (Entity signatureMorphismKey _) signatureSource
signatureTarget logicMappingResult mappingResults symbolMappingResults =
fromIntegral $ fromSqlKey signatureMorphismKey
, GraphQLResultSignatureMorphism.logicMapping = logicMappingResult
, GraphQLResultSignatureMorphism.mappings = mappingResults
IdReference $ fromIntegral $ fromSqlKey $ entityKey signatureSource
, GraphQLResultSignatureMorphism.symbolMappings = symbolMappingResults
IdReference $ fromIntegral $ fromSqlKey $ entityKey signatureTarget
}
symbolToResult :: Entity DatabaseSchema.LocIdBase
-> Entity DatabaseSchema.Symbol
-> Maybe (Entity DatabaseSchema.FileRange)
symbolToResult (Entity _ locIdBaseValue) (Entity _ symbolValue) fileRangeM =
let fileRangeResult = fmap fileRangeToResult fileRangeM
{ GraphQLResultSymbol.__typename = "Symbol"
, GraphQLResultSymbol.fileRange = fileRangeResult
, GraphQLResultSymbol.fullName = Text.unpack $ symbolFullName symbolValue
, GraphQLResultSymbol.kind = symbolSymbolKind symbolValue
, GraphQLResultSymbol.locId = locIdBaseLocId locIdBaseValue
, GraphQLResultSymbol.name = symbolName symbolValue
}
symbolToResultUncurried :: ( Entity DatabaseSchema.LocIdBase
, Entity DatabaseSchema.Symbol
, Maybe (Entity DatabaseSchema.FileRange)
symbolToResultUncurried = uncurry3 symbolToResult
symbolMappingToResult :: ( Entity DatabaseSchema.LocIdBase
, Entity DatabaseSchema.Symbol
, Maybe (Entity DatabaseSchema.FileRange)
)
-> ( Entity DatabaseSchema.LocIdBase
, Entity DatabaseSchema.Symbol
, Maybe (Entity DatabaseSchema.FileRange)
)
symbolMappingToResult sourceSymbolData targetSymbolData =
symbolToResultUncurried sourceSymbolData
symbolToResultUncurried targetSymbolData
}
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 f (a, b, c) = f a b c