Bloccs.Effects (bloccs v0.2.0)

Copy Markdown View Source

Declared effect capabilities materialized at runtime.

Each node's [effects] block becomes a %Bloccs.Effects.Capabilities{} struct injected into the per-message context. The struct's fields refuse out-of-scope calls — that's the runtime half of the "declared capabilities" guarantee. The compile-time half lives in Bloccs.Node (AST warning).

Mock backends are the default (tests stay hermetic); real HTTP (Bloccs.Effects.HTTP.Req) and DB (Bloccs.Effects.DB.Ecto) adapters are opt-in via config, with :req / Ecto as optional deps. See Bloccs.Effects.HTTP and Bloccs.Effects.DB for the behaviours.

Summary

Functions

Build a capability struct from a parsed node manifest.

Raise Bloccs.Effects.Denied with a useful message.

Functions

bind(node, opts \\ [])

Build a capability struct from a parsed node manifest.

The backend module for each axis is resolved by layering, lowest precedence first:

  1. Built-in defaults — mock HTTP/DB, real wall-clock/RNG. Safe for tests.
  2. App configconfig :bloccs, :effect_backends, http: ..., db: .... This is how production selects the real adapters (HTTP.Req, DB.Ecto) without touching node source.
  3. Per-call :backends — a keyword override, mainly for tests that want a specific backend inline.

Backend-specific configuration (e.g. the Ecto repo) is read by the backend itself from its own config key — see each adapter's docs.

deny!(axis, detail)

@spec deny!(atom(), String.t()) :: no_return()

Raise Bloccs.Effects.Denied with a useful message.