pub trait Module:
Send
+ Sync
+ 'static {
Show 15 methods
// Required methods
fn name(&self) -> &'static str;
fn version(&self) -> &'static str;
fn requires(&self) -> &'static [Port];
fn migrations(&self) -> Migrations;
fn validate_config(&self, cfg: &dyn Config) -> Result<(), ConfigError>;
fn router(&self, ctx: ModuleContext) -> Router;
// Provided methods
fn harness_api(&self) -> u32 { ... }
fn optional(&self) -> &'static [Port] { ... }
fn tables(&self) -> &'static [&'static str] { ... }
fn emits(&self) -> &'static [&'static str] { ... }
fn public_writes(&self) -> bool { ... }
fn well_known(&self) -> Option<Router> { ... }
fn surface(&self) -> Surface { ... }
fn events(&self) -> Vec<(EventName, EventHandler)> { ... }
fn scheduled<'a>(
&'a self,
ctx: &'a ModuleContext,
cron: &'a str,
) -> BoxFuture<'a, Result<(), AnyError>> { ... }
}Expand description
A Factory Zero module. Object-safe; composed as Arc<dyn Module>.
Handlers get the request scope as an axum extractor:
async fn join(scope: Scope, State(ctx): State<Arc<ModuleContext>>, ...).
There is no ambient “current request” (ADR 0007).
Required Methods§
Sourcefn requires(&self) -> &'static [Port]
fn requires(&self) -> &'static [Port]
Ports the module cannot run without; missing = build error.
Sourcefn migrations(&self) -> Migrations
fn migrations(&self) -> Migrations
The module’s migrations, embedded per dialect.
Sourcefn validate_config(&self, cfg: &dyn Config) -> Result<(), ConfigError>
fn validate_config(&self, cfg: &dyn Config) -> Result<(), ConfigError>
Rejects invalid configuration: missing required keys or malformed values, reported together with the module name.
When it runs. The conformance kit calls it, and a module’s own
tests should. It cannot run at Harness::build or in fz doctor,
because neither has the deploy config — the values live on the runtime
Env and only exist per request. The Cloudflare runtime therefore runs
it once at cold start and logs any failure loudly (console_error!,
so it reaches Workers Logs); it does not fail the boot, so a
misconfigured module still degrades per request (issue #101) rather
than taking the whole Worker down. Turning that into a hard boot
failure is a deployment decision for an ADR.
§Errors
Err listing every invalid or missing key for this module.
Sourcefn router(&self, ctx: ModuleContext) -> Router
fn router(&self, ctx: ModuleContext) -> Router
The module’s router, nested under /v1/<name>.
Provided Methods§
Sourcefn harness_api(&self) -> u32
fn harness_api(&self) -> u32
Contract version, checked by Harness::build.
Sourcefn tables(&self) -> &'static [&'static str]
fn tables(&self) -> &'static [&'static str]
Table names this module owns; duplicates across modules are a build error.
Sourcefn emits(&self) -> &'static [&'static str]
fn emits(&self) -> &'static [&'static str]
Event names this module emits ("<module>.<event>"), listed by
/__health.
Sourcefn public_writes(&self) -> bool
fn public_writes(&self) -> bool
Whether the module has public write endpoints; drives the production-captcha rule (section 11).
Sourcefn well_known(&self) -> Option<Router>
fn well_known(&self) -> Option<Router>
Routes this module serves at the root under /.well-known, for
spec-mandated discovery documents (OIDC openid-configuration,
jwks.json) that must live outside /v1 (issue #46). Paths are
relative to the prefix: register /jwks.json, not
/.well-known/jwks.json.
At most one module may provide one: discovery URLs are a singleton
namespace, so Harness::build fails (naming every provider) when
two modules return a router here. None by default.
Sourcefn surface(&self) -> Surface
fn surface(&self) -> Surface
The module’s UI surface (ADR 0010): the actions a renderer may
offer and the views that compose them. Input schemas come from
the handler’s own body types (Action::input::<Body>()), so the
declaration cannot drift from the route. Harness::build
validates it; GET /__surface serves the composition. Default:
nothing, and a module that declares nothing renders nothing.
Sourcefn events(&self) -> Vec<(EventName, EventHandler)>
fn events(&self) -> Vec<(EventName, EventHandler)>
Handlers for events other modules emit; registered at
Harness::build.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".