Hammer: an elixir rate-limiter with pluggable backends Elixir for the Little Things

alembic 3.4.0

https://hex.pm/packages/alembic/3.4.0

Changelog

Enhancements

  • Alembic.Document.from_ecto_changeset/2 converts the errors in ecto_changeset to Alembic.Error.t in a single Alembic.Document.t. Bypasses a bug in JaSerializer where it assumes all fields that don’t end in _id are attribute names, which leads to association names (as opposed to their foreign key) being put under /data/attributes. Alembic.Document.from_ecto_changeset reflects on the Ecto.Changeset.t data struct module to get the __schema__/1 information from the Ecto.Schema.t. It also assumes that if the field maps to no known attribute, association or foreign key, then the error should not have an Alembic.Source.t instead of defaulting to /data/attributes.
  • Alembic.Pagination.Page.count calculates the number of pages given the page size and the total_size of resources to be paginated.
  • Alembic.Pagination.Page.first returns the Alembic.Pagination.Page.t for the first for Alembic.Pagination.t given any page and the page count.
  • Alembic.Pagination.Page.last is the last page for Alembic.Pagination.t given any page and the page count.
  • Alembic.Pagination.Page.next is the next page after the current page. If page number matches count, then it must be the last page and so next will be nil.
  • Alembic.Paginaton.Page.previous is the previous page to the current page. If the page number is 1, then it is the first page, and the previous page is nil.
  • Alembic.Pagination.Page.to_pagination takes the current page and the total_size of resources to paginated and produces the Alembic.Pagination with first, last, next, and previous around that page. If page number is greater than the calculated page count {:error, Alembic.Document.t} is returned instead of {:ok, Alembic.Pagination.t}.
  • Alembic.FromJson.integer_from_json
  • Alembic.FromJson.integer_to_positive_integer takes an integer and returns it if positive, otherwise returns error Document if 0 or below.
  • Alembic.Pagination.Page.from_params parses param format with quoted integer page number and size or JSON format with integer page number and size.
  • Allow pagination opt-out with %{"page" => nil}. Alembic.Pagination.Page.from_params(%{"page" => nil}) will return {:ok, :all} while no "page" param will return {:ok, nil}.
  • Use IntelliJ Elixir formatter for make the formatting consistent
  • Support many_to_many associations in Alembic.ToEctoSchema.to_ecto_schema/2
  • Alembic.ToEctoSchema.to_ecto_schema/2 doctests

Bug Fixes

  • Allow next and previous to be nil in Pagination.t @type since they were already allowed to be nil in use for the last and first page, respectively.
  • Alembic.Pagination.Page number is pos_integer because non_neg_integer allows 0, but that’s not valid because number is 1-based, not 0-based.

ElixirWeekly: The Elixir Community Newsletter, covering community news you easily miss, shared on ElixirStatus and the web, in one email every Thursday.