diff --git a/CHANGELOG.md b/CHANGELOG.md index 602df2011..6c6f98474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file. ### Changed +- `workspaceName` is typed as `IndexName`, which respect ElasticSearch constraints + ### Removed ### Fixed diff --git a/src/Monocle/Config.hs b/src/Monocle/Config.hs index dcc93cbf9..b9354ed59 100644 --- a/src/Monocle/Config.hs +++ b/src/Monocle/Config.hs @@ -90,7 +90,7 @@ import Data.ByteString qualified as BS import Data.Char (isLetter, isLowerCase) import Data.Either.Validation (Validation (Failure, Success)) import Data.Map qualified as Map -import Data.Text qualified as T (all, dropWhileEnd, isPrefixOf, null, replace, toUpper, uncons, unpack) +import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Text.Lazy qualified as TL import Dhall qualified @@ -480,6 +480,24 @@ getIdentByAliasFromIdents alias idents' = case find isMatched idents' of isMatched :: Ident -> Bool isMatched Ident {..} = alias `elem` aliases +-- | Create an IndexName with checked constraints +-- +-- >>> mkIndexName "" +-- Left "Is empty" +-- >>> mkIndexName $ T.replicate 256 "x" +-- Left "Is longer than 255 bytes" +-- >>> mkIndexName "azerTY" +-- Left "Contains uppercase letter(s)" +-- >>> mkIndexName "hello#world" +-- Left "Includes [\\/*?\"<>| ,#:]" +-- >>> mkIndexName "-test" +-- Left "Starts with [-_+.]" +-- >>> mkIndexName "." +-- Left "Is (.|..)" +-- >>> mkIndexName ".." +-- Left "Is (.|..)" +-- >>> mkIndexName "hello-world_42" +-- Right (IndexName "hello-world_42") mkIndexName :: Text -> Either Text IndexName mkIndexName name = do let check explanation p = if p then Right () else Left explanation diff --git a/src/Monocle/Effects.hs b/src/Monocle/Effects.hs index a047378c4..7253b2452 100644 --- a/src/Monocle/Effects.hs +++ b/src/Monocle/Effects.hs @@ -70,7 +70,7 @@ import Effectful.Dispatch.Static.Primitive qualified as EffStatic import Monocle.Effects.Compat () import GHC.IO.Handle (hClose) -import Monocle.Config (ConfigStatus) +import Monocle.Config (ConfigStatus, IndexName, mkIndexName) import System.Directory import System.Posix.Temp (mkstemp) import Test.Tasty @@ -99,7 +99,6 @@ import Effectful.Reader.Static qualified as E import Effectful.Retry as Retry import Monocle.Client (MonocleClient) import Monocle.Client.Api (crawlerAddDoc, crawlerCommit, crawlerCommitInfo) -import Monocle.Config (IndexName, mkIndexName) import Monocle.Protob.Crawler qualified as CrawlerPB