Ferricstore.Commands.Extension behaviour (ferricstore v0.7.0)

Copy Markdown View Source

Behaviour and registry helpers for optional command providers.

A provider is configured with:

config :ferricstore, :command_extensions, [MyApp.Commands]

Providers declare command metadata with commands/0 and execute commands with handle/3. The core dispatcher uses this metadata for routing and key ACL extraction, while leaving command semantics in the provider module.

Summary

Functions

Builds the dispatcher AST for a configured command.

Returns true when a configured provider owns the command.

Returns the key access type for a configured command.

Returns configured command names in uppercase form.

Returns normalized command metadata from all configured providers.

Dispatches a configured command to its provider module.

Extracts key arguments for a configured command.

Looks up configured command metadata by command name.

Looks up configured command metadata by an already-uppercase command name.

Returns configured provider modules.

Returns the access type for a non-shadowing configured command.

Returns uppercase configured command names excluding built-in shadows.

Returns configured command metadata excluding names already owned by built-in commands.

Returns trusted request context attached by the server protocol layer.

Types

access()

@type access() :: :read | :write | :rw

command_entry()

@type command_entry() :: %{
  :name => binary(),
  optional(:arity) => integer(),
  optional(:flags) => [binary()],
  optional(:first_key) => integer(),
  optional(:last_key) => integer(),
  optional(:step) => integer(),
  optional(:access) => access(),
  optional(:summary) => binary()
}

Callbacks

commands()

@callback commands() :: [command_entry()]

handle(binary, list, map)

@callback handle(binary(), [binary()], map()) :: term()

keys(binary, list)

(optional)
@callback keys(binary(), [binary()]) :: {:ok, [binary()]} | :error

Functions

ast(command, args)

@spec ast(binary(), [binary()]) :: {:extension_command, binary(), [binary()]}

Builds the dispatcher AST for a configured command.

command?(command)

@spec command?(binary()) :: boolean()

Returns true when a configured provider owns the command.

command_access_type(command)

@spec command_access_type(binary()) :: access() | nil

Returns the key access type for a configured command.

command_names_upper()

@spec command_names_upper() :: MapSet.t(binary())

Returns configured command names in uppercase form.

commands()

@spec commands() :: [map()]

Returns normalized command metadata from all configured providers.

handle(command, args, store)

@spec handle(binary(), [binary()], map()) :: term() | :not_found

Dispatches a configured command to its provider module.

keys(command, args)

@spec keys(binary(), [binary()]) :: {:ok, [binary()]} | :error

Extracts key arguments for a configured command.

lookup(command)

@spec lookup(binary()) :: {:ok, map()} | :error

Looks up configured command metadata by command name.

lookup_upper(command)

@spec lookup_upper(binary()) :: {:ok, map()} | :error

Looks up configured command metadata by an already-uppercase command name.

modules()

@spec modules() :: [module()]

Returns configured provider modules.

non_shadowing_command_access_type(command)

@spec non_shadowing_command_access_type(binary()) :: access() | nil

Returns the access type for a non-shadowing configured command.

non_shadowing_command_names_upper()

@spec non_shadowing_command_names_upper() :: MapSet.t(binary())

Returns uppercase configured command names excluding built-in shadows.

non_shadowing_commands()

@spec non_shadowing_commands() :: [map()]

Returns configured command metadata excluding names already owned by built-in commands.

request_context(store)

@spec request_context(map()) :: map()

Returns trusted request context attached by the server protocol layer.

Extension providers can use this to read authenticated subject, tenant, and scope data without parsing command arguments as authority.