Skip to content

Commit

Permalink
Split Supabase Storage (#13)
Browse files Browse the repository at this point in the history
* Refactor/project restructure (#11)

* feat: remove umbrella project

* refactor: use client to storage

* fix: credo

* refactor: documentation

* feat: add bang option to init_client/1

* fix: improve ci

* feat: supabase basic tests

* feat: split supabase storage
  • Loading branch information
zoedsoupe committed Oct 10, 2023
1 parent ba20bec commit 688cdf3
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 1,588 deletions.
1 change: 0 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ unit-test:
FROM +deps
RUN MIX_ENV=test mix deps.compile
COPY mix.exs mix.lock ./
COPY --dir config ./
COPY --dir lib ./
COPY --dir test ./
RUN mix test
1 change: 0 additions & 1 deletion config/config.exs

This file was deleted.

5 changes: 0 additions & 5 deletions config/runtime.exs

This file was deleted.

5 changes: 5 additions & 0 deletions guides/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This module provides a set of Elixir functions that integrate seamlessly with Supabase's Storage API, allowing developers to perform various operations on buckets and objects.

For more detailed information and specialized documentation, refers to:

- [supabase_storage](https://github.com/zoedsoupe/supabase_storage)
- [supabase storage docs](https://hexdocs.pm/supabase_storage)

### Features

1. **Bucket Operations**: Easily create, list, empty, or remove buckets.
Expand Down
18 changes: 1 addition & 17 deletions lib/supabase/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ defmodule Supabase.Application do

use Application

alias Supabase.Storage

@finch_opts [name: Supabase.Finch, pools: %{:default => [size: 10]}]

@impl true
def start(_start_type, _args) do
children = [
{Finch, @finch_opts},
if(manage_clients?(), do: Supabase.ClientSupervisor),
if(manage_clients?(), do: Supabase.ClientRegistry),
if(start_cache?(), do: {Storage.Cache, cache_max_size: cache_max_size()}),
if(start_cache?(), do: {Storage.CacheSupervisor, reload_interval: reload_interval()})
if(manage_clients?(), do: Supabase.ClientRegistry)
]

opts = [strategy: :one_for_one, name: Supabase.Supervisor]
Expand All @@ -27,16 +23,4 @@ defmodule Supabase.Application do
defp manage_clients? do
Application.get_env(:supabase, :manage_clients, true)
end

defp cache_max_size do
Application.get_env(:supabase, :cache_max_size, 100)
end

defp start_cache? do
Application.get_env(:supabase, :cache_buckets?)
end

defp reload_interval do
Application.get_env(:supabase, :reload_interval, 60_000)
end
end
19 changes: 19 additions & 0 deletions lib/supabase/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ defmodule Supabase.Client do
|> cast_embed(:global, required: false)
|> cast_embed(:auth, required: false)
|> validate_required([:name])
|> maybe_put_assocs()
|> apply_action(:parse)
end

Expand All @@ -130,6 +131,24 @@ defmodule Supabase.Client do
end
end

defp maybe_put_assocs(%{valid?: false} = changeset), do: changeset

defp maybe_put_assocs(changeset) do
auth = get_change(changeset, :auth)
db = get_change(changeset, :db)
global = get_change(changeset, :global)

changeset
|> maybe_put_assoc(:auth, auth, %Auth{})
|> maybe_put_assoc(:db, db, %Db{})
|> maybe_put_assoc(:global, global, %Global{})
end

defp maybe_put_assoc(changeset, key, nil, default),
do: put_change(changeset, key, default)

defp maybe_put_assoc(changeset, _key, _assoc, _default), do: changeset

def start_link(config) do
name = Keyword.get(config, :name)
client_info = Keyword.get(config, :client_info)
Expand Down
1 change: 1 addition & 0 deletions lib/supabase/client/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Supabase.Client.Db do
@type t :: %__MODULE__{schema: String.t()}
@type params :: %{schema: String.t()}

@primary_key false
embedded_schema do
field(:schema, :string, default: "public")
end
Expand Down
1 change: 1 addition & 0 deletions lib/supabase/client/global.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Supabase.Client.Global do
@type t :: %__MODULE__{headers: Map.t()}
@type params :: %{headers: Map.t()}

@primary_key false
embedded_schema do
field(:headers, {:map, :string}, default: %{})
end
Expand Down
Loading

0 comments on commit 688cdf3

Please sign in to comment.