View Source OpenFeature.Provider behaviour (OpenFeature v0.1.1)

This module provides the behaviour that must be implemented by all providers. Also includes helper functions to be used with providers.

Summary

Callbacks

Initializes the provider with the domain and context, and sets the provider's state to :ready.

Resolves the boolean value of a flag based on the key, default value, and context.

Resolves the map value of a flag based on the key, default value, and context.

Resolves the number value of a flag based on the key, default value, and context.

Resolves the string value of a flag based on the key, default value, and context.

Shuts down the provider and cleans up any resources.

Functions

Checks if two providers are equal based on their name, domain, and state.

Initializes the provider and emits the :ready event if successful. If an error occurs, emits the :error event.

Resolves the value of a flag based on the key, default value, and context.

Shuts down the provider and catches any errors that may occur.

Validates if the provider implements the required functions.

Types

@type error() ::
  {:error, :flag_not_found}
  | {:error, :variant_not_found, binary() | nil}
  | {:error, :unexpected_error, Exception.t()}
Link to this type

result()

View Source (since 0.1.0)
@type result() :: success() | error()
Link to this type

success()

View Source (since 0.1.0)
@type success() :: {:ok, OpenFeature.ResolutionDetails.t()}
@type t() :: struct()

Callbacks

Link to this callback

initialize(provider, domain, context)

View Source (since 0.1.0)
@callback initialize(
  provider :: t(),
  domain :: binary(),
  context :: OpenFeature.Types.context()
) ::
  {:ok, t()} | {:error, OpenFeature.Types.error_code()}

Initializes the provider with the domain and context, and sets the provider's state to :ready.

Link to this callback

resolve_boolean_value(provider, key, default, context)

View Source (since 0.1.0)
@callback resolve_boolean_value(
  provider :: t(),
  key :: binary(),
  default :: boolean(),
  context :: OpenFeature.Types.context()
) :: result()

Resolves the boolean value of a flag based on the key, default value, and context.

Link to this callback

resolve_map_value(provider, key, default, context)

View Source (since 0.1.0)
@callback resolve_map_value(
  provider :: t(),
  key :: binary(),
  default :: map(),
  context :: OpenFeature.Types.context()
) :: result()

Resolves the map value of a flag based on the key, default value, and context.

Link to this callback

resolve_number_value(provider, key, default, context)

View Source (since 0.1.0)
@callback resolve_number_value(
  provider :: t(),
  key :: binary(),
  default :: number(),
  context :: OpenFeature.Types.context()
) :: result()

Resolves the number value of a flag based on the key, default value, and context.

Link to this callback

resolve_string_value(provider, key, default, context)

View Source (since 0.1.0)
@callback resolve_string_value(
  provider :: t(),
  key :: binary(),
  default :: binary(),
  context :: OpenFeature.Types.context()
) :: result()

Resolves the string value of a flag based on the key, default value, and context.

Link to this callback

shutdown(provider)

View Source (since 0.1.0)
@callback shutdown(provider :: t()) :: :ok

Shuts down the provider and cleans up any resources.

Functions

Link to this function

equal?(provider1, provider2)

View Source (since 0.1.0)
@spec equal?(t(), t()) :: boolean()

Checks if two providers are equal based on their name, domain, and state.

Link to this function

initialize(domain, provider, context)

View Source (since 0.1.0)
@spec initialize(
  domain :: binary(),
  provider :: t(),
  context :: OpenFeature.Types.context()
) ::
  {:ok, t()} | {:error, any()}

Initializes the provider and emits the :ready event if successful. If an error occurs, emits the :error event.

Link to this function

resolve_value(provider, atom, key, default, context)

View Source (since 0.1.0)

Resolves the value of a flag based on the key, default value, and context.

Link to this function

shutdown(provider)

View Source (since 0.1.0)
@spec shutdown(t()) :: :ok

Shuts down the provider and catches any errors that may occur.

Link to this function

validate_provider(provider)

View Source (since 0.1.0)
@spec validate_provider(t()) :: {:ok, t()} | {:error, :invalid_provider}

Validates if the provider implements the required functions.