Select Git revision
LintConfig.hs 6.29 KiB
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Module that deals with handling config options
module LintConfig (LintConfig(..), LintConfig', ConfigKind (..), patchConfig,stuffConfig,feedConfig) where
import Universum
import Data.Aeson (FromJSON (parseJSON), Options (..),
defaultOptions, eitherDecode)
import Data.Aeson.Types (genericParseJSON)
import qualified Data.ByteString.Char8 as C8
import qualified Data.ByteString.Lazy as LB
import qualified Data.Map.Strict as M
import GHC.Generics (Generic (Rep, from, to), K1 (..),
M1 (..), (:*:) (..))
import Types (Level)
import Uris (SchemaSet,
Substitution (DomainSubstitution))
import WithCli.Pure (Argument (argumentType, parseArgument))
data ConfigKind = Complete | Basic | Skeleton | Patch
-- | a field that must be given in configs for both server & standalone linter
type family ConfigField (f::ConfigKind) a where
ConfigField Patch a = Maybe a
ConfigField _ a = a
-- | a field that must be given for the standalone linter, but not the server
-- (usually because the server will infer them from its own config)
type family StandaloneField (f :: ConfigKind) a where
StandaloneField Complete a = a
StandaloneField Skeleton a = a
StandaloneField _ a = Maybe a
-- | a field specific to a single world / assembly
type family WorldField (f :: ConfigKind) a where
WorldField Complete a = a
WorldField _ a = Maybe a
data LintConfig (f :: ConfigKind) = LintConfig
{ configScriptInject :: ConfigField f (Maybe Text)
-- ^ Link to Script that should be injected
, configAssemblyTag :: WorldField f Text
-- ^ Assembly name (used for jitsiRoomAdminTag)
, configAssemblies :: StandaloneField f [Text]
-- ^ list of all assembly slugs (used to lint e.g. world:// links)
, configEventSlug :: StandaloneField f Text
-- ^ slug of this event (used e.g. to resolve world:// links)
, configMaxLintLevel :: ConfigField f Level
-- ^ Maximum warn level allowed before the lint fails
, configDontCopyAssets :: ConfigField f Bool
-- ^ Don't copy map assets (mostly useful for development)
, configAllowScripts :: ConfigField f Bool
-- ^ Allow defining custom scripts in maps
, configUriSchemas :: ConfigField f SchemaSet
} deriving (Generic)