Skip to main content

larust_support/
lib.rs

1//! Laravel-style top-level helpers. Sits above `larust-core`/`larust-http`
2//! rather than below them - this is the "batteries-included facade" layer,
3//! analogous to Laravel's `helpers.php`. `Collection<T>` lands later.
4
5mod abort;
6pub mod config_env;
7mod config_helper;
8pub mod date;
9mod html;
10mod loop_iter;
11pub mod maintenance;
12mod redirect;
13pub mod regex_replace;
14pub mod strings;
15pub mod truthy;
16mod url_helper;
17pub mod vitex;
18
19pub use abort::abort;
20pub use config_helper::config;
21pub use html::sanitize_rich_text;
22pub use loop_iter::{Loop, WithLoop};
23pub use redirect::{redirect, route, route_with, Redirect, RedirectBuilder};
24pub use url_helper::{asset, url};
25
26/// `#[derive(FormRequest)]`, `view!`, `error_view!`, and `#[derive(Model)]` -
27/// re-exported here so generated apps depend only on `larust-support`, not
28/// on `larust-macros` directly. All four macros' generated code assumes
29/// this re-export path (`::larust_support::...`).
30pub use larust_macros::{error_view, view, FormRequest, Model};
31
32/// Re-exported (not just used internally) so macro-generated code can
33/// reference `::larust_support::axum::...`/`::larust_support::AppError`
34/// instead of `::larust_core::...` - a crate depending on `larust-support`
35/// alone must not need `larust-core` as a *direct* dependency just to use
36/// a macro. Keep every path in `larust-macros`' generated code routed
37/// through `larust_support` for the same reason. `default_not_found_html`/
38/// `default_internal_html` are `error_view!`'s own fallback when no
39/// `resources/views/errors/{code}.blade.xr` override exists.
40pub use larust_core::{axum, default_internal_html, default_not_found_html, AppError};
41
42/// Re-exported so app code can log (e.g. a best-effort failure, matching
43/// `Redirect::with`'s own pattern) without adding `tracing` as a direct
44/// dependency - the same "one dependency surface" reasoning as `axum`
45/// above.
46pub use tracing;
47
48/// Re-exported for the same "one dependency surface" reason as `axum`/
49/// `tracing` above - `view!`'s `@wire(...)` codegen arm references
50/// `::larust_support::serde_json::{Value, to_value}` directly in generated
51/// code, so an app using `@wire(...)` doesn't need `serde_json` as a direct
52/// dependency of its own just to compile that macro expansion.
53pub use serde_json;
54
55pub mod validation {
56    pub use larust_validation::{form_urlencoded, rules, ValidationErrors};
57}
58
59pub mod view {
60    pub use larust_view::{escape, js, View};
61}
62
63/// Runtime home for `@push`/`@stack` content that needs to cross a boundary
64/// compile-time `view!(...)` resolution can't see across (a `<wire:...>`
65/// mount, or two `view!(...)` calls glued by `.into_html()`) - see
66/// `larust_view::push_registry`'s own doc comment for the full design.
67/// Reached by generated codegen the same way `larust_support::wire::mount`/
68/// `larust_support::view::escape` already are.
69pub mod push_registry {
70    pub use larust_view::push_registry::{drain, drain_since, mark, record, with_scope};
71}
72
73pub mod orm {
74    pub use larust_orm::{
75        backend, connect, migrate, migrate_fresh, placeholder, pool, read_pool, sqlx, table_names,
76        AnyRepository, Backend, BindValue, ConnectionConfig, DatabaseConnections, Driver, Factory,
77        FactoryBuilder, Model, Op, Order, QueryBuilder, SoftDeletes,
78    };
79}
80
81/// The non-SQL half of Larust's persistence story - see
82/// `larust_repository::Repository`'s own doc comment for the full design
83/// (storage-agnostic CRUD, implemented automatically for `#[derive(Model)]`
84/// structs via `orm::AnyRepository<T>`, by hand for anything else).
85pub mod repository {
86    pub use larust_repository::Repository;
87}
88
89pub mod auth {
90    pub use larust_auth::{
91        authorize, check, check_for, hash_password, id, id_for, login, logout, logout_for,
92        redirect_authenticated, redirect_authenticated_for, require_auth, require_auth_for, user,
93        verify_password, Auth, Authenticatable, Policy,
94    };
95}
96
97pub mod mail {
98    pub use larust_mail::{mail, MailBuilder, MailJob, Mailable};
99}
100
101/// Backs `@globals`' `persist` entries - see `larust_http::preferences`'
102/// own doc comment for the full design (a dedicated, unsigned,
103/// long-lived cookie, deliberately not `Session`-backed).
104pub mod preferences {
105    pub use larust_http::preferences::{get, CookieJar};
106}
107
108pub mod notification {
109    pub use larust_notifications::{
110        clear_notifications, delete_notification, mark_all_as_read, mark_as_read,
111        notifications_for, notify, notify_and_mail, to, unread_count, MailNotifiable,
112        MailNotification, Notification, PendingNotification, StoredNotification,
113    };
114}
115
116/// Umbrella namespace for subscription billing (`laravel/cashier`) - one
117/// submodule per payment provider backend, each gated behind its own
118/// independently-selectable feature (`cashier-stripe` today; a future
119/// `cashier-paypal`/`cashier-square` gets its own `paypal`/`square`
120/// submodule the same way) rather than one shared trait every provider
121/// implements - see `larust-cashier-stripe`'s own doc comment for why a
122/// shared interface would be either leaky or lowest-common-denominator
123/// thin across providers whose own object models don't actually agree.
124/// An app can enable more than one backend at once; nothing here forces a
125/// choice between them.
126pub mod cashier {
127    /// See [`permission`]'s own doc comment for why this (and every
128    /// backend submodule here) is opt-in. No `Billable` trait the way
129    /// real Cashier mixes into its `User` model - see
130    /// `larust-cashier-stripe`'s own doc comment for the full design.
131    #[cfg(feature = "cashier-stripe")]
132    pub mod stripe {
133        pub use larust_cashier_stripe::{
134            cancel_subscription, checkout_url, create_customer, customer_for, handle_webhook,
135            resume_subscription, subscribed, subscription_for, swap_subscription, CashierError,
136            Subscription, WebhookEvent,
137        };
138    }
139}
140
141/// Gated behind the `db` feature - see [`permission`]'s own doc comment
142/// for why. `db` stands in for no particular Laravel package (there isn't
143/// one) - it's an optional, additive facade over `larust-db`'s embedded
144/// pure-Rust key-value store, alongside the SQL database rather than
145/// replacing it (named `db`, not `kv`, purely for wizard/CLI
146/// discoverability - see `larust-db`'s own doc comment). See that crate's
147/// own doc comment for the full design and the `#[derive(Model)]`/
148/// relations trade-off that keeps this from being a second database
149/// backend.
150#[cfg(feature = "db")]
151pub mod db {
152    pub use larust_db::{
153        connect, forget, get, get_raw, keys, parse_cli_value, put, put_raw, DbPlugin,
154    };
155}
156
157/// Not feature-gated, unlike [`cashier`]/[`db`]/[`permission`]/etc. above:
158/// `<Image ...>` is core template-directive surface, the same tier as
159/// [`wire`]/[`spa`] (see [`spa`]'s own doc comment for the identical
160/// reasoning). Backs `larust-view`'s own `<Image src="..." width="..."
161/// height="..." />` tag - see `larust-image`'s own doc comment for the
162/// full design (on-demand resize + AVIF/JPEG re-encoding, local images
163/// only).
164pub mod image {
165    pub use larust_image::{
166        build_srcset, optimized_url, tag, ImageOptions, ImagePlugin, Loading, Placeholder,
167        DEFAULT_QUALITY,
168    };
169}
170
171/// Gated behind the `passport` feature - see [`permission`]'s own doc
172/// comment for why. A full OAuth2 authorization server (`laravel/
173/// passport`) - client registration, the Authorization Code grant with
174/// mandatory PKCE, Client Credentials, and Refresh Token rotation; see
175/// `larust-passport`'s own doc comment for the full design, including
176/// the three ways it's deliberately narrower than real Passport (one
177/// redirect URI per client, no bespoke `xr` client-registration
178/// subcommand, no scopes UI/consent-screen rendering - your own
179/// `/oauth/authorize` route owns that).
180#[cfg(feature = "passport")]
181pub mod passport {
182    pub use larust_passport::{
183        create_authorization_code, create_client, exchange_token, has_scope, require_scope,
184        revoke_access_token, revoke_refresh_token, AuthorizeRequest, NewClient, OAuthAuth,
185        OAuthClientAuth, OAuthError, PkceMethod, TokenRequest, TokenResponse,
186    };
187}
188
189/// Gated behind the `pennant` feature - see [`permission`]'s own doc
190/// comment for why. Boolean-only, scope-aware feature flags
191/// (`laravel/pennant`) - persisted via this crate's own `feature_flags`
192/// table, no process-wide resolver registry; see `larust-pennant`'s own
193/// doc comment for the full design, including why `active`'s `default`
194/// is a plain argument rather than something registered once elsewhere.
195#[cfg(feature = "pennant")]
196pub mod pennant {
197    pub use larust_pennant::{activate, active, deactivate, forget, purge};
198}
199
200/// Gated behind the `permissions` feature - see `larust-support`'s own
201/// `Cargo.toml` doc comment (if any) or `docs/ARCHITECTURE.md` for why
202/// this and its three siblings below are opt-in rather than always
203/// compiled in: each stands in for a genuinely optional third-party
204/// Laravel package (`spatie/laravel-permission`), not core framework
205/// surface, so an app that never uses it shouldn't pay to compile it.
206#[cfg(feature = "permissions")]
207pub mod permission {
208    pub use larust_permissions::{
209        assign_role, authorize_admin, authorize_permission, create_permission, create_role,
210        give_permission_to, grant_role_permission, has_permission_to, has_role, is_admin,
211        remove_role, AdminRole, PermissionName, RoleName,
212    };
213}
214
215/// Gated behind the `reverb` feature - see [`permission`]'s own doc
216/// comment for why.
217#[cfg(feature = "reverb")]
218pub mod reverb {
219    pub use larust_reverb::{authorize, broadcast_event, runtime_js, socket, ReverbPlugin};
220}
221
222/// Gated behind the `sanctum` feature - see [`permission`]'s own doc
223/// comment for why.
224#[cfg(feature = "sanctum")]
225pub mod sanctum {
226    pub use larust_sanctum::{create_token, revoke_all_tokens_for, revoke_token, ApiAuth};
227}
228
229/// Gated behind the `scout` feature - see [`permission`]'s own doc
230/// comment for why. Full-text search (`laravel/scout`), Meilisearch
231/// only - see `larust-scout`'s own doc comment for the full design,
232/// including why there's no `Searchable` trait/automatic model-lifecycle
233/// indexing the way real Scout has.
234#[cfg(feature = "scout")]
235pub mod scout {
236    pub use larust_scout::{index, remove, search, SearchResults};
237}
238
239/// Gated behind the `shield` feature (which implies `permissions` - see
240/// that feature's own `Cargo.toml` comment) - a lighter-weight,
241/// `bezhansalleh/filament-shield`-inspired resource/ability layer on top
242/// of [`permission`], not a stand-in for a Laravel package (there isn't
243/// one). See `larust-shield`'s own doc comment for the full design and
244/// what's deliberately out of scope.
245#[cfg(feature = "shield")]
246pub mod shield {
247    pub use larust_shield::{
248        authorize_ability, can, create_resource_permissions, grant_resource_abilities, Ability,
249        ResourceName, ResourcePermission, ALL_ABILITIES,
250    };
251}
252
253/// Gated behind the `sitemap` feature - see [`permission`]'s own doc
254/// comment for why.
255#[cfg(feature = "sitemap")]
256pub mod sitemap {
257    pub use larust_sitemap::{build_xml, from_static_routes, response, ChangeFreq, SitemapEntry};
258}
259
260/// Gated behind the `socialite` feature - see [`permission`]'s own doc
261/// comment for why.
262#[cfg(feature = "socialite")]
263pub mod socialite {
264    pub use larust_socialite::{
265        github, google, redirect_url, user_from_callback, OAuthProvider, ProviderUser,
266        SocialiteUser,
267    };
268}
269
270pub mod cache {
271    pub use larust_cache::{forget, get, put, remember, sweep_expired};
272}
273
274pub mod console {
275    pub use larust_console::{Command, CommandInfo, CommandRegistry};
276}
277
278pub mod event {
279    pub use larust_events::{dispatch, listeners, Event, ListenerRegistry};
280}
281
282/// Not feature-gated - see [`spa`]'s own doc comment for the same
283/// reasoning: `__()`/`trans()` are core Laravel functionality, not a
284/// stand-in for a specific optional third-party package the way
285/// `permission`/`sanctum`/etc. are. `larust_http::locale::negotiate` (the
286/// session-reading half of this) lives with the other opt-in HTTP
287/// middleware instead of being re-exported here, matching `csrf::verify`/
288/// `require_auth`'s own precedent of being attached via `.middleware(...)`
289/// directly rather than through the facade.
290pub mod lang {
291    pub use larust_lang::{current_locale, set_current_locale, t, t_or, t_or_with, t_with};
292}
293
294pub mod queue {
295    pub use larust_queue::{dispatch, prune_failed_jobs, work, Job, JobRegistry};
296}
297
298pub mod schedule {
299    pub use larust_scheduler::{work, Schedule};
300}
301
302pub mod storage {
303    pub use larust_storage::{
304        local, local_at, public, public_at, Disk, DiskConfig, FilesystemConfig,
305    };
306}
307
308pub mod wire {
309    pub use larust_live::{
310        components, mount, runtime_js, update, LiveRegistry, WireComponent, WirePlugin,
311    };
312}
313
314pub mod push {
315    pub use larust_live::push::{broadcast, runtime_js, socket, wrap, PushPlugin};
316}
317
318/// Not feature-gated, unlike [`permission`]/`reverb`/`sanctum`/`sitemap`/
319/// `socialite` above - `@spa` is core template-directive surface (the same
320/// tier as [`wire`]/[`push`]), not a stand-in for an optional third-party
321/// Laravel package an app opts into compiling.
322pub mod spa {
323    pub use larust_spa::{runtime_js, SpaPlugin};
324}