Skip to main content

ForgeBuilder

Struct ForgeBuilder 

Source
pub struct ForgeBuilder { /* private fields */ }
Expand description

Builder for configuring the FORGE runtime.

Implementations§

Source§

impl ForgeBuilder

Source

pub fn new() -> Self

Source

pub fn migrations_dir(self, path: impl Into<PathBuf>) -> Self

Set the directory to load migrations from.

Defaults to ./migrations. Migration files should be named like:

  • 0001_create_users.sql
  • 0002_add_posts.sql
Source

pub fn migration(self, name: impl Into<String>, sql: impl Into<String>) -> Self

Add a migration programmatically.

Use this for migrations that need to be generated at runtime, or for testing. For most cases, use migration files instead.

Source

pub fn frontend_handler( self, handler: fn(Request<Body>) -> Pin<Box<dyn Future<Output = Response> + Send>>, ) -> Self

Set a frontend handler for serving embedded SPA assets.

Use with the embedded-frontend feature to build a single binary that includes both backend and frontend.

Source

pub fn with_role_resolver(self, resolver: SharedRoleResolver) -> Self

Plug in a custom role resolver for RBAC extension.

The default resolver returns the flat roles JWT claim as-is. Use this to expand roles hierarchically, perform group-membership lookups, or consult an external permission service.

The resolver is called for every request that carries a require_role constraint. Keep it cheap — cache remote lookups internally.

Source

pub fn custom_routes<F>(self, f: F) -> Self
where F: FnOnce(PgPool) -> Router + Send + Sync + 'static,

Register custom axum routes built from Forge’s managed pool.

The factory runs once during run(), after the database pool is connected. The returned router is merged into the gateway’s /_api namespace, so every route receives the full middleware stack: auth (JWT), CORS, tracing, concurrency limits, and timeouts.

Route paths are relative to /_api. Registering /export/csv exposes GET /_api/export/csv. Avoid paths that collide with built-ins under /_api: /health, /ready, /rpc, /rpc/*, /events, /subscribe, /unsubscribe, /subscribe-job, /subscribe-workflow, /signal/*, /mcp, and /oauth/*.

The factory receives the framework’s sqlx::PgPool. Cloning it is cheap (PgPool is internally an Arc).

If your handlers don’t need the pool, ignore the argument:

builder.custom_routes(|_| Router::new().route("/healthz", get(|| async { "ok" })));

With pool access:

use axum::{Router, routing::get};

builder.custom_routes(|pool| {
    Router::new()
        .route("/export/csv", get(export_handler))
        .with_state(pool)
});
Source

pub fn auto_register(self) -> Self

Automatically register all functions discovered via #[forge::query], #[forge::mutation], #[forge::job], #[forge::cron], #[forge::workflow], #[forge::daemon], #[forge::webhook], and #[forge::mcp_tool] macros.

This replaces the need to manually call .register_query::<T>() etc. for every function in your application.

Source

pub fn config(self, config: ForgeConfig) -> Self

Source

pub fn function_registry_mut(&mut self) -> &mut FunctionRegistry

Source

pub fn job_registry_mut(&mut self) -> &mut JobRegistry

Source

pub fn mcp_registry_mut(&mut self) -> &mut McpToolRegistry

Source

pub fn register_mcp_tool<T: ForgeMcpTool>(self) -> Self

Source

pub fn cron_registry_mut(&mut self) -> &mut CronRegistry

Source

pub fn workflow_registry_mut(&mut self) -> &mut WorkflowRegistry

Source

pub fn daemon_registry_mut(&mut self) -> &mut DaemonRegistry

Source

pub fn webhook_registry_mut(&mut self) -> &mut WebhookRegistry

Source

pub fn register_query<Q: ForgeQuery>(self) -> Self
where Q::Args: DeserializeOwned + Send + 'static, Q::Output: Serialize + Send + 'static,

Source

pub fn register_mutation<M: ForgeMutation>(self) -> Self
where M::Args: DeserializeOwned + Send + 'static, M::Output: Serialize + Send + 'static,

Source

pub fn register_job<J: ForgeJob>(self) -> Self
where J::Args: DeserializeOwned + Send + 'static, J::Output: Serialize + Send + 'static,

Source

pub fn register_cron<C: ForgeCron>(self) -> Self

Source

pub fn register_workflow<W: ForgeWorkflow>(self) -> Self

Source

pub fn register_daemon<D: ForgeDaemon>(self) -> Self

Source

pub fn register_webhook<W: ForgeWebhook>(self) -> Self

Source

pub fn build(self) -> Result<Forge>

Trait Implementations§

Source§

impl Default for ForgeBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,