Skip to content

Commit

Permalink
Merge pull request #473 from woylie/elixir-1.17
Browse files Browse the repository at this point in the history
elixir 1.17
  • Loading branch information
woylie authored Jun 13, 2024
2 parents c94d8e6 + 4ce5cd1 commit 2878db6
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 198 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI

env:
ELIXIR_VERSION: "1.16"
OTP_VERSION: "26"
ELIXIR_VERSION: "1.17"
OTP_VERSION: "27"

on:
push:
Expand All @@ -19,9 +19,6 @@ jobs:
strategy:
matrix:
include:
- { elixir: 1.12, otp: 22 }
- { elixir: 1.12, otp: 23 }
- { elixir: 1.12, otp: 24 }
- { elixir: 1.13, otp: 22 }
- { elixir: 1.13, otp: 23 }
- { elixir: 1.13, otp: 24 }
Expand All @@ -34,6 +31,9 @@ jobs:
- { elixir: 1.16, otp: 24 }
- { elixir: 1.16, otp: 25 }
- { elixir: 1.16, otp: 26 }
- { elixir: 1.17, otp: 25 }
- { elixir: 1.17, otp: 26 }
- { elixir: 1.17, otp: 27 }
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

## Unreleased

### Removed

- The previously deprecated tuple syntax for defining join fields has been
removed in favor of a keyword list.
- The previously deprecated function `Flop.Schema.field_type/2` was removed in
favor of `Flop.Schema.field_info/2`.

### Upgrade Guide

Replace the tuple syntax for join fields with a keyword list.

```diff
@derive {
Flop.Schema,
join_fields: [
- owner_name: {:owner, :name}
+ owner_name: [
+ binding: :owner,
+ field: :name
+ ]
]
}
```

## [0.25.0] - 2024-01-14

### Added
Expand Down
7 changes: 6 additions & 1 deletion lib/flop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,12 @@ defmodule Flop do
filterable: [:name, :owner_age],
sortable: [:name, :owner_age],
adapter_opts: [
join_fields: [owner_age: {:owner, :age}]
join_fields: [
owner_age: [
binding: :owner,
field: :age
]
]
]
}
Expand Down
15 changes: 0 additions & 15 deletions lib/flop/adapter/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -699,21 +699,6 @@ defmodule Flop.Adapter.Ecto do
Enum.into(fields, %{}, &normalize_join_field_opts/1)
end

defp normalize_join_field_opts({name, {binding, field}}) do
Logger.warning(
"The tuple syntax for defining Flop join fields has been deprecated. Use a keyword list instead."
)

opts = %{
binding: binding,
field: field,
path: [binding, field],
ecto_type: nil
}

{name, opts}
end

defp normalize_join_field_opts({name, opts}) when is_list(opts) do
binding = Keyword.fetch!(opts, :binding)
field = Keyword.fetch!(opts, :field)
Expand Down
18 changes: 7 additions & 11 deletions lib/flop/nimble_schemas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@ defmodule Flop.NimbleSchemas do
default: [],
keys: [
*: [
type:
{:or,
[
keyword_list: [
binding: [type: :atom, required: true],
field: [type: :atom, required: true],
ecto_type: [type: :any],
path: [type: {:list, :atom}]
],
tuple: [:atom, :atom]
]}
type: :keyword_list,
keys: [
binding: [type: :atom, required: true],
field: [type: :atom, required: true],
ecto_type: [type: :any],
path: [type: {:list, :atom}]
]
]
]
],
Expand Down
119 changes: 0 additions & 119 deletions lib/flop/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -634,56 +634,6 @@ defprotocol Flop.Schema do
| {:from_schema, module, atom}
| {:ecto_enum, [atom] | keyword}

@doc """
Returns the field type in a schema.
- `{:normal, atom}` - An ordinary field on the schema. The second tuple
element is the field name.
- `{:compound, [atom]}` - A combination of fields defined with the
`compound_fields` option. The list of atoms refers to the list of fields
that are included.
- `{:join, map}` - A field from a named binding as defined with the
`join_fields` option. The map has keys for the `:binding`, `:field` and
`:path`.
- `{:custom, keyword}` - A filter field that uses a custom filter function.
## Examples
iex> field_type(%MyApp.Pet{}, :age)
{:normal, :age}
iex> field_type(%MyApp.Pet{}, :full_name)
{:compound, [:family_name, :given_name]}
iex> field_type(%MyApp.Pet{}, :owner_name)
{
:join,
%{
binding: :owner,
field: :name,
path: [:owner, :name],
ecto_type: :string
}
}
iex> field_type(%MyApp.Pet{}, :reverse_name)
{
:custom,
%{
filter: {MyApp.Pet, :reverse_name_filter, []},
ecto_type: :string,
operators: nil,
bindings: []
}
}
"""
@doc since: "0.11.0"
@spec field_type(any, atom) ::
{:normal, atom}
| {:compound, [atom]}
| {:join, map}
| {:alias, atom}
| {:custom, map}
@deprecated "use field_info/2 instead"
def field_type(data, field)

@doc """
Returns the field information for the given field name.
Expand Down Expand Up @@ -899,11 +849,6 @@ defimpl Flop.Schema, for: Any do

validate_options!(options, adapter_opts, struct)

alias_fields = Map.fetch!(adapter_opts, :alias_fields)
compound_fields = Map.fetch!(adapter_opts, :compound_fields)
custom_fields = Map.fetch!(adapter_opts, :custom_fields)
join_fields = Map.fetch!(adapter_opts, :join_fields)

filterable_fields = Keyword.get(options, :filterable)
sortable_fields = Keyword.get(options, :sortable)
default_limit = Keyword.get(options, :default_limit)
Expand All @@ -912,14 +857,6 @@ defimpl Flop.Schema, for: Any do
default_pagination_type = Keyword.get(options, :default_pagination_type)
default_order = Keyword.get(options, :default_order)

field_type_func =
build_field_type_func(
compound_fields,
join_fields,
alias_fields,
custom_fields
)

field_info_func = build_field_info_func(adapter, adapter_opts, struct)
get_field_func = build_get_field_func(struct, adapter, adapter_opts)

Expand All @@ -938,7 +875,6 @@ defimpl Flop.Schema, for: Any do
end

unquote(field_info_func)
unquote(field_type_func)
unquote(get_field_func)

def filterable(_) do
Expand Down Expand Up @@ -1052,54 +988,6 @@ defimpl Flop.Schema, for: Any do
end
end

def build_field_type_func(
compound_fields,
join_fields,
alias_fields,
custom_fields
) do
compound_field_funcs = field_type_funcs(:compound, compound_fields)
join_field_funcs = field_type_funcs(:join, join_fields)
alias_field_funcs = field_type_funcs(:alias, alias_fields)
custom_field_funcs = field_type_funcs(:custom, custom_fields)

default_funcs =
quote do
def field_type(_, name) do
{:normal, name}
end
end

quote do
unquote(compound_field_funcs)
unquote(join_field_funcs)
unquote(alias_field_funcs)
unquote(custom_field_funcs)
unquote(default_funcs)
end
end

defp field_type_funcs(type, fields)
when type in [:compound, :join, :custom] do
for {name, value} <- fields do
quote do
def field_type(_, unquote(name)) do
{unquote(type), unquote(Macro.escape(value))}
end
end
end
end

defp field_type_funcs(:alias, fields) do
for name <- fields do
quote do
def field_type(_, unquote(name)) do
{:alias, unquote(name)}
end
end
end
end

def build_get_field_func(struct, adapter, adapter_opts) do
for {field, field_info} <- adapter.fields(struct, adapter_opts) do
quote do
Expand Down Expand Up @@ -1140,13 +1028,6 @@ defimpl Flop.Schema, for: Any do
description: @instructions
end

def field_type(struct, _) do
raise Protocol.UndefinedError,
protocol: @protocol,
value: struct,
description: @instructions
end

def custom(_, _), do: []

# add default implementation for maps, so that cursor value functions can use
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.6", "b8f14011a5443f2839b04def0b252300842ce7388f3af177157c86da18dfbeea", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "146f347fb9f8cbc5f7e39e3f22f70acbef51d441baa6d10169dd604bfbc55296"},
"credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"},
"db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
Expand All @@ -20,6 +20,6 @@
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"postgrex": {:hex, :postgrex, "0.18.0", "f34664101eaca11ff24481ed4c378492fed2ff416cd9b06c399e90f321867d7e", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "a042989ba1bc1cca7383ebb9e461398e3f89f868c92ce6671feb7ef132a252d1"},
"stream_data": {:hex, :stream_data, "1.1.0", "ef3a7cac0f200c43caf3e6caf9be63115851b4f1cde3f21afaab220adc40e3d7", [:mix], [], "hexpm", "cccc411d5facf1bab86e7c671382d164f05f8992574c95349d3c8b317e14d953"},
"stream_data": {:hex, :stream_data, "1.1.1", "fd515ca95619cca83ba08b20f5e814aaf1e5ebff114659dc9731f966c9226246", [:mix], [], "hexpm", "45d0cd46bd06738463fd53f22b70042dbb58c384bb99ef4e7576e7bb7d3b8c8c"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
}
Loading

0 comments on commit 2878db6

Please sign in to comment.