Skip to content

Commit 040c469

Browse files
authored
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
1 parent c2b1168 commit 040c469

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+967
-1782
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Earthly version
3232
run: earthly --version
3333
- name: Run lint
34-
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +ci
34+
run: earthly -P +ci

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Earthly version
3232
run: earthly --version
3333
- name: Run unit tests
34-
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +unit-test
34+
run: earthly -P +unit-test

Earthfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
VERSION 0.7
22

33
deps:
4-
ARG ELIXIR=1.15.4
5-
FROM hexpm/elixir:${ELIXIR}-alpine
4+
ARG ELIXIR=1.15.6
5+
FROM hexpm/elixir:${ELIXIR}-erlang-26.1.1-alpine-3.18.2
66
WORKDIR /src
77
COPY mix.exs mix.lock ./
8-
COPY --dir apps . # check .earthlyignore
98
RUN mix local.rebar --force
109
RUN mix local.hex --force
1110
RUN mix deps.get
1211
SAVE ARTIFACT /src/deps AS LOCAL deps
1312

1413
ci:
1514
FROM +deps
16-
COPY .credo.exs .
1715
COPY .formatter.exs .
1816
RUN mix clean
1917
RUN mix compile --warning-as-errors
@@ -27,7 +25,7 @@ unit-test:
2725
FROM +deps
2826
RUN MIX_ENV=test mix deps.compile
2927
COPY mix.exs mix.lock ./
30-
COPY .env-sample ./
3128
COPY --dir config ./
32-
COPY --dir apps ./
29+
COPY --dir lib ./
30+
COPY --dir test ./
3331
RUN mix test

README.md

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ This monorepo houses the collection of Elixir SDK packages for integrating with
66

77
## Packages Overview
88

9-
- **Supabase**: Main entrypoint for the Supabase SDK library, providing easy management for Supabase clients and connections.
10-
- **Supabase Connection**: Handles individual connections to Supabase, encapsulating the API endpoint and credentials.
11-
- **Supabase Storage**: Offers developers a way to store large objects like images, videos, and other files.
12-
- **Supabase PostgREST**: Directly turns your PostgreSQL database into a RESTful API using PostgREST.
13-
- **Supabase Realtime**: Provides a realtime websocket API, enabling listening to database changes.
14-
- **Supabase Auth**: A comprehensive user authentication system, complete with email sign-in, password recovery, session management, and more.
15-
- **Supabase UI**: UI components to help build Supabase-powered applications quickly.
16-
- **Supabase Fetcher**: Customized HTTP client for making requests to Supabase APIs.
9+
- **Supabase**: Main entrypoint for the Supabase SDK library, providing easy management for Supabase clients and connections. [Guide](#usage).
10+
- **Supabase Storage**: Offers developers a way to store large objects like images, videos, and other files. [Guide](./guides/storage.md)
11+
- **Supabase PostgREST**: Directly turns your PostgreSQL database into a RESTful API using PostgREST. [Guide](#)
12+
- **Supabase Realtime**: Provides a realtime websocket API, enabling listening to database changes. [Guide](#)
13+
- **Supabase Auth**: A comprehensive user authentication system, complete with email sign-in, password recovery, session management, and more. [Guide](#)
14+
- **Supabase UI**: UI components to help build Supabase-powered applications quickly. [Guide](#)
15+
- **Supabase Fetcher**: Customized HTTP client for making requests to Supabase APIs. [Guide](./guides/fetcher.md)
1716

1817
## Getting Started
1918

@@ -29,81 +28,70 @@ def deps do
2928
end
3029
```
3130

32-
Or, install specific packages as needed:
33-
34-
```elixir
35-
def deps do
36-
[
37-
{:supabase_storage, "~> 0.1"},
38-
{:supabase_realtime, "~> 0.1"},
39-
# ... add other packages
40-
]
41-
end
42-
```
43-
44-
### Clients vs Connections
31+
### Clients
4532

4633
A `Supabase.Client` is an Agent that holds general information about Supabase, that can be used to intereact with any of the children integrations, for example: `Supabase.Storage` or `Supabase.UI`.
4734

48-
Also a `Supabase.Client` holds a list of `Supabase.Connection` that can be used to perform operations on different buckets, for example.
49-
5035
`Supabase.Client` is defined as:
5136

5237
- `:name` - the name of the client, started by `start_link/1`
53-
- `:connections` - a list of `%{conn_alias => conn_name}`, where `conn_alias` is the alias of the connection and `conn_name` is the name of the connection.
38+
- `:conn` - connection information, the only required option as it is vital to the `Supabase.Client`.
39+
- `:base_url` - The base url of the Supabase API, it is usually in the form `https://<app-name>.supabase.io`.
40+
- `:api_key` - The API key used to authenticate requests to the Supabase API.
41+
- `:access_token` - Token with specific permissions to access the Supabase API, it is usually the same as the API key.
5442
- `:db` - default database options
55-
- `:schema` - default schema to use, defaults to `"public"`
43+
- `:schema` - default schema to use, defaults to `"public"`
5644
- `:global` - global options config
57-
- `:headers` - additional headers to use on each request
45+
- `:headers` - additional headers to use on each request
5846
- `:auth` - authentication options
59-
- `:auto_refresh_token` - automatically refresh the token when it expires, defaults to `true`
60-
- `:debug` - enable debug mode, defaults to `false`
61-
- `:detect_session_in_url` - detect session in URL, defaults to `true`
62-
- `:flow_type` - authentication flow type, defaults to `"web"`
63-
- `:persist_session` - persist session, defaults to `true`
64-
- `:storage` - storage type
65-
- `:storage_key` - storage key
66-
47+
- `:auto_refresh_token` - automatically refresh the token when it expires, defaults to `true`
48+
- `:debug` - enable debug mode, defaults to `false`
49+
- `:detect_session_in_url` - detect session in URL, defaults to `true`
50+
- `:flow_type` - authentication flow type, defaults to `"web"`
51+
- `:persist_session` - persist session, defaults to `true`
52+
- `:storage` - storage type
53+
- `:storage_key` - storage key
6754

68-
On the other side, a `Supabase.Connection` is an Agent that holds the connection information and the current bucket, being defined as:
55+
## Usage
6956

70-
- `:base_url` - The base url of the Supabase API, it is usually in the form `https://<app-name>.supabase.io`.
71-
- `:api_key` - The API key used to authenticate requests to the Supabase API.
72-
- `:access_token` - Token with specific permissions to access the Supabase API, it is usually the same as the API key.
73-
- `:name` - Simple field to track the name of the connection, started by `start_link/1`.
74-
- `:alias` - Field to easily manage multiple connections on a `Supabase.Client` Agent.
75-
- `:bucket` - The current bucket to perform operations on.
57+
The Supabase Elixir SDK provides a flexible way to manage `Supabase.Client` instances, which can, in turn, manage multiple `Supabase.Client` instances. Here's a brief overview of the key concepts:
7658

77-
In simple words, a `Supabase.Client` is a container for multiple `Supabase.Connection`, and each `Supabase.Connection` is a container for a single bucket.
59+
### Starting a Client
7860

79-
### Establishing a Connection
80-
81-
To start a Supabase connection:
61+
You can start a client using the `Supabase.Client.start_link/1` function. However, it's recommended to use `Supabase.init_client!/1`, which allows you to pass client options and automatically manage `Supabase.Client` processes.
8262

8363
```elixir
84-
Supabase.init_connection(%{base_url: "https://myapp.supabase.io", api_key: "my_api_key", name: :my_conn, alias: :conn})
64+
iex> Supabase.Client.init_client!(%{conn: %{base_url: "<supa-url>", api_key: "<supa-key>"}})
65+
{:ok, #PID<0.123.0>}
8566
```
8667

87-
This will automatically adds the Connection instance to a `DynamicSupervisor` that can be found in the [`Supabase.Connection`](./apps/supabase_connection/lib/supabase/connection_supervisor.ex) specific module documentation.
68+
## Supabase Services
8869

89-
For manually Connection creation and management, please refer to the corresponding documentation:
70+
The Supabase Elixir SDK allows you to interact with various Supabase services:
9071

91-
- [Supabase.Connection](./apps/supabase_connection/lib/supabase/connection.ex)
72+
### Supabase Storage
9273

93-
### Creating a Client
74+
Supabase Storage is a service for storing large objects like images, videos, and other files. It provides a simple API with strong consistency, similar to AWS S3.
9475

95-
To start a Supabase Client:
76+
### Supabase PostgREST
9677

97-
```elixir
98-
Supabase.init_client(%{name: :my_client}, [conn_list])
99-
```
78+
PostgREST is a web server that turns your PostgreSQL database into a RESTful API. It automatically generates API endpoints and operations based on your database's structure and permissions.
79+
80+
### Supabase Realtime
81+
82+
Supabase Realtime offers a realtime WebSocket API powered by PostgreSQL notifications. You can use it to listen to changes in your database and receive updates instantly as they happen.
10083

101-
This will automatically adds the Client instance to a `DynamicSupervisor` that can be found in the [`Supabase.ClientSupervisor`](./apps/supabase/lib/supabase/client_supervisor.ex) specific module documentation.
84+
### Supabase Auth
10285

103-
For manually Client creation and management, please refer to the corresponding documentation:
86+
Supabase Auth is a comprehensive user authentication system that includes features like email and password sign-in, email verification, password recovery, session management, and more, out of the box.
10487

105-
- [Supabase.Client](./apps/supabase/lib/supabase/client.ex)
88+
### Supabase UI
10689

90+
Supabase UI provides a set of UI components to help you build Supabase-powered applications quickly. It's built on top of Tailwind CSS and Headless UI, and it's fully customizable. The package even includes `Phoenix.LiveView` components!
91+
92+
### Supabase Fetcher
93+
94+
Supabase Fetcher is a customized HTTP client for Supabase, mainly used in Supabase Potion. It gives you complete control over how you make requests to any Supabase API.
10795

10896
## Configuration
10997

@@ -112,7 +100,8 @@ Ensure your Supabase configurations are set:
112100
```elixir
113101
import Config
114102

115-
config :supabase_fetch,
103+
config :supabase,
104+
manage_clients?: true,
116105
supabase_url: System.fetch_env!("SUPABASE_BASE_URL"),
117106
supabase_key: System.fetch_env!("SUPABASE_API_KEY"),
118107
```
@@ -127,6 +116,7 @@ If you want to track integration-specific roadmaps, check their own README.
127116

128117
- [x] Fetcher to interact with the Supabase API in a low-level way
129118
- [x] Supabase Storage integration
119+
- [ ] Supabase UI for Phoenix Live View
130120
- [ ] Supabase Postgrest integration
131121
- [ ] Supabase Auth integration
132122
- [ ] Supabase Realtime API integration
@@ -154,3 +144,7 @@ This SDK is a comprehensive representation of Supabase's client integrations. Th
154144
## License
155145

156146
[MIT](LICENSE)
147+
148+
---
149+
150+
With the Supabase Elixir SDK, you have the tools you need to supercharge your Elixir applications by seamlessly integrating them with Supabase's powerful cloud services. Happy coding! 😄

apps/supabase/.formatter.exs

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/supabase/.gitignore

Lines changed: 0 additions & 26 deletions
This file was deleted.

apps/supabase/README.md

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)