# `Supabase`

The main entrypoint for the Supabase SDK library.

## Starting a Client

You then can start a Client calling `Supabase.init_client/3`:

    iex> Supabase.init_client("base_url", "api_key", %{db: %{schema: "public"}})
    {:ok, %Supabase.Client{}}

## Acknowledgements

This package represents the base SDK for Supabase. That means
that it not includes all of the functionality of the Supabase client integrations, so you need to install each feature separetely, as:

- [Supabase.GoTrue](https://hexdocs.pm/supabase_gotrue)
- [Supabase.Storage](https://hexdocs.pm/supabase_storage)
- [Supabase.PostgREST](https://hexdocs.pm/supabase_postgrest)
- `Realtime` - TODO
- `UI` - TODO

### Supabase Storage

Supabase Storage is a service for developers to store large objects like images, videos, and other files. It is a hosted object storage service, like AWS S3, but with a simple API and strong consistency.

### Supabase PostgREST

PostgREST is a web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.

### Supabase Realtime

Supabase Realtime provides a realtime websocket API powered by PostgreSQL notifications. It allows you to listen to changes in your database, and instantly receive updates as soon as they happen.

### Supabase Auth/GoTrue

Supabase Auth is a feature-complete user authentication system. It provides email & password sign in, email verification, password recovery, session management, and more, out of the box.

### Supabase UI

Supabase UI is a set of UI components that help you quickly build Supabase-powered applications. It is built on top of Tailwind CSS and Headless UI, and is fully customizable. The package provides `Phoenix.LiveView` components!

# `result`

```elixir
@type result(a) :: {:ok, a} | {:error, Supabase.Error.t()}
```

Helper typespec to define general success and error returns

# `service`

```elixir
@type service() :: :database | :storage | :auth | :functions | :realtime
```

The available Supabase services to interact with

# `init_client`

```elixir
@spec init_client(supabase_url, supabase_key, options) ::
  {:ok, Supabase.Client.t()} | {:error, changeset()}
when supabase_url: String.t(),
     supabase_key: String.t(),
     options: Supabase.Client.options()
```

Creates a new Supabase client struct

## Parameters
- `base_url`: The unique Supabase URL which is supplied when you create a new project in your project dashboard.
- `api_key`: The unique Supabase Key which is supplied when you create a new project in your project dashboard.
- `options`: Additional options to configure the client behaviour, check `Supabase.Client.options()` typespec to check all available options.

## Examples
    iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>")
    iex> {:ok, %Supabase.Client{}}

    iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>",
      db: [schema: "another"],
      auth: [flow_type: :pkce],
      global: [headers: %{"custom-header" => "custom-value"}]
    )
    iex> {:ok, %Supabase.Client{}}

# `init_client!`

```elixir
@spec init_client!(supabase_url, supabase_key, options) :: Supabase.Client.t()
when supabase_url: String.t(), supabase_key: String.t(), options: Enumerable.t()
```

Same as `Supabase.init_client/3` but raises if any errors occurs while
parsing the client options.

# `json_library`

```elixir
@spec json_library() :: Poison | Jason | JSON
```

Returns the configured JSON encoding library for Supabase libraries.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
