Featurevisor (featurevisor v2.1.0)

Copy Markdown View Source

Feature flags, experiments, and remote configuration for Elixir.

Create an isolated instance with create_featurevisor/1, then evaluate flags, variations, and variables against a Featurevisor schema version 4 or legacy schema version 2 datafile.

Summary

Functions

Registers an SDK module. Returns an idempotent removal function or nil.

Applies variable mutation operations to a value, as datafile overrides do, for packages that change their entries by the same notation. Raises ArgumentError for an operation the interpreter refuses.

Closes modules, subscriptions, listeners, caches, and the instance owner.

Creates an isolated Featurevisor instance.

Evaluates a feature flag and returns details.

Returns stored context merged with optional evaluation context.

Returns a feature definition.

Returns all feature keys. Ordering is not guaranteed.

Returns a global variable value or nil. JSON variables are decoded.

Returns all global variable keys. Ordering is not guaranteed.

Returns a typed number global variable, whole or fractional.

Returns the current datafile revision.

Returns the informational datafile schema version.

Returns a segment definition.

Returns a variable value or nil. JSON variables are decoded.

Returns a list variable after runtime type checking.

Returns a boolean variable after runtime type checking.

Returns an integer variable after runtime type checking.

Returns variable keys for a feature.

Returns a finite number variable, whole or fractional, after runtime type checking.

Returns a map variable after runtime type checking.

Returns a string variable after runtime type checking.

Whether a module with the supplied name is registered, as a package that registers under its own name checks before adding a second.

Returns whether a feature defines variations.

Returns a Featurevisor handle for a running owner process or registered name.

Subscribes to an event and returns an idempotent unsubscribe function.

Milliseconds since the epoch of a portable timestamp, as before and after read one, such as 2026-01-31T09:00:00Z, or nil for a value that is not one.

Removes every module with the supplied name.

Merges or replaces the stored context.

Merges or replaces the stored datafile.

Changes the diagnostic threshold.

Merges or replaces sticky feature evaluations.

Merges or replaces sticky global variable values.

Spawns a child instance with isolated context and sticky state.

Starts a supervised Featurevisor owner process.

Whether a value is a version the semver operators accept.

Types

options()

@type options() :: %{
  optional(:datafile) => map() | String.t(),
  optional(:context) => map(),
  optional(:log_level) => Featurevisor.Diagnostic.level(),
  optional(:on_diagnostic) => (Featurevisor.Diagnostic.t() -> any()),
  optional(:sticky_features) => map(),
  optional(:sticky_variables) => map(),
  optional(:modules) => [Featurevisor.Module.t()],
  optional(:name) => GenServer.name()
}

t()

@opaque t()

Functions

add_module(instance, original)

Registers an SDK module. Returns an idempotent removal function or nil.

apply_variable_operations(value, operations)

@spec apply_variable_operations(term(), [map()]) :: term()

Applies variable mutation operations to a value, as datafile overrides do, for packages that change their entries by the same notation. Raises ArgumentError for an operation the interpreter refuses.

close(instance)

Closes modules, subscriptions, listeners, caches, and the instance owner.

create_featurevisor(options \\ %{})

@spec create_featurevisor(options() | keyword()) :: t()

Creates an isolated Featurevisor instance.

enabled?(instance, feature_key, context \\ %{}, options \\ %{})

Returns whether a feature is enabled.

evaluate_flag(instance, feature_key, context \\ %{}, options \\ %{})

Evaluates a feature flag and returns details.

evaluate_global_variable(instance, variable_key, context \\ %{}, options \\ %{})

Evaluates a global variable and returns details.

evaluate_variable(instance, feature_key, variable_key, context \\ %{}, options \\ %{})

Evaluates a variable and returns details.

evaluate_variation(instance, feature_key, context \\ %{}, options \\ %{})

Evaluates a variation and returns details.

get_context(instance, context \\ %{})

Returns stored context merged with optional evaluation context.

get_feature(instance, key)

Returns a feature definition.

get_feature_evaluations(instance, context \\ %{}, feature_keys \\ [], options \\ %{})

Evaluates all or selected features.

get_feature_keys(instance)

Returns all feature keys. Ordering is not guaranteed.

get_global_variable(instance, variable_key, context \\ %{}, options \\ %{})

Returns a global variable value or nil. JSON variables are decoded.

get_global_variable_array(instance, key, context \\ %{}, options \\ %{})

Returns a typed list global variable.

get_global_variable_boolean(instance, key, context \\ %{}, options \\ %{})

Returns a typed boolean global variable.

get_global_variable_evaluations(instance, context \\ %{}, variable_keys \\ [], options \\ %{})

Evaluates all or selected global variables.

get_global_variable_integer(instance, key, context \\ %{}, options \\ %{})

Returns a typed integer global variable.

get_global_variable_json(instance, key, context \\ %{}, options \\ %{})

Returns a decoded JSON global variable.

get_global_variable_keys(instance)

Returns all global variable keys. Ordering is not guaranteed.

get_global_variable_number(instance, key, context \\ %{}, options \\ %{})

Returns a typed number global variable, whole or fractional.

get_global_variable_object(instance, key, context \\ %{}, options \\ %{})

Returns a typed map global variable.

get_global_variable_string(instance, key, context \\ %{}, options \\ %{})

Returns a typed string global variable.

get_revision(instance)

Returns the current datafile revision.

get_schema_version(instance)

Returns the informational datafile schema version.

get_segment(instance, key)

Returns a segment definition.

get_variable(instance, feature_key, variable_key, context \\ %{}, options \\ %{})

Returns a variable value or nil. JSON variables are decoded.

get_variable_array(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a list variable after runtime type checking.

get_variable_boolean(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a boolean variable after runtime type checking.

get_variable_integer(instance, feature, variable, context \\ %{}, options \\ %{})

Returns an integer variable after runtime type checking.

get_variable_json(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a decoded JSON variable.

get_variable_keys(instance, key)

Returns variable keys for a feature.

get_variable_number(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a finite number variable, whole or fractional, after runtime type checking.

get_variable_object(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a map variable after runtime type checking.

get_variable_string(instance, feature, variable, context \\ %{}, options \\ %{})

Returns a string variable after runtime type checking.

get_variation(instance, feature_key, context \\ %{}, options \\ %{})

Returns a variation value or nil.

has_module?(instance, name)

@spec has_module?(t(), String.t()) :: boolean()

Whether a module with the supplied name is registered, as a package that registers under its own name checks before adding a second.

has_variations?(instance, key)

Returns whether a feature defines variations.

instance(server)

@spec instance(GenServer.server()) :: t()

Returns a Featurevisor handle for a running owner process or registered name.

on(instance, event, callback)

Subscribes to an event and returns an idempotent unsubscribe function.

portable_timestamp(value)

@spec portable_timestamp(term()) :: integer() | nil

Milliseconds since the epoch of a portable timestamp, as before and after read one, such as 2026-01-31T09:00:00Z, or nil for a value that is not one.

remove_module(instance, name)

Removes every module with the supplied name.

set_context(instance, context, replace \\ false)

Merges or replaces the stored context.

set_datafile(instance, input, replace \\ false)

@spec set_datafile(t(), map() | String.t(), boolean()) :: boolean()

Merges or replaces the stored datafile.

Returns true when accepted, including unchanged input, or false when rejected or closed.

set_log_level(instance, level)

Changes the diagnostic threshold.

set_sticky_features(instance, sticky, replace \\ false)

Merges or replaces sticky feature evaluations.

set_sticky_variables(instance, sticky, replace \\ false)

Merges or replaces sticky global variable values.

spawn(instance, context \\ %{}, options \\ %{})

Spawns a child instance with isolated context and sticky state.

start_link(options \\ %{})

@spec start_link(options() | keyword()) :: GenServer.on_start()

Starts a supervised Featurevisor owner process.

valid_version?(value)

@spec valid_version?(term()) :: boolean()

Whether a value is a version the semver operators accept.