Skip to content

Commit e290e05

Browse files
authored
fix: allow configure json library for supabase libs (#70)
1 parent c9d02fe commit e290e05

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

lib/supabase.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,9 @@ defmodule Supabase do
165165
defmacro __using__(which) when is_atom(which) do
166166
apply(__MODULE__, which, [])
167167
end
168+
169+
@doc "Returns the configured JSON encoding library for Supabase libraries."
170+
def json_library do
171+
Application.get_env(:supabase, :json_library, Jason)
172+
end
168173
end

lib/supabase/fetcher/body_decoder.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ defmodule Supabase.Fetcher.JSONDecoder do
3535
@impl true
3636
def decode(%Response{body: body}, opts \\ []) do
3737
keys = Keyword.get(opts, :keys, :strings)
38-
Jason.decode(body, keys: keys)
38+
Supabase.json_library().decode(body, keys: keys)
3939
end
4040
end

lib/supabase/fetcher/request.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ defmodule Supabase.Fetcher.Request do
196196

197197
@doc """
198198
Defines the request body to be sent, it can be a map, that will be encoded
199-
with `Jason.encode_to_iodata!/1`, any `iodata` or a stream body in the pattern of `{:stream, Enumerable.t}`, although you will problably prefer to use the `upload/2`
199+
with `encode_to_iodata!/1`, any `iodata` or a stream body in the pattern of `{:stream, Enumerable.t}`, although you will problably prefer to use the `upload/2`
200200
function of this module to hadle body stream since it will handle file management, content headers and so on.
201201
"""
202202
@impl true
203203
def with_body(builder, body \\ nil)
204204

205205
def with_body(%__MODULE__{} = builder, %{} = body) do
206-
%{builder | body: Jason.encode_to_iodata!(body)}
206+
json_library = Supabase.json_library()
207+
%{builder | body: json_library.encode_to_iodata!(body)}
207208
end
208209

209210
def with_body(%__MODULE__{} = builder, body) do

lib/supabase/fetcher/request/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Supabase.Fetcher.Request.Behaviour do
1414
@callback with_http_client(Request.t(), adapter :: module) :: Request.t()
1515
@callback with_query(Request.t(), query :: Enumerable.t()) :: Request.t()
1616
@callback with_body(Request.t(), body) :: Request.t()
17-
when body: Jason.Encoder.t() | {:stream, Enumerable.t()} | nil
17+
when body: term | {:stream, Enumerable.t()} | nil
1818
@callback with_headers(Request.t(), headers) :: Request.t()
1919
when headers: Supabase.Fetcher.headers()
2020
@callback with_body_decoder(Request.t(), decoder, decoder_opts) :: Request.t()

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ defmodule Supabase.MixProject do
3333
[
3434
{:mime, "~> 2.0"},
3535
{:finch, "~> 0.16"},
36-
{:jason, "~> 1.4"},
3736
{:ecto, "~> 3.10"},
37+
{:jason, "~> 1.4", optional: true},
3838
{:mox, "~> 1.2", only: :test},
3939
{:ex_doc, ">= 0.0.0", only: [:dev], runtime: false},
4040
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},

0 commit comments

Comments
 (0)