packages feed

hydra-build-0.17.3: src/main/haskell/Hydra/Decode/Build/Format.hs

-- Note: this is an automatically generated file. Do not edit.

-- | Term decoders for hydra.build.format

module Hydra.Decode.Build.Format where

import qualified Hydra.Build.Format as Format
import qualified Hydra.Core as Core
import qualified Hydra.Decode.Packaging as Packaging
import qualified Hydra.Errors as Errors
import qualified Hydra.Extract.Core as ExtractCore
import qualified Hydra.Graph as Graph
import qualified Hydra.Lexical as Lexical
import qualified Hydra.Overlay.Haskell.Lib.Eithers as Eithers
import qualified Hydra.Overlay.Haskell.Lib.Maps as Maps
import qualified Hydra.Overlay.Haskell.Lib.Optionals as Optionals
import qualified Hydra.Overlay.Haskell.Lib.Strings as Strings
import qualified Hydra.Rewriting as Rewriting
import qualified Hydra.Util as Util
import Prelude hiding  (Enum, Ordering, decodeFloat, encodeFloat, fail, map, pure, sum)
import qualified Data.Scientific as Sci

-- | Decoder for hydra.build.format.DefinitionNameConventionProfile
definitionNameConventionProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.DefinitionNameConventionProfile
definitionNameConventionProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "severity" severity fieldMap cx) (\field_severity -> Eithers.bind (ExtractCore.requireField "allowUnderscores" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralBoolean v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected boolean literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_allowUnderscores -> Right (Format.DefinitionNameConventionProfile {
          Format.definitionNameConventionProfileSeverity = field_severity,
          Format.definitionNameConventionProfileAllowUnderscores = field_allowUnderscores}))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.DefinitionNameConventionProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.DefinitionValidationProfile
definitionValidationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.DefinitionValidationProfile
definitionValidationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "hasDescription" (ExtractCore.decodeMaybe documentationProfile) fieldMap cx) (\field_hasDescription -> Eithers.bind (ExtractCore.requireField "ordering" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_ordering -> Eithers.bind (ExtractCore.requireField "nameConvention" (ExtractCore.decodeMaybe definitionNameConventionProfile) fieldMap cx) (\field_nameConvention -> Eithers.bind (ExtractCore.requireField "notInModuleName" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_notInModuleName -> Eithers.bind (ExtractCore.requireField "duplicateName" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_duplicateName -> Right (Format.DefinitionValidationProfile {
          Format.definitionValidationProfileHasDescription = field_hasDescription,
          Format.definitionValidationProfileOrdering = field_ordering,
          Format.definitionValidationProfileNameConvention = field_nameConvention,
          Format.definitionValidationProfileNotInModuleName = field_notInModuleName,
          Format.definitionValidationProfileDuplicateName = field_duplicateName})))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.DefinitionValidationProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.DigestEntry
digestEntry :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.DigestEntry
digestEntry cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "kind" digestKind fieldMap cx) (\field_kind -> Eithers.bind (ExtractCore.requireField "hash" sha256Hash fieldMap cx) (\field_hash -> Right (Format.DigestEntry {
          Format.digestEntryKind = field_kind,
          Format.digestEntryHash = field_hash}))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.DigestEntry")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.DigestKind
digestKind :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.DigestKind
digestKind cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermInject v0 ->
        let field = Core.injectionField v0
            fname = Core.fieldName field
            fterm = Core.fieldTerm field
            variantMap =
                    Maps.fromList [
                      (Core.Name "dslSource", (\input -> Eithers.map (\t -> Format.DigestKindDslSource) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "jsonFile", (\input -> Eithers.map (\t -> Format.DigestKindJsonFile) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "targetFile", (\input -> Eithers.map (\t -> Format.DigestKindTargetFile) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "runtimeFile", (\input -> Eithers.map (\t -> Format.DigestKindRuntimeFile) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "other", (\input -> Eithers.map (\t -> Format.DigestKindOther) (ExtractCore.decodeUnit cx input)))]
        in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
          "no such field ",
          (Core.unName fname),
          " in union"]))) (\f -> f fterm))
      _ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.DocumentationProfile
documentationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.DocumentationProfile
documentationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "severity" severity fieldMap cx) (\field_severity -> Eithers.bind (ExtractCore.requireField "exemptDeprecated" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralBoolean v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected boolean literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_exemptDeprecated -> Right (Format.DocumentationProfile {
          Format.documentationProfileSeverity = field_severity,
          Format.documentationProfileExemptDeprecated = field_exemptDeprecated}))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.DocumentationProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.Generation
generation :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.Generation
generation cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "generatorId" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_generatorId -> Eithers.bind (ExtractCore.requireField "mode" generationMode fieldMap cx) (\field_mode -> Eithers.bind (ExtractCore.requireField "host" languageName fieldMap cx) (\field_host -> Eithers.bind (ExtractCore.requireField "hydraVersion" (ExtractCore.decodeMaybe Packaging.version) fieldMap cx) (\field_hydraVersion -> Eithers.bind (ExtractCore.requireField "revision" (ExtractCore.decodeMaybe (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2))) fieldMap cx) (\field_revision -> Eithers.bind (ExtractCore.requireField "timestamp" (ExtractCore.decodeMaybe (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2))) fieldMap cx) (\field_timestamp -> Right (Format.Generation {
          Format.generationGeneratorId = field_generatorId,
          Format.generationMode = field_mode,
          Format.generationHost = field_host,
          Format.generationHydraVersion = field_hydraVersion,
          Format.generationRevision = field_revision,
          Format.generationTimestamp = field_timestamp}))))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.Generation")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.GenerationMode
generationMode :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.GenerationMode
generationMode cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermInject v0 ->
        let field = Core.injectionField v0
            fname = Core.fieldName field
            fterm = Core.fieldTerm field
            variantMap =
                    Maps.fromList [
                      (Core.Name "published", (\input -> Eithers.map (\t -> Format.GenerationModePublished) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "shim", (\input -> Eithers.map (\t -> Format.GenerationModeShim) (ExtractCore.decodeUnit cx input)))]
        in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
          "no such field ",
          (Core.unName fname),
          " in union"]))) (\f -> f fterm))
      _ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.HostOverride
hostOverride :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.HostOverride
hostOverride cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermInject v0 ->
        let field = Core.injectionField v0
            fname = Core.fieldName field
            fterm = Core.fieldTerm field
            variantMap =
                    Maps.fromList [
                      (Core.Name "local", (\input -> Eithers.map (\t -> Format.HostOverrideLocal) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "version", (\input -> Eithers.map (\t -> Format.HostOverrideVersion t) (Packaging.version cx input)))]
        in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
          "no such field ",
          (Core.unName fname),
          " in union"]))) (\f -> f fterm))
      _ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.InputDigest
inputDigest :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.InputDigest
inputDigest cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "digestFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_digestFormatVersion -> Eithers.bind (ExtractCore.requireField "moduleFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_moduleFormatVersion -> Eithers.bind (ExtractCore.requireField "selfHash" (ExtractCore.decodeMaybe sha256Hash) fieldMap cx) (\field_selfHash -> Eithers.bind (ExtractCore.requireField "dependencyHashes" (ExtractCore.decodeMap Packaging.packageName sha256Hash) fieldMap cx) (\field_dependencyHashes -> Eithers.bind (ExtractCore.requireField "moduleHashes" (ExtractCore.decodeMap Packaging.moduleName sha256Hash) fieldMap cx) (\field_moduleHashes -> Right (Format.InputDigest {
          Format.inputDigestDigestFormatVersion = field_digestFormatVersion,
          Format.inputDigestModuleFormatVersion = field_moduleFormatVersion,
          Format.inputDigestSelfHash = field_selfHash,
          Format.inputDigestDependencyHashes = field_dependencyHashes,
          Format.inputDigestModuleHashes = field_moduleHashes})))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.InputDigest")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.LanguageName
languageName :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.LanguageName
languageName cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermWrap v0 -> Eithers.map (\b -> Format.LanguageName b) ((\raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
        Core.TermLiteral v1 -> case v1 of
          Core.LiteralString v2 -> Right v2
          _ -> Left (Errors.DecodingError "expected string literal")
        _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx raw2)) (Core.wrappedTermBody v0))
      _ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.ModuleValidationProfile
moduleValidationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.ModuleValidationProfile
moduleValidationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "definitions" (ExtractCore.decodeMaybe definitionValidationProfile) fieldMap cx) (\field_definitions -> Eithers.bind (ExtractCore.requireField "nameConvention" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_nameConvention -> Eithers.bind (ExtractCore.requireField "conflictingVariantName" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_conflictingVariantName -> Right (Format.ModuleValidationProfile {
          Format.moduleValidationProfileDefinitions = field_definitions,
          Format.moduleValidationProfileNameConvention = field_nameConvention,
          Format.moduleValidationProfileConflictingVariantName = field_conflictingVariantName})))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.ModuleValidationProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.OutputDigest
outputDigest :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.OutputDigest
outputDigest cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "digestFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_digestFormatVersion -> Eithers.bind (ExtractCore.requireField "moduleFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_moduleFormatVersion -> Eithers.bind (ExtractCore.requireField "generator" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_generator -> Eithers.bind (ExtractCore.requireField "generation" generation fieldMap cx) (\field_generation -> Eithers.bind (ExtractCore.requireField "selfHash" (ExtractCore.decodeMaybe sha256Hash) fieldMap cx) (\field_selfHash -> Eithers.bind (ExtractCore.requireField "dependencyHashes" (ExtractCore.decodeMap Packaging.packageName sha256Hash) fieldMap cx) (\field_dependencyHashes -> Eithers.bind (ExtractCore.requireField "inputs" (ExtractCore.decodeMap (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) digestEntry) fieldMap cx) (\field_inputs -> Eithers.bind (ExtractCore.requireField "outputs" (ExtractCore.decodeMap (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) digestEntry) fieldMap cx) (\field_outputs -> Right (Format.OutputDigest {
          Format.outputDigestDigestFormatVersion = field_digestFormatVersion,
          Format.outputDigestModuleFormatVersion = field_moduleFormatVersion,
          Format.outputDigestGenerator = field_generator,
          Format.outputDigestGeneration = field_generation,
          Format.outputDigestSelfHash = field_selfHash,
          Format.outputDigestDependencyHashes = field_dependencyHashes,
          Format.outputDigestInputs = field_inputs,
          Format.outputDigestOutputs = field_outputs}))))))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.OutputDigest")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.PackageDescriptor
packageDescriptor :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.PackageDescriptor
packageDescriptor cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "packageFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_packageFormatVersion -> Eithers.bind (ExtractCore.requireField "name" Packaging.packageName fieldMap cx) (\field_name -> Eithers.bind (ExtractCore.requireField "description" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_description -> Eithers.bind (ExtractCore.requireField "sourceLanguage" languageName fieldMap cx) (\field_sourceLanguage -> Eithers.bind (ExtractCore.requireField "targetLanguages" (ExtractCore.decodeMaybe (ExtractCore.decodeList languageName)) fieldMap cx) (\field_targetLanguages -> Eithers.bind (ExtractCore.requireField "dependencies" (ExtractCore.decodeList Packaging.packageName) fieldMap cx) (\field_dependencies -> Eithers.bind (ExtractCore.requireField "validation" (ExtractCore.decodeMaybe packageValidationConfiguration) fieldMap cx) (\field_validation -> Right (Format.PackageDescriptor {
          Format.packageDescriptorPackageFormatVersion = field_packageFormatVersion,
          Format.packageDescriptorName = field_name,
          Format.packageDescriptorDescription = field_description,
          Format.packageDescriptorSourceLanguage = field_sourceLanguage,
          Format.packageDescriptorTargetLanguages = field_targetLanguages,
          Format.packageDescriptorDependencies = field_dependencies,
          Format.packageDescriptorValidation = field_validation})))))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.PackageDescriptor")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.PackageManifest
packageManifest :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.PackageManifest
packageManifest cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "manifestFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_manifestFormatVersion -> Eithers.bind (ExtractCore.requireField "moduleFormatVersion" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralInteger v2 -> case v2 of
              Core.IntegerValueInt32 v3 -> Right v3
              _ -> Left (Errors.DecodingError "expected int32 value")
            _ -> Left (Errors.DecodingError "expected int32 literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_moduleFormatVersion -> Eithers.bind (ExtractCore.requireField "package" Packaging.packageName fieldMap cx) (\field_package -> Eithers.bind (ExtractCore.requireField "mainModules" (ExtractCore.decodeList Packaging.moduleName) fieldMap cx) (\field_mainModules -> Eithers.bind (ExtractCore.requireField "testModules" (ExtractCore.decodeList Packaging.moduleName) fieldMap cx) (\field_testModules -> Eithers.bind (ExtractCore.requireField "mainDslModules" (ExtractCore.decodeList Packaging.moduleName) fieldMap cx) (\field_mainDslModules -> Eithers.bind (ExtractCore.requireField "mainEncodingModules" (ExtractCore.decodeList Packaging.moduleName) fieldMap cx) (\field_mainEncodingModules -> Right (Format.PackageManifest {
          Format.packageManifestManifestFormatVersion = field_manifestFormatVersion,
          Format.packageManifestModuleFormatVersion = field_moduleFormatVersion,
          Format.packageManifestPackage = field_package,
          Format.packageManifestMainModules = field_mainModules,
          Format.packageManifestTestModules = field_testModules,
          Format.packageManifestMainDslModules = field_mainDslModules,
          Format.packageManifestMainEncodingModules = field_mainEncodingModules})))))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.PackageManifest")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.PackageValidationConfiguration
packageValidationConfiguration :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.PackageValidationConfiguration
packageValidationConfiguration cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "package" (ExtractCore.decodeMaybe packageValidationProfile) fieldMap cx) (\field_package -> Eithers.bind (ExtractCore.requireField "module" (ExtractCore.decodeMaybe moduleValidationProfile) fieldMap cx) (\field_module -> Eithers.bind (ExtractCore.requireField "type" (ExtractCore.decodeMaybe typeValidationProfile) fieldMap cx) (\field_type -> Eithers.bind (ExtractCore.requireField "term" (ExtractCore.decodeMaybe termValidationProfile) fieldMap cx) (\field_term -> Right (Format.PackageValidationConfiguration {
          Format.packageValidationConfigurationPackage = field_package,
          Format.packageValidationConfigurationModule = field_module,
          Format.packageValidationConfigurationType = field_type,
          Format.packageValidationConfigurationTerm = field_term}))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.PackageValidationConfiguration")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.PackageValidationProfile
packageValidationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.PackageValidationProfile
packageValidationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "conflictingModuleName" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_conflictingModuleName -> Eithers.bind (ExtractCore.requireField "duplicateModuleName" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_duplicateModuleName -> Eithers.bind (ExtractCore.requireField "nameConvention" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_nameConvention -> Right (Format.PackageValidationProfile {
          Format.packageValidationProfileConflictingModuleName = field_conflictingModuleName,
          Format.packageValidationProfileDuplicateModuleName = field_duplicateModuleName,
          Format.packageValidationProfileNameConvention = field_nameConvention})))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.PackageValidationProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.RepositoryDescriptor
repositoryDescriptor :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.RepositoryDescriptor
repositoryDescriptor cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "currentVersion" Packaging.version fieldMap cx) (\field_currentVersion -> Eithers.bind (ExtractCore.requireField "hostVersion" Packaging.version fieldMap cx) (\field_hostVersion -> Eithers.bind (ExtractCore.requireField "hostOverrides" (ExtractCore.decodeMap languageName hostOverride) fieldMap cx) (\field_hostOverrides -> Eithers.bind (ExtractCore.requireField "group" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_group -> Eithers.bind (ExtractCore.requireField "author" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_author -> Eithers.bind (ExtractCore.requireField "url" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_url -> Eithers.bind (ExtractCore.requireField "license" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
          Core.TermLiteral v1 -> case v1 of
            Core.LiteralString v2 -> Right v2
            _ -> Left (Errors.DecodingError "expected string literal")
          _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_license -> Eithers.bind (ExtractCore.requireField "packages" (ExtractCore.decodeList Packaging.packageName) fieldMap cx) (\field_packages -> Right (Format.RepositoryDescriptor {
          Format.repositoryDescriptorCurrentVersion = field_currentVersion,
          Format.repositoryDescriptorHostVersion = field_hostVersion,
          Format.repositoryDescriptorHostOverrides = field_hostOverrides,
          Format.repositoryDescriptorGroup = field_group,
          Format.repositoryDescriptorAuthor = field_author,
          Format.repositoryDescriptorUrl = field_url,
          Format.repositoryDescriptorLicense = field_license,
          Format.repositoryDescriptorPackages = field_packages}))))))))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.RepositoryDescriptor")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.Severity
severity :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.Severity
severity cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermInject v0 ->
        let field = Core.injectionField v0
            fname = Core.fieldName field
            fterm = Core.fieldTerm field
            variantMap =
                    Maps.fromList [
                      (Core.Name "error", (\input -> Eithers.map (\t -> Format.SeverityError) (ExtractCore.decodeUnit cx input))),
                      (Core.Name "warning", (\input -> Eithers.map (\t -> Format.SeverityWarning) (ExtractCore.decodeUnit cx input)))]
        in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.concat [
          "no such field ",
          (Core.unName fname),
          " in union"]))) (\f -> f fterm))
      _ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.Sha256Hash
sha256Hash :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.Sha256Hash
sha256Hash cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermWrap v0 -> Eithers.map (\b -> Format.Sha256Hash b) ((\raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
        Core.TermLiteral v1 -> case v1 of
          Core.LiteralString v2 -> Right v2
          _ -> Left (Errors.DecodingError "expected string literal")
        _ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx raw2)) (Core.wrappedTermBody v0))
      _ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.TermValidationProfile
termValidationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.TermValidationProfile
termValidationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "duplicateBinding" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_duplicateBinding -> Eithers.bind (ExtractCore.requireField "emptyTermAnnotation" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_emptyTermAnnotation -> Eithers.bind (ExtractCore.requireField "undefinedVariable" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_undefinedVariable -> Right (Format.TermValidationProfile {
          Format.termValidationProfileDuplicateBinding = field_duplicateBinding,
          Format.termValidationProfileEmptyTermAnnotation = field_emptyTermAnnotation,
          Format.termValidationProfileUndefinedVariable = field_undefinedVariable})))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.TermValidationProfile")) (ExtractCore.stripWithDecodingError cx raw)

-- | Decoder for hydra.build.format.TypeValidationProfile
typeValidationProfile :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Format.TypeValidationProfile
typeValidationProfile cx raw =
    Eithers.either (\err -> Left err) (\stripped -> case stripped of
      Core.TermRecord v0 ->
        let fieldMap = ExtractCore.toFieldMap v0
        in (Eithers.bind (ExtractCore.requireField "emptyAnnotation" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_emptyAnnotation -> Eithers.bind (ExtractCore.requireField "duplicateField" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_duplicateField -> Eithers.bind (ExtractCore.requireField "singleVariantUnion" (ExtractCore.decodeMaybe severity) fieldMap cx) (\field_singleVariantUnion -> Right (Format.TypeValidationProfile {
          Format.typeValidationProfileEmptyAnnotation = field_emptyAnnotation,
          Format.typeValidationProfileDuplicateField = field_duplicateField,
          Format.typeValidationProfileSingleVariantUnion = field_singleVariantUnion})))))
      _ -> Left (Errors.DecodingError "expected a record of type hydra.build.format.TypeValidationProfile")) (ExtractCore.stripWithDecodingError cx raw)