Skip to content

Commit

Permalink
fix(deps): Drop explicit dependency on vector (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmillwood committed Feb 1, 2024
1 parent d0e44b3 commit 3bb826d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 0 additions & 2 deletions launchdarkly-server-sdk.cabal
Expand Up @@ -124,7 +124,6 @@ library
, time >=1.9.3 && <1.13
, unordered-containers >=0.2.10.0 && <0.3
, uuid >=1.3.13 && <1.4
, vector >=0.12.1.2 && <0.13
, yaml >=0.11.5.0 && <0.12
default-language: Haskell2010

Expand Down Expand Up @@ -235,6 +234,5 @@ test-suite haskell-server-sdk-test
, time >=1.9.3 && <1.13
, unordered-containers >=0.2.10.0 && <0.3
, uuid >=1.3.13 && <1.4
, vector >=0.12.1.2 && <0.13
, yaml >=0.11.5.0 && <0.12
default-language: Haskell2010
1 change: 0 additions & 1 deletion package.yaml
Expand Up @@ -49,7 +49,6 @@ dependencies:
- time >=1.9.3 && <1.13
- unordered-containers >=0.2.10.0 && <0.3
- uuid >=1.3.13 && <1.4
- vector >=0.12.1.2 && <0.13
- yaml >=0.11.5.0 && <0.12

default-extensions:
Expand Down
6 changes: 3 additions & 3 deletions src/LaunchDarkly/Server/Context/Internal.hs
Expand Up @@ -45,7 +45,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text, intercalate, replace, unpack)
import qualified Data.Vector as V
import qualified GHC.Exts as Exts (fromList)
import GHC.Generics (Generic)
import LaunchDarkly.AesonCompat (KeyMap, deleteKey, emptyObject, foldrWithKey, fromList, insertKey, keyMapUnion, lookupKey, mapValues, objectKeys, singleton, toList)
import LaunchDarkly.Server.Config (Config)
Expand Down Expand Up @@ -339,7 +339,7 @@ getMapOfRequiredProperties includeKind SingleContext {key, kind, anonymous, priv
( "_meta"
, case privateAttributes of
Nothing -> Null
Just attrs -> toJSON $ singleton "privateAttributes" (Array $ V.fromList $ map toJSON $ S.elems attrs)
Just attrs -> toJSON $ singleton "privateAttributes" (Array $ Exts.fromList $ map toJSON $ S.elems attrs)
)
]

Expand Down Expand Up @@ -413,7 +413,7 @@ redactContext config (Single context) =
redactSingleContext :: Bool -> SingleContext -> Set Reference -> Value
redactSingleContext includeKind context privateAttributes =
let State {context = redactedContext, redacted} = foldr applyRedaction State {context = fromList $ getMapOfRedactableProperties context, redacted = []} privateAttributes
redactedValues = Array $ V.fromList $ map String redacted
redactedValues = Array $ Exts.fromList $ map String redacted
required = fromList $ getMapOfRequiredProperties includeKind context
in case redacted of
[] -> Object $ keyMapUnion redactedContext required
Expand Down
3 changes: 1 addition & 2 deletions src/LaunchDarkly/Server/Evaluate.hs
Expand Up @@ -22,7 +22,6 @@ import Data.Scientific (Scientific, floatingOrInteger)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Vector as V
import Data.Word (Word8)
import GHC.Natural (Natural)

Expand Down Expand Up @@ -334,7 +333,7 @@ clauseMatchesContextNoSegments clause context
Nothing -> Right False
Just ctx -> case getValueForReference (getField @"attribute" clause) ctx of
Null -> Right False
Array a -> Right $ maybeNegate clause $ V.any (matchAnyClauseValue clause) a
Array a -> Right $ maybeNegate clause $ any (matchAnyClauseValue clause) a
x -> Right $ maybeNegate clause $ matchAnyClauseValue clause x

clauseMatchesContext :: (Monad m, LaunchDarklyStoreRead store m) => store -> Clause -> Context -> HS.HashSet Text -> m (Either Text Bool)
Expand Down
22 changes: 11 additions & 11 deletions test/Spec/Context.hs
Expand Up @@ -8,8 +8,8 @@ import Data.Function ((&))
import Data.Maybe (fromJust)
import qualified Data.Set as S
import Data.Text (Text)
import qualified Data.Vector as V
import LaunchDarkly.AesonCompat (fromList, lookupKey)
import GHC.Exts (fromList)
import LaunchDarkly.AesonCompat (lookupKey)
import LaunchDarkly.Server.Config (configSetAllAttributesPrivate, makeConfig)
import LaunchDarkly.Server.Context
import LaunchDarkly.Server.Context.Internal (redactContext)
Expand Down Expand Up @@ -112,7 +112,7 @@ singleContextSupportsValueRetrieval =
makeContext "user-key" "user"
& withName "Example"
& withAnonymous False
& withAttribute "groups" (Array $ V.fromList ["beta_testers"])
& withAttribute "groups" (Array $ fromList ["beta_testers"])
& withAttribute "address" address
& withAttribute "preferences" preferences
& withAttribute "complex/and-weird~attribute" "nailed it"
Expand All @@ -133,7 +133,7 @@ singleContextSupportsValueRetrieval =
assertEqual "" (Bool False) $ getValueForReference (R.makeReference "anonymous") user
assertEqual "" "Chicago" $ getValueForReference (R.makeReference "/address/city") user
assertEqual "" "baseball" $ getValueForReference (R.makeReference "/preferences/favorites/sport") user
assertEqual "" (Array $ V.fromList ["beta_testers"]) $ getValueForReference (R.makeReference "/groups") user
assertEqual "" (Array $ fromList ["beta_testers"]) $ getValueForReference (R.makeReference "/groups") user
assertEqual "" Null $ getValueForReference (R.makeReference "/groups/0") user
assertEqual "" "nailed it" $ getValueForReference (R.makeReference "/complex~1and-weird~0attribute") user
)
Expand Down Expand Up @@ -176,7 +176,7 @@ cannotUseWithAttributeToSetRestrictedAttributes =
setAndVerifyAttribute "anonymous" (Bool False) (Bool False) user
setAndVerifyAttribute "anonymous" "false" (Bool True) user
setAndVerifyAttribute "_meta" "anything" Null user
setAndVerifyAttribute "privateAttributeNames" (Array $ V.fromList ["name"]) Null user
setAndVerifyAttribute "privateAttributeNames" (Array $ fromList ["name"]) Null user

setAndVerifyAttribute "kind" "org" "multi" multi
setAndVerifyAttribute "key" "new-key" Null multi
Expand All @@ -185,7 +185,7 @@ cannotUseWithAttributeToSetRestrictedAttributes =
setAndVerifyAttribute "anonymous" (Bool False) Null multi
setAndVerifyAttribute "anonymous" "false" Null multi
setAndVerifyAttribute "_meta" "anything" Null multi
setAndVerifyAttribute "privateAttributeNames" (Array $ V.fromList ["name"]) Null multi
setAndVerifyAttribute "privateAttributeNames" (Array $ fromList ["name"]) Null multi

setAndVerifyAttribute "kind" "org" Null invalid
setAndVerifyAttribute "key" "new-key" Null invalid
Expand All @@ -194,7 +194,7 @@ cannotUseWithAttributeToSetRestrictedAttributes =
setAndVerifyAttribute "anonymous" (Bool False) Null invalid
setAndVerifyAttribute "anonymous" "false" Null invalid
setAndVerifyAttribute "_meta" "anything" Null invalid
setAndVerifyAttribute "privateAttributeNames" (Array $ V.fromList ["name"]) Null invalid
setAndVerifyAttribute "privateAttributeNames" (Array $ fromList ["name"]) Null invalid
)

canParseFromLegacyUserFormat :: Test
Expand Down Expand Up @@ -263,7 +263,7 @@ canRedactAttributesCorrectly = TestCase $ do
config = makeConfig "sdk-key"

address = Object $ fromList [("city", "Chicago"), ("state", "IL")]
hobbies = (Array $ V.fromList ["coding", "reading"])
hobbies = (Array $ fromList ["coding", "reading"])

context =
makeContext "user-key" "user"
Expand All @@ -278,7 +278,7 @@ canRedactAttributesCorrectly = TestCase $ do
decodedAsValue = fromJust $ decode jsonByteString :: Value
decodedIntoMap = case decodedAsValue of (Object o) -> o; _ -> error "expected object"
meta = case lookupKey "_meta" decodedIntoMap of (Just (Object o)) -> o; _ -> error "expected object"
expectedRedacted = Array $ V.fromList ["/address/city", "name"]
expectedRedacted = Array $ fromList ["/address/city", "name"]
expectedAddress = Object $ fromList [("state", "IL")]

canRedactAllAttributesCorrectly :: Test
Expand All @@ -301,13 +301,13 @@ canRedactAllAttributesCorrectly = TestCase $ do
& withAttribute "firstName" "Sandy"
& withAttribute "lastName" "Beaches"
& withAttribute "address" address
& withAttribute "hobbies" (Array $ V.fromList ["coding", "reading"])
& withAttribute "hobbies" (Array $ fromList ["coding", "reading"])

jsonByteString = encode $ redactContext config context
decodedAsValue = fromJust $ decode jsonByteString :: Value
decodedIntoMap = case decodedAsValue of (Object o) -> o; _ -> error "expected object"
meta = case lookupKey "_meta" decodedIntoMap of (Just (Object o)) -> o; _ -> error "expected object"
expectedRedacted = Array $ V.fromList ["address", "firstName", "hobbies", "lastName", "name"]
expectedRedacted = Array $ fromList ["address", "firstName", "hobbies", "lastName", "name"]
expectedAddress = Object $ fromList [("state", "IL")]

allTests :: Test
Expand Down

0 comments on commit 3bb826d

Please sign in to comment.