Skip to content

Commit

Permalink
fix: dialyzer and compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Jan 16, 2025
1 parent 5033ec0 commit 2cb68b8
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 107 deletions.
Empty file added .dialyzerignore
Empty file.
155 changes: 152 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:
lint:
runs-on: ubuntu-latest

env:
MIX_ENV: test

strategy:
matrix:
elixir: [1.17.0]
elixir: [1.18.1]
otp: [27.0]

steps:
Expand All @@ -27,8 +30,30 @@ jobs:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Install dependencies
run: mix deps.get
- name: Cache Elixir deps
uses: actions/cache@v1
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Cache Elixir _build
uses: actions/cache@v1
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install deps
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get --only ${{ env.MIX_ENV }}
- name: Compile deps
if: steps.build-cache.outputs.cache-hit != 'true'
run: mix deps.compile --warnings-as-errors

- name: Clean build
run: mix clean
Expand All @@ -38,3 +63,127 @@ jobs:

- name: Run Credo
run: mix credo --strict

static-analisys:
runs-on: ubuntu-latest

env:
MIX_ENV: test

strategy:
matrix:
elixir: [1.18.1]
otp: [27.0]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Cache Elixir deps
uses: actions/cache@v1
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Cache Elixir _build
uses: actions/cache@v1
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install deps
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get --only ${{ env.MIX_ENV }}
- name: Compile deps
if: steps.build-cache.outputs.cache-hit != 'true'
run: mix deps.compile --warnings-as-errors

# Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
# Cache key based on Elixir & Erlang version (also useful when running in matrix)
- name: Restore PLT cache
uses: actions/cache/restore@v3
id: plt_cache
with:
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt
restore-keys: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt
path: priv/plts

# Create PLTs if no cache was found
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

- name: Save PLT cache
uses: actions/cache/save@v3
if: steps.plt_cache.outputs.cache-hit != 'true'
id: plt_cache_save
with:
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt
path: priv/plts

- name: Run dialyzer
run: mix dialyzer --format github

test:
runs-on: ubuntu-latest

env:
MIX_ENV: test

strategy:
matrix:
elixir: [1.18.1]
otp: [27.0]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Cache Elixir deps
uses: actions/cache@v1
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Cache Elixir _build
uses: actions/cache@v1
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install deps
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get --only ${{ env.MIX_ENV }}
- name: Compile deps
if: steps.build-cache.outputs.cache-hit != 'true'
run: mix deps.compile --warnings-as-errors

- name: Clean build
run: mix clean

- name: Run tests
run: mix test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ result
.elixir_ls/
.elixir-tools/
.lexical/

/priv/plts/
33 changes: 0 additions & 33 deletions Earthfile

This file was deleted.

13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Supabase GoTrue

> ![WARNING]
> This library is under development and for so expect breaking changes
[Auth](https://supabase.com/docs/guides/auth) implementation for the [Supabase Potion](https://hexdocs.pm/supabase_potion) SDK in Elixir.

## Installation

```elixir
def deps do
[
{:supabase_potion, "~> 0.5"},
{:supabase_gotrue, "~> 0.3"}
{:supabase_potion, "~> 0.6"},
{:supabase_gotrue, "~> 0.4"}
]
end
```
Expand Down Expand Up @@ -36,7 +39,7 @@ iex> Supabase.GoTrue.Admin.create_user(client, %{} = params)

There are sample apps in the `examples` directory that demonstrate how to use the `Supabase.GoTrue` module in your application.

Check the [Supabase Potion examples showcase](https://github.com/zoedsoupe/supabase-ex?tab=readme-ov-file#examples)!
Check the [Supabase Potion examples showcase](https://github.com/supabase-community/supabase-ex?tab=readme-ov-file#examples)!

### Configuration

Expand Down Expand Up @@ -85,7 +88,7 @@ end

> [!WARNING]
> The `client` options must be a module that implements the `Supabase.Client.Behaviour` behaviour.
> It should be a [Self Managed Client](https://github.com/zoedsoupe/supabase-ex?tab=readme-ov-file#self-managed-clients) but it can be a [One off Client](https://github.com/zoedsoupe/supabase-ex?tab=readme-ov-file#one-off-clients) if you correctly manage the client state on your application.
> It should be a [Self Managed Client](https://github.com/supabase-community/supabase-ex?tab=readme-ov-file#self-managed-clients) but it can be a [One off Client](https://github.com/supabase-community/supabase-ex?tab=readme-ov-file#one-off-clients) if you correctly manage the client state on your application.
So, considering that you have something like this on your `config.exs`:

Expand Down Expand Up @@ -204,7 +207,7 @@ end

> [!WARNING]
> The `client` options must be a module that implements the `Supabase.Client.Behaviour` behaviour.
> It should be a [Self Managed Client](https://github.com/zoedsoupe/supabase-ex?tab=readme-ov-file#self-managed-clients) but it can be a [One off Client](https://github.com/zoedsoupe/supabase-ex?tab=readme-ov-file#one-off-clients) if you correctly manage the client state on your application.
> It should be a [Self Managed Client](https://github.com/supabase-community/supabase-ex?tab=readme-ov-file#self-managed-clients) but it can be a [One off Client](https://github.com/supabase-community/supabase-ex?tab=readme-ov-file#one-off-clients) if you correctly manage the client state on your application.
So, considering that you have something like this on your `config.exs`:

Expand Down
6 changes: 3 additions & 3 deletions lib/supabase/go_true.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Supabase.GoTrue do
@impl true
def get_user(%Client{} = client, %Session{} = session) do
with {:ok, response} <- UserHandler.get_user(client, session.access_token) do
User.parse(response)
User.parse(response.body)
end
end

Expand Down Expand Up @@ -116,7 +116,7 @@ defmodule Supabase.GoTrue do
@impl true
def verify_otp(%Client{} = client, params) do
with{:ok, response} <- UserHandler.verify_otp(client, params) do
Session.parse(response)
Session.parse(response.body)
end
end

Expand Down Expand Up @@ -155,7 +155,7 @@ defmodule Supabase.GoTrue do
def sign_in_with_password(%Client{} = client, credentials) do
with{:ok, credentials} <- SignInWithPassword.parse(credentials),
{:ok, response} <- UserHandler.sign_in_with_password(client, credentials) do
Session.parse(response)
Session.parse(response.body)
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/supabase/go_true/admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ defmodule Supabase.GoTrue.Admin do
def sign_out(%Client{} = client, %Session{} = session, scope) when scope in @scopes do
case AdminHandler.sign_out(client, session.access_token, scope) do
{:ok, _} -> :ok
{:error, :not_found} -> :ok
{:error, :unauthorized} -> :ok
{:error, %{code: :not_found}} -> :ok
{:error, %{code: :unauthorized}} -> :ok
err -> err
end
end
Expand All @@ -57,7 +57,7 @@ defmodule Supabase.GoTrue.Admin do
def invite_user_by_email(%Client{} = client, email, options \\ %{}) do
with {:ok, options} <- InviteUserParams.parse(options),
{:ok, response} <- AdminHandler.invite_user(client, email, options) do
User.parse(response)
User.parse(response.body)
end
end

Expand All @@ -75,7 +75,7 @@ defmodule Supabase.GoTrue.Admin do
def generate_link(%Client{} = client, attrs) do
with {:ok, params} <- GenerateLink.parse(attrs),
{:ok, response} <- AdminHandler.generate_link(client, params) do
GenerateLink.properties(response)
GenerateLink.properties(response.body)
end
end

Expand All @@ -93,7 +93,7 @@ defmodule Supabase.GoTrue.Admin do
def create_user(%Client{} = client, attrs) do
with {:ok, params} <- AdminUserParams.parse(attrs),
{:ok, response} <- AdminHandler.create_user(client, params) do
User.parse(response)
User.parse(response.body)
end
end

Expand Down Expand Up @@ -128,7 +128,7 @@ defmodule Supabase.GoTrue.Admin do
@impl true
def get_user_by_id(%Client{} = client, user_id) do
with {:ok, response} <- AdminHandler.get_user(client, user_id) do
User.parse(response)
User.parse(response.body)
end
end

Expand Down Expand Up @@ -199,7 +199,7 @@ defmodule Supabase.GoTrue.Admin do
def update_user_by_id(%Client{} = client, user_id, attrs) do
with {:ok, params} <- AdminUserParams.parse_update(attrs),
{:ok, response} <- AdminHandler.update_user(client, user_id, params) do
User.parse(response)
User.parse(response.body)
end
end
end
19 changes: 9 additions & 10 deletions lib/supabase/go_true/admin_behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ defmodule Supabase.GoTrue.AdminBehaviour do
@type scope :: :global | :local | :others
@type invite_options :: %{data: map, redirect_to: String.t()}

@callback sign_out(Client.t(), Session.t(), scope) :: :ok | {:error, atom}
@callback invite_user_by_email(Client.t(), email, invite_options) :: :ok | {:error, atom}
@callback sign_out(Client.t(), Session.t(), scope) :: :ok | {:error, Supabase.Error.t()}
@callback invite_user_by_email(Client.t(), email, invite_options) ::
:ok | {:error, Supabase.Error.t()}
when email: String.t()
@callback generate_link(Client.t(), map) :: {:ok, String.t()} | {:error, atom}
@callback create_user(Client.t(), map) :: {:ok, User.t()} | {:error, atom}
@callback list_users(Client.t()) :: {:ok, list(User.t())} | {:error, atom}
@callback get_user_by_id(Client.t(), Ecto.UUID.t()) :: {:ok, User.t()} | {:error, atom}
@callback update_user_by_id(Client.t(), Ecto.UUID.t(), map) ::
{:ok, User.t()} | {:error, atom}
@callback delete_user(Client.t(), Ecto.UUID.t(), keyword) ::
{:ok, User.t()} | {:error, atom}
@callback generate_link(Client.t(), map) :: Supabase.result(String.t())
@callback create_user(Client.t(), map) :: Supabase.result(User.t())
@callback list_users(Client.t()) :: Supabase.result(list(User.t()))
@callback get_user_by_id(Client.t(), Ecto.UUID.t()) :: Supabase.result(User.t())
@callback update_user_by_id(Client.t(), Ecto.UUID.t(), map) :: Supabase.result(User.t())
@callback delete_user(Client.t(), Ecto.UUID.t(), keyword) :: Supabase.result(User.t())
end
2 changes: 1 addition & 1 deletion lib/supabase/go_true/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Supabase.GoTrue.Auth do
end

defp network_failure_changeset(failure, attrs) do
cast(failure, attrs, ~w[max_retries max_interval])
cast(failure, attrs, ~w[max_retries max_interval]a)
end

def parse_mfa(attrs) do
Expand Down
Loading

0 comments on commit 2cb68b8

Please sign in to comment.