Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify API and use "state" to improve type-safety #27

Merged
merged 6 commits into from
Nov 2, 2023
Merged

Commits on Nov 2, 2023

  1. chore: doc typo

    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    0927aab View commit details
    Browse the repository at this point in the history
  2. feat!: introduce State to make Tx more type-safe

    `Tx` now implements `FromRequestParts<State>`, meaning the `Router` must
    be provided an instance of `State` in order for it to compile.
    
    `State` can be constructed with `Layer::new`, which now returns a tuple
    of `Layer` and `State`. The idea behind constructing both in the same
    function is to make it harder to forget to add the `Layer`, however
    `Layer::new` is perhaps not the best place for it long-term.
    
    Ultimately this has the desired effect of making `Tx` more type-safe -
    applications that attempt to use `Tx` without providing `State` won't
    compile, and the API for obtaining `State` makes it harder to forget to
    add the `Layer`.
    
    BREAKING CHANGE: `Layer::new` now returns a `(Layer, State)` tuple. This
    can be consumed easily by destructuring assignment. `Tx` now requires
    `State` to be provided on `Router`s in order for the `Router` to be
    usable.
    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    c9eccaf View commit details
    Browse the repository at this point in the history
  3. feat: introduce Tx::setup, Tx::config, and Config APIs

    This will centralise the configuration API and reduce the number of
    types that need to interacted with directly (i.e. `use`d) down to just
    `Tx`.
    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    32a0a0f View commit details
    Browse the repository at this point in the history
  4. refactor!: remove Layer::new and Layer::new_with_error

    This leaves `Tx::{setup,config}` as the only entrypoints to the API.
    
    Error handling documentation was also rewritten.
    
    BREAKING CHANGE: `Layer::{new,new_with_error}` have been removed. Use
    `Tx::{setup,config}` instead.
    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    e8f694e View commit details
    Browse the repository at this point in the history
  5. refactor!: rationalise generic error type bounds

    Required bounds are now present on more `impl` blocks to provide better
    diagnostics if error types are missing required traits.
    
    The `Layer` error type is now only required to implement
    `From<sqlx::Error>` (technically `sqlx::Error` is required to implement
    `Into<LayerError>` since this is more flexible).
    
    BREAKING CHANGE: The tighter bounds on `impl` blocks shouldn't break
    already working code, however the change to the `Layer` error type
    bounds will break error overrides that implement
    `From<axum_sqlx_tx::Error>` - this must be changed to
    `From<sqlx::Error>`.
    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    e2701a7 View commit details
    Browse the repository at this point in the history
  6. chore: doc fix

    connec committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    e896b5a View commit details
    Browse the repository at this point in the history