OpenFeature.Provider behaviour (OpenFeature v0.1.3)

View Source

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 module and name.

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

error()

(since 0.1.0)
@type error() ::
  {:error, :flag_not_found}
  | {:error, :variant_not_found, binary() | nil}
  | {:error, :unexpected_error, Exception.t()}

result()

(since 0.1.0)
@type result() :: success() | error()

success()

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

t()

(since 0.1.0)
@type t() :: struct()

Callbacks

initialize(provider, domain, context)

(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.

resolve_boolean_value(provider, key, default, context)

(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.

resolve_map_value(provider, key, default, context)

(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.

resolve_number_value(provider, key, default, context)

(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.

resolve_string_value(provider, key, default, context)

(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.

shutdown(provider)

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

Shuts down the provider and cleans up any resources.

Functions

equal?(provider1, provider2)

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

Checks if two providers are equal based on their module and name.

initialize(domain, provider, context)

(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.

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

(since 0.1.0)

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

shutdown(provider)

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

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

validate_provider(provider)

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

Validates if the provider implements the required functions.