larust-support 0.9.0

A Laravel-shaped web framework for Rust.
Documentation
//! Laravel-style top-level helpers. Sits above `larust-core`/`larust-http`
//! rather than below them - this is the "batteries-included facade" layer,
//! analogous to Laravel's `helpers.php`. `Collection<T>` lands later.

mod abort;
pub mod config_env;
mod config_helper;
pub mod date;
mod html;
mod loop_iter;
mod redirect;
pub mod regex_replace;
pub mod strings;
pub mod truthy;
mod url_helper;
pub mod vitex;

pub use abort::abort;
pub use config_helper::config;
pub use html::sanitize_rich_text;
pub use loop_iter::{Loop, WithLoop};
pub use redirect::{redirect, route, route_with, Redirect, RedirectBuilder};
pub use url_helper::{asset, url};

/// `#[derive(FormRequest)]`, `view!`, `error_view!`, and `#[derive(Model)]` -
/// re-exported here so generated apps depend only on `larust-support`, not
/// on `larust-macros` directly. All four macros' generated code assumes
/// this re-export path (`::larust_support::...`).
pub use larust_macros::{error_view, view, FormRequest, Model};

/// Re-exported (not just used internally) so macro-generated code can
/// reference `::larust_support::axum::...`/`::larust_support::AppError`
/// instead of `::larust_core::...` - a crate depending on `larust-support`
/// alone must not need `larust-core` as a *direct* dependency just to use
/// a macro. Keep every path in `larust-macros`' generated code routed
/// through `larust_support` for the same reason. `default_not_found_html`/
/// `default_internal_html` are `error_view!`'s own fallback when no
/// `resources/views/errors/{code}.blade.xr` override exists.
pub use larust_core::{axum, default_internal_html, default_not_found_html, AppError};

/// Re-exported so app code can log (e.g. a best-effort failure, matching
/// `Redirect::with`'s own pattern) without adding `tracing` as a direct
/// dependency - the same "one dependency surface" reasoning as `axum`
/// above.
pub use tracing;

/// Re-exported for the same "one dependency surface" reason as `axum`/
/// `tracing` above - `view!`'s `@wire(...)` codegen arm references
/// `::larust_support::serde_json::{Value, to_value}` directly in generated
/// code, so an app using `@wire(...)` doesn't need `serde_json` as a direct
/// dependency of its own just to compile that macro expansion.
pub use serde_json;

pub mod validation {
    pub use larust_validation::{form_urlencoded, rules, ValidationErrors};
}

pub mod view {
    pub use larust_view::{escape, js, View};
}

/// Runtime home for `@push`/`@stack` content that needs to cross a boundary
/// compile-time `view!(...)` resolution can't see across (a `<wire:...>`
/// mount, or two `view!(...)` calls glued by `.into_html()`) - see
/// `larust_view::push_registry`'s own doc comment for the full design.
/// Reached by generated codegen the same way `larust_support::wire::mount`/
/// `larust_support::view::escape` already are.
pub mod push_registry {
    pub use larust_view::push_registry::{drain, drain_since, mark, record, with_scope};
}

pub mod orm {
    pub use larust_orm::{
        backend, connect, migrate, migrate_fresh, placeholder, pool, sqlx, table_names,
        AnyRepository, Backend, BindValue, ConnectionConfig, DatabaseConnections, Driver, Factory,
        FactoryBuilder, Model, Op, Order, QueryBuilder, SoftDeletes,
    };
}

/// The non-SQL half of Larust's persistence story - see
/// `larust_repository::Repository`'s own doc comment for the full design
/// (storage-agnostic CRUD, implemented automatically for `#[derive(Model)]`
/// structs via `orm::AnyRepository<T>`, by hand for anything else).
pub mod repository {
    pub use larust_repository::Repository;
}

pub mod auth {
    pub use larust_auth::{
        authorize, check, check_for, hash_password, id, id_for, login, logout, logout_for,
        redirect_authenticated, redirect_authenticated_for, require_auth, require_auth_for, user,
        verify_password, Auth, Authenticatable, Policy,
    };
}

pub mod mail {
    pub use larust_mail::{mail, MailBuilder, MailJob, Mailable};
}

/// Backs `@globals`' `persist` entries - see `larust_http::preferences`'
/// own doc comment for the full design (a dedicated, unsigned,
/// long-lived cookie, deliberately not `Session`-backed).
pub mod preferences {
    pub use larust_http::preferences::{get, CookieJar};
}

pub mod notification {
    pub use larust_notifications::{
        clear_notifications, delete_notification, mark_all_as_read, mark_as_read,
        notifications_for, notify, notify_and_mail, to, unread_count, MailNotifiable,
        MailNotification, Notification, PendingNotification, StoredNotification,
    };
}

/// Umbrella namespace for subscription billing (`laravel/cashier`) - one
/// submodule per payment provider backend, each gated behind its own
/// independently-selectable feature (`cashier-stripe` today; a future
/// `cashier-paypal`/`cashier-square` gets its own `paypal`/`square`
/// submodule the same way) rather than one shared trait every provider
/// implements - see `larust-cashier-stripe`'s own doc comment for why a
/// shared interface would be either leaky or lowest-common-denominator
/// thin across providers whose own object models don't actually agree.
/// An app can enable more than one backend at once; nothing here forces a
/// choice between them.
pub mod cashier {
    /// See [`permission`]'s own doc comment for why this (and every
    /// backend submodule here) is opt-in. No `Billable` trait the way
    /// real Cashier mixes into its `User` model - see
    /// `larust-cashier-stripe`'s own doc comment for the full design.
    #[cfg(feature = "cashier-stripe")]
    pub mod stripe {
        pub use larust_cashier_stripe::{
            cancel_subscription, checkout_url, create_customer, customer_for, handle_webhook,
            resume_subscription, subscribed, subscription_for, swap_subscription, CashierError,
            Subscription, WebhookEvent,
        };
    }
}

/// Gated behind the `db` feature - see [`permission`]'s own doc comment
/// for why. `db` stands in for no particular Laravel package (there isn't
/// one) - it's an optional, additive facade over `larust-db`'s embedded
/// pure-Rust key-value store, alongside the SQL database rather than
/// replacing it (named `db`, not `kv`, purely for wizard/CLI
/// discoverability - see `larust-db`'s own doc comment). See that crate's
/// own doc comment for the full design and the `#[derive(Model)]`/
/// relations trade-off that keeps this from being a second database
/// backend.
#[cfg(feature = "db")]
pub mod db {
    pub use larust_db::{
        connect, forget, get, get_raw, keys, parse_cli_value, put, put_raw, DbPlugin,
    };
}

/// Not feature-gated, unlike [`cashier`]/[`db`]/[`permission`]/etc. above:
/// `<Image ...>` is core template-directive surface, the same tier as
/// [`wire`]/[`spa`] (see [`spa`]'s own doc comment for the identical
/// reasoning). Backs `larust-view`'s own `<Image src="..." width="..."
/// height="..." />` tag - see `larust-image`'s own doc comment for the
/// full design (on-demand resize + AVIF/JPEG re-encoding, local images
/// only).
pub mod image {
    pub use larust_image::{
        build_srcset, optimized_url, tag, ImageOptions, ImagePlugin, Loading, Placeholder,
        DEFAULT_QUALITY,
    };
}

/// Gated behind the `passport` feature - see [`permission`]'s own doc
/// comment for why. A full OAuth2 authorization server (`laravel/
/// passport`) - client registration, the Authorization Code grant with
/// mandatory PKCE, Client Credentials, and Refresh Token rotation; see
/// `larust-passport`'s own doc comment for the full design, including
/// the three ways it's deliberately narrower than real Passport (one
/// redirect URI per client, no bespoke `xr` client-registration
/// subcommand, no scopes UI/consent-screen rendering - your own
/// `/oauth/authorize` route owns that).
#[cfg(feature = "passport")]
pub mod passport {
    pub use larust_passport::{
        create_authorization_code, create_client, exchange_token, has_scope, require_scope,
        revoke_access_token, revoke_refresh_token, AuthorizeRequest, NewClient, OAuthAuth,
        OAuthClientAuth, OAuthError, PkceMethod, TokenRequest, TokenResponse,
    };
}

/// Gated behind the `pennant` feature - see [`permission`]'s own doc
/// comment for why. Boolean-only, scope-aware feature flags
/// (`laravel/pennant`) - persisted via this crate's own `feature_flags`
/// table, no process-wide resolver registry; see `larust-pennant`'s own
/// doc comment for the full design, including why `active`'s `default`
/// is a plain argument rather than something registered once elsewhere.
#[cfg(feature = "pennant")]
pub mod pennant {
    pub use larust_pennant::{activate, active, deactivate, forget, purge};
}

/// Gated behind the `permissions` feature - see `larust-support`'s own
/// `Cargo.toml` doc comment (if any) or `docs/ARCHITECTURE.md` for why
/// this and its three siblings below are opt-in rather than always
/// compiled in: each stands in for a genuinely optional third-party
/// Laravel package (`spatie/laravel-permission`), not core framework
/// surface, so an app that never uses it shouldn't pay to compile it.
#[cfg(feature = "permissions")]
pub mod permission {
    pub use larust_permissions::{
        assign_role, authorize_admin, authorize_permission, create_permission, create_role,
        give_permission_to, grant_role_permission, has_permission_to, has_role, is_admin,
        remove_role, AdminRole, PermissionName, RoleName,
    };
}

/// Gated behind the `reverb` feature - see [`permission`]'s own doc
/// comment for why.
#[cfg(feature = "reverb")]
pub mod reverb {
    pub use larust_reverb::{authorize, broadcast_event, runtime_js, socket, ReverbPlugin};
}

/// Gated behind the `sanctum` feature - see [`permission`]'s own doc
/// comment for why.
#[cfg(feature = "sanctum")]
pub mod sanctum {
    pub use larust_sanctum::{create_token, revoke_all_tokens_for, revoke_token, ApiAuth};
}

/// Gated behind the `scout` feature - see [`permission`]'s own doc
/// comment for why. Full-text search (`laravel/scout`), Meilisearch
/// only - see `larust-scout`'s own doc comment for the full design,
/// including why there's no `Searchable` trait/automatic model-lifecycle
/// indexing the way real Scout has.
#[cfg(feature = "scout")]
pub mod scout {
    pub use larust_scout::{index, remove, search, SearchResults};
}

/// Gated behind the `shield` feature (which implies `permissions` - see
/// that feature's own `Cargo.toml` comment) - a lighter-weight,
/// `bezhansalleh/filament-shield`-inspired resource/ability layer on top
/// of [`permission`], not a stand-in for a Laravel package (there isn't
/// one). See `larust-shield`'s own doc comment for the full design and
/// what's deliberately out of scope.
#[cfg(feature = "shield")]
pub mod shield {
    pub use larust_shield::{
        authorize_ability, can, create_resource_permissions, grant_resource_abilities, Ability,
        ResourceName, ResourcePermission, ALL_ABILITIES,
    };
}

/// Gated behind the `sitemap` feature - see [`permission`]'s own doc
/// comment for why.
#[cfg(feature = "sitemap")]
pub mod sitemap {
    pub use larust_sitemap::{build_xml, from_static_routes, response, ChangeFreq, SitemapEntry};
}

/// Gated behind the `socialite` feature - see [`permission`]'s own doc
/// comment for why.
#[cfg(feature = "socialite")]
pub mod socialite {
    pub use larust_socialite::{
        github, google, redirect_url, user_from_callback, OAuthProvider, ProviderUser,
        SocialiteUser,
    };
}

pub mod cache {
    pub use larust_cache::{forget, get, put, remember};
}

pub mod console {
    pub use larust_console::{Command, CommandInfo, CommandRegistry};
}

pub mod event {
    pub use larust_events::{dispatch, listeners, Event, ListenerRegistry};
}

/// Not feature-gated - see [`spa`]'s own doc comment for the same
/// reasoning: `__()`/`trans()` are core Laravel functionality, not a
/// stand-in for a specific optional third-party package the way
/// `permission`/`sanctum`/etc. are. `larust_http::locale::negotiate` (the
/// session-reading half of this) lives with the other opt-in HTTP
/// middleware instead of being re-exported here, matching `csrf::verify`/
/// `require_auth`'s own precedent of being attached via `.middleware(...)`
/// directly rather than through the facade.
pub mod lang {
    pub use larust_lang::{current_locale, set_current_locale, t, t_or, t_or_with, t_with};
}

pub mod queue {
    pub use larust_queue::{dispatch, work, Job, JobRegistry};
}

pub mod schedule {
    pub use larust_scheduler::{work, Schedule};
}

pub mod storage {
    pub use larust_storage::{
        local, local_at, public, public_at, Disk, DiskConfig, FilesystemConfig,
    };
}

pub mod wire {
    pub use larust_live::{
        components, mount, runtime_js, update, LiveRegistry, WireComponent, WirePlugin,
    };
}

pub mod push {
    pub use larust_live::push::{broadcast, runtime_js, socket, wrap, PushPlugin};
}

/// Not feature-gated, unlike [`permission`]/`reverb`/`sanctum`/`sitemap`/
/// `socialite` above - `@spa` is core template-directive surface (the same
/// tier as [`wire`]/[`push`]), not a stand-in for an optional third-party
/// Laravel package an app opts into compiling.
pub mod spa {
    pub use larust_spa::{runtime_js, SpaPlugin};
}