Skip to content

Commit

Permalink
Merge pull request #996 from mankyKitty/sc/change-lens-dep-to-microlens
Browse files Browse the repository at this point in the history
Remove chonky Lens and replace with microlens for smaller footprint.
  • Loading branch information
endgame authored Dec 27, 2024
2 parents 30b200d + 567292c commit fbc91ee
Show file tree
Hide file tree
Showing 202 changed files with 1,366 additions and 1,311 deletions.
16 changes: 16 additions & 0 deletions .ormolu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Amazonka.Prelude exports Control.Applicative
module Amazonka.Prelude exports Control.Monad
module Amazonka.Prelude exports Data.Function
module Amazonka.Prelude exports Data.Functor
module Amazonka.Prelude exports Data.List.NonEmpty
module Amazonka.Prelude exports Lens.Micro
module Amazonka.Prelude exports Lens.Micro.Pro
module Amazonka.Prelude exports Prelude
module Gen.Prelude exports Control.Applicative
module Gen.Prelude exports Control.Comonad
module Gen.Prelude exports Control.Comonad.Cofree
module Gen.Prelude exports Control.Monad
module Gen.Prelude exports Data.Functor
module Gen.Prelude exports Data.Function
module Gen.Prelude exports Prelude
module Gen.Prelude exports System.FilePath
2 changes: 1 addition & 1 deletion configs/services/s3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"libraryName": "amazonka-s3",
"extraDependencies": ["text", "lens"],
"extraDependencies": ["text"],
"operationPlugins": {
"DeleteObjects": ["Request.contentMD5Header", "Request.s3vhost"],
"GetBucketLocation": [],
Expand Down
41 changes: 19 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
{
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

flake-utils = {
url = "github:numtide/flake-utils";
};
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";

pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};

botocore = {
Expand Down Expand Up @@ -103,10 +97,22 @@
ghc92.developPackage {
root = ./gen;
overrides = _hsFinal: hsPrev: with pkgs.haskell.lib; {
ede = dontCheck (dontHaddock hsPrev.ede);
data-fix = doJailbreak hsPrev.data-fix;
ede = dontCheck (hsPrev.callHackageDirect
{
pkg = "ede";
ver = "0.3.4.0";
sha256 = "sha256-bEYTVnVj/TigHgGiiMP/Yz3YE1gg2QYPCPrx6RrpSOo=";
}
{ });
hashable = hsPrev.callHackage "hashable" "1.3.5.0" { };
pandoc = dontHaddock hsPrev.pandoc;
semialign = doJailbreak hsPrev.semialign;
string-qq = dontCheck hsPrev.string-qq;
text-short = doJailbreak hsPrev.text-short;
these = doJailbreak hsPrev.these;
unordered-containers =
hsPrev.callHackage "unordered-containers" "0.2.19.1" { };
};
};

Expand Down
16 changes: 9 additions & 7 deletions lib/amazonka-core/amazonka-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ common base
-fwarn-unused-packages

default-extensions:
NoImplicitPrelude
ConstraintKinds
DataKinds
DefaultSignatures
Expand All @@ -50,6 +49,7 @@ common base
GeneralizedNewtypeDeriving
LambdaCase
NamedFieldPuns
NoImplicitPrelude
OverloadedStrings
PackageImports
PatternSynonyms
Expand Down Expand Up @@ -102,21 +102,23 @@ library
Amazonka.Waiter

build-depends:
, aeson ^>=1.5.0.0 || >=2.0 && <2.2 || ^>=2.2
, aeson ^>=1.5.0.0 || ^>=2.0 || ^>=2.1 || ^>=2.2
, attoparsec >=0.11.3
, bytestring >=0.10.8
, case-insensitive >=1.2
, conduit >=1.3
, conduit-extra >=1.3
, containers >=0.5 && <0.7
, crypton >=0.32 && <0.35 || ^>=1.0.0
, containers >=0.5 && <0.7
, crypton >=0.32 && <0.35 || ^>=1.0.0
, deepseq >=1.4
, hashable >=1.2
, http-client >=0.5 && <0.8
, http-conduit >=2.3 && <3
, http-client >=0.5 && <0.8
, http-conduit >=2.3 && <3
, http-types >=0.12
, lens >=4.14
, memory >=0.6
, microlens ^>=0.4.13.1
, microlens-contra ^>=0.1.0.3
, microlens-pro ^>=0.2.0
, regex-posix >=0.96
, resourcet >=1.1
, scientific >=0.3
Expand Down
89 changes: 57 additions & 32 deletions lib/amazonka-core/src/Amazonka/Core/Lens/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,29 @@
--
-- Re-export a number of lens types and combinators for use in service
-- bindings.
module Amazonka.Core.Lens.Internal (module Export) where

import Control.Exception.Lens as Export
( catching,
catching_,
exception,
throwingM,
trying,
_IOException,
module Amazonka.Core.Lens.Internal
( concatOf,
folding,
to,
module Export,
)
import Control.Lens as Export
( AReview,
Choice,
Fold,
Getter,
where

import Lens.Micro as Export
( ASetter,
ASetter',
Getting,
IndexedTraversal',
Iso',
Lens,
Lens',
Optic',
Prism',
Setter',
Traversal',
allOf,
anyOf,
coerced,
concatOf,
SimpleFold,
SimpleGetter,
filtered,
folding,
has,
iso,
lens,
mapping,
non,
prism,
sets,
to,
toListOf,
traversed,
un,
view,
(#),
(%~),
(.~),
(<&>),
Expand All @@ -63,3 +44,47 @@ import Control.Lens as Export
_Just,
_last,
)
import qualified Lens.Micro as Lens
import Lens.Micro.Contra as Export
( Fold,
Getter,
fromSimpleFold,
fromSimpleGetter,
)
import Lens.Micro.Extras as Export
( view,
)
import Lens.Micro.Internal as Export
( foldMapOf,
(#.),
)
import Lens.Micro.Pro as Export
( AReview,
Iso',
LensLike',
Prism',
Traversal',
coerced,
iso,
mapping,
preview,
prism,
prism',
review,
(#),
)
import Prelude (Foldable, ($))

-- | 'concatOf' is 'view', with a type signature to make it obvious
-- that it concatenates all focused lists.
concatOf :: Getting [r] s [r] -> s -> [r]
concatOf = view
{-# INLINE concatOf #-}

folding :: (Foldable f) => (s -> f a) -> Fold s a
folding f = fromSimpleFold $ Lens.folding f
{-# INLINE folding #-}

to :: (s -> a) -> Getter s a
to f = fromSimpleGetter $ Lens.to f
{-# INLINE to #-}
22 changes: 10 additions & 12 deletions lib/amazonka-core/src/Amazonka/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- Portability : non-portable (GHC extensions)
module Amazonka.Error where

import Amazonka.Core.Lens.Internal (Choice, Fold, Optic', filtered)
import Amazonka.Core.Lens.Internal (Fold, LensLike', filtered)
import Amazonka.Data
import Amazonka.Prelude
import Amazonka.Types
Expand Down Expand Up @@ -40,7 +40,7 @@ import Network.HTTP.Types.Status (Status (..))
-- >>> :t trying _NoSuchBucketPolicy
-- MonadCatch m => m a -> m (Either ServiceError a)
_MatchServiceError ::
AsError a =>
(AsError a) =>
Service ->
ErrorCode ->
Fold a ServiceError
Expand All @@ -49,7 +49,7 @@ _MatchServiceError s c = _ServiceError . hasService s . hasCode c
statusSuccess :: Status -> Bool
statusSuccess (statusCode -> n) = n >= 200 && n < 300 || n == 304

_HttpStatus :: AsError a => Traversal' a Status
_HttpStatus :: (AsError a) => Traversal' a Status
_HttpStatus = _Error . f
where
f g = \case
Expand All @@ -67,21 +67,21 @@ _HttpStatus = _Error . f
(\x -> ServiceError (e {status = x})) <$> g status

hasService ::
(Applicative f, Choice p) =>
(Applicative f) =>
Service ->
Optic' p f ServiceError ServiceError
LensLike' f ServiceError ServiceError
hasService Service {abbrev} = filtered ((abbrev ==) . ServiceError.abbrev)

hasStatus ::
(Applicative f, Choice p) =>
(Applicative f) =>
Int ->
Optic' p f ServiceError ServiceError
LensLike' f ServiceError ServiceError
hasStatus n = filtered ((n ==) . fromEnum . ServiceError.status)

hasCode ::
(Applicative f, Choice p) =>
(Applicative f) =>
ErrorCode ->
Optic' p f ServiceError ServiceError
LensLike' f ServiceError ServiceError
hasCode c = filtered ((c ==) . ServiceError.code)

serviceError ::
Expand Down Expand Up @@ -134,9 +134,7 @@ parseJSONError a s h bs =
msg c o =
if c == Just "RequestEntityTooLarge"
then pure (Just "Request body must be less than 1 MB")
else
Just <$> o .: "message"
<|> o .:? "Message"
else Just <$> o .: "message" <|> o .:? "Message"

parseXMLError ::
Abbrev ->
Expand Down
Loading

0 comments on commit fbc91ee

Please sign in to comment.