brendanhay / amazonka

A comprehensive Amazon Web Services SDK for Haskell.
https://amazonka.brendanhay.nz
Other
599 stars 227 forks source link

Hook system improvements #995

Open endgame opened 3 months ago

endgame commented 3 months ago

While writing an example that uses hooks, I noticed that they were very hard to use correctly, and reasonable-looking code would silently ignore the request type you think you're hooking into.

We should provide {add,remove}Hook{,_} variants which are specialised to each hook type and are harder to misuse:

  1. addHookFor and addHookFor_ should be moved to the bottom of the file and marked {-# DEPRECATED #-} with a message recommending the hook-specific functions, and promising removal in 2.2. The export list for Amazonka.Env.Hooks should have a -- * section for deprecated functions.
  2. addAWSRequestHook should be renamed to addRequestHookFor, and addAWSRequestHook should remain as a {-# DEPRECATED #-} alias, also scheduled for removal in 2.2.
  3. addAWSRequestHook_ should be deprecated and scheduled for removal in 2.2.
  4. removeHooksFor and removeHooksFor_ should be moved to the bottom of the file and deprecated, much the same as №1.
  5. For each field in the Hooks record (example requestRetry) that has a forall a, we should have:
    • An add-for function for this hook: addRequestRetryHookFor :: forall a b. Hook_ (Request a, Text, Retry.RetryStatus) -> Hook_ (Request b, Text, Retry.RetryStatus) -> Hook_ (Request b, Text, Retry.RetryStatus) = addHookFor_ @(Request a, Text, Retry.RetryStatus)
    • A remove-for function for this hook: removeRequestRetryHookFor :: _ = removeHookFor_
  6. Haddocks for each new function from №5
  7. Export these in a new -- ** Functions for specific hooks first, with an explanatory note:
    -- ** Functions for specific hooks
    -- $functions-specific-hooks (say that the type application for these is the AWS Request type e.g. `@S3.GetObject`.)
    addRequestHookFor,
    removeRequestsHooksFor,
    ...
    -- ** Functions for arbitrary hooks
    -- $functions-arbitrary-hooks
    noHook,
    noHook_,
    addHook,
    addHook_,
    ...
endgame commented 3 months ago

@dalpd as discussed at ZuriHac