diff --git a/CHANGES.txt b/CHANGES.txt index 8a88764..0abaf59 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,9 +1,9 @@ 0.2.0 (February XX, 2025): - BREAKING CHANGES: - - Removed the `fallback_enabled` option from the `Split.Supervisor.start_link/1` function. The fallback behavior is now always enabled, so `Split` functions will never return `{:error, _}` tuples. Instead, they will use the fallback value when an error occurs. - - Updated the return types of `Split.get_treatment/3` and `Split.get_treatments/3` to return the treatment string value and a map of treatment string values, respectively. - - Updated the `Split` struct: renamed the `configurations` field to `configs`, the `flag_sets` field to `sets`, and added the `impressions_disabled` field. - - Updated the signature of all `get_treatment` functions: removed the 3rd argument (`bucketing_key`) and extended the first argument (`key`) to accept a union, allowing a string or a map with the key and optional bucketing key (`{:matching_key, String.t(), :bucketing_key, String.t() | nil}`). + - Removed the `fallback_enabled` option from `Split.Supervisor.start_link/1`. Fallback behavior is now always enabled, so `Split` functions no longer return `{:error, _}` tuples but instead use the fallback value when an error occurs. + - Moved the `Split` struct to the new `Split.SplitView` module and updated some fields: renamed `configurations` to `configs`, `flag_sets` to `sets`, and added the `impressions_disabled` field. + - Updated the return types of `Split.get_treatment/3` and `Split.get_treatments/3` to return a treatment string and a map of treatment strings, respectively. + - Updated all `get_treatment` function signatures: removed the third argument (`bucketing_key`) and expanded the first argument (`key`) to accept a union, allowing either a string or a map with a key and optional bucketing key (`{:matching_key, String.t(), :bucketing_key, String.t() | nil}`). 0.1.0 (January 27, 2025): - BREAKING CHANGES: diff --git a/lib/split.ex b/lib/split.ex index 93013c7..40cea1c 100644 --- a/lib/split.ex +++ b/lib/split.ex @@ -52,21 +52,10 @@ defmodule Split do alias Split.Telemetry alias Split.Sockets.Pool alias Split.Treatment + alias Split.SplitView alias Split.RPC.Message alias Split.RPC.ResponseParser - @type t :: %Split{ - name: String.t(), - traffic_type: String.t(), - killed: boolean(), - treatments: [String.t()], - change_number: integer(), - configs: map(), - default_treatment: String.t(), - sets: [String.t()], - impressions_disabled: boolean() - } - @typedoc "An option that can be provided when starting `Split`." @type option :: {:socket_path, String.t()} @@ -77,18 +66,6 @@ defmodule Split do @type split_key :: String.t() | {:matching_key, String.t(), :bucketing_key, String.t() | nil} - defstruct [ - :name, - :traffic_type, - :killed, - :treatments, - :change_number, - :configs, - :default_treatment, - :sets, - :impressions_disabled - ] - @doc """ Builds a child specification to use in a Supervisor. @@ -164,14 +141,14 @@ defmodule Split do execute_rpc(request) end - @spec split(String.t()) :: Split.t() | nil + @spec split(String.t()) :: SplitView.t() | nil def split(name) do request = Message.split(name) execute_rpc(request) end - @spec splits() :: [Split.t()] + @spec splits() :: [SplitView.t()] def splits do request = Message.splits() execute_rpc(request) diff --git a/lib/split/rpc/response_parser.ex b/lib/split/rpc/response_parser.ex index 6214b58..aa5b69a 100644 --- a/lib/split/rpc/response_parser.ex +++ b/lib/split/rpc/response_parser.ex @@ -9,6 +9,7 @@ defmodule Split.RPC.ResponseParser do alias Split.RPC.Message alias Split.Telemetry alias Split.Treatment + alias Split.SplitView @type splitd_response :: {:ok, map()} | {:error, term()} @@ -17,7 +18,7 @@ defmodule Split.RPC.ResponseParser do """ @spec parse_response(response :: splitd_response(), request :: Message.t(), [ {:span_context, reference()} | {:span_context, nil} - ]) :: map() | list() | Treatment.t() | Split.t() | boolean() | nil + ]) :: map() | list() | Treatment.t() | SplitView.t() | boolean() | nil def parse_response(response, original_request, opts \\ []) @@ -151,7 +152,7 @@ defmodule Split.RPC.ResponseParser do end defp parse_split(payload) do - %Split{ + %SplitView{ name: Map.get(payload, "n", nil), traffic_type: payload["t"], killed: payload["k"], diff --git a/lib/split/split_view.ex b/lib/split/split_view.ex new file mode 100644 index 0000000..312e7e7 --- /dev/null +++ b/lib/split/split_view.ex @@ -0,0 +1,25 @@ +defmodule Split.SplitView do + defstruct [ + :name, + :traffic_type, + :killed, + :treatments, + :change_number, + :configs, + :default_treatment, + :sets, + :impressions_disabled + ] + + @type t :: %__MODULE__{ + name: String.t(), + traffic_type: String.t(), + killed: boolean(), + treatments: [String.t()], + change_number: integer(), + configs: map(), + default_treatment: String.t(), + sets: [String.t()], + impressions_disabled: boolean() + } +end diff --git a/test/rpc/response_parser_test.exs b/test/rpc/response_parser_test.exs index 8a7c776..c185a9d 100644 --- a/test/rpc/response_parser_test.exs +++ b/test/rpc/response_parser_test.exs @@ -6,6 +6,7 @@ defmodule Split.RPC.ResponseParserTest do alias Split.RPC.ResponseParser alias Split.RPC.Message alias Split.Treatment + alias Split.SplitView import ExUnit.CaptureLog @@ -166,7 +167,7 @@ defmodule Split.RPC.ResponseParserTest do }} assert ResponseParser.parse_response(response, message) == - %Split{ + %SplitView{ name: "feature_name", traffic_type: "user", killed: false, @@ -222,7 +223,7 @@ defmodule Split.RPC.ResponseParserTest do # Order of splits is not guaranteed assert ResponseParser.parse_response(response, message) |> Enum.sort_by(& &1.name) == [ - %Split{ + %SplitView{ name: "feature_a", traffic_type: "user", killed: false, @@ -233,7 +234,7 @@ defmodule Split.RPC.ResponseParserTest do sets: [], impressions_disabled: false }, - %Split{ + %SplitView{ name: "feature_b", traffic_type: "user", killed: false, diff --git a/test/split_test.exs b/test/split_test.exs index 36f440d..f279948 100644 --- a/test/split_test.exs +++ b/test/split_test.exs @@ -3,6 +3,7 @@ defmodule SplitThinElixirTest do alias Split.Impression alias Split.Treatment + alias Split.SplitView setup_all context do test_id = :erlang.phash2(context.case) @@ -104,12 +105,12 @@ defmodule SplitThinElixirTest do end test "split/1" do - assert %Split{name: "test-split"} = + assert %SplitView{name: "test-split"} = Split.split("test-split") end test "splits/0" do - assert [%Split{name: "test-split"}] = Split.splits() + assert [%SplitView{name: "test-split"}] = Split.splits() end describe "telemetry" do