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;
11mod redirect;
12pub mod regex_replace;
13pub mod strings;
14pub mod truthy;
15mod url_helper;
16pub mod vitex;
17
18pub use abort::abort;
19pub use config_helper::config;
20pub use html::sanitize_rich_text;
21pub use loop_iter::{Loop, WithLoop};
22pub use redirect::{redirect, route, route_with, Redirect, RedirectBuilder};
23pub use url_helper::{asset, url};
24
25/// `#[derive(FormRequest)]`, `view!`, `error_view!`, and `#[derive(Model)]` -
26/// re-exported here so generated apps depend only on `larust-support`, not
27/// on `larust-macros` directly. All four macros' generated code assumes
28/// this re-export path (`::larust_support::...`).
29pub use larust_macros::{error_view, view, FormRequest, Model};
30
31/// Re-exported (not just used internally) so macro-generated code can
32/// reference `::larust_support::axum::...`/`::larust_support::AppError`
33/// instead of `::larust_core::...` - a crate depending on `larust-support`
34/// alone must not need `larust-core` as a *direct* dependency just to use
35/// a macro. Keep every path in `larust-macros`' generated code routed
36/// through `larust_support` for the same reason. `default_not_found_html`/
37/// `default_internal_html` are `error_view!`'s own fallback when no
38/// `resources/views/errors/{code}.blade.xr` override exists.
39pub use larust_core::{axum, default_internal_html, default_not_found_html, AppError};
40
41/// Re-exported so app code can log (e.g. a best-effort failure, matching
42/// `Redirect::with`'s own pattern) without adding `tracing` as a direct
43/// dependency - the same "one dependency surface" reasoning as `axum`
44/// above.
45pub use tracing;
46
47/// Re-exported for the same "one dependency surface" reason as `axum`/
48/// `tracing` above - `view!`'s `@wire(...)` codegen arm references
49/// `::larust_support::serde_json::{Value, to_value}` directly in generated
50/// code, so an app using `@wire(...)` doesn't need `serde_json` as a direct
51/// dependency of its own just to compile that macro expansion.
52pub use serde_json;
53
54pub mod validation {
55    pub use larust_validation::{form_urlencoded, rules, ValidationErrors};
56}
57
58pub mod view {
59    pub use larust_view::{escape, js, View};
60}
61
62/// Runtime home for `@push`/`@stack` content that needs to cross a boundary
63/// compile-time `view!(...)` resolution can't see across (a `<wire:...>`
64/// mount, or two `view!(...)` calls glued by `.into_html()`) - see
65/// `larust_view::push_registry`'s own doc comment for the full design.
66/// Reached by generated codegen the same way `larust_support::wire::mount`/
67/// `larust_support::view::escape` already are.
68pub mod push_registry {
69    pub use larust_view::push_registry::{drain, drain_since, mark, record, with_scope};
70}
71
72pub mod orm {
73    pub use larust_orm::{
74        backend, connect, migrate, migrate_fresh, placeholder, pool, sqlx, table_names,
75        AnyRepository, Backend, BindValue, ConnectionConfig, DatabaseConnections, Driver, Factory,
76        FactoryBuilder, Model, Op, Order, QueryBuilder, SoftDeletes,
77    };
78}
79
80/// The non-SQL half of Larust's persistence story - see
81/// `larust_repository::Repository`'s own doc comment for the full design
82/// (storage-agnostic CRUD, implemented automatically for `#[derive(Model)]`
83/// structs via `orm::AnyRepository<T>`, by hand for anything else).
84pub mod repository {
85    pub use larust_repository::Repository;
86}
87
88pub mod auth {
89    pub use larust_auth::{
90        authorize, check, check_for, hash_password, id, id_for, login, logout, logout_for,
91        redirect_authenticated, redirect_authenticated_for, require_auth, require_auth_for, user,
92        verify_password, Auth, Authenticatable, Policy,
93    };
94}
95
96pub mod mail {
97    pub use larust_mail::{mail, MailBuilder, MailJob, Mailable};
98}
99
100/// Backs `@globals`' `persist` entries - see `larust_http::preferences`'
101/// own doc comment for the full design (a dedicated, unsigned,
102/// long-lived cookie, deliberately not `Session`-backed).
103pub mod preferences {
104    pub use larust_http::preferences::{get, CookieJar};
105}
106
107pub mod notification {
108    pub use larust_notifications::{
109        clear_notifications, delete_notification, mark_all_as_read, mark_as_read,
110        notifications_for, notify, notify_and_mail, to, unread_count, MailNotifiable,
111        MailNotification, Notification, PendingNotification, StoredNotification,
112    };
113}
114
115/// Gated behind the `db` feature - see [`permission`]'s own doc comment
116/// for why. `db` stands in for no particular Laravel package (there isn't
117/// one) - it's an optional, additive facade over `larust-db`'s embedded
118/// pure-Rust key-value store, alongside the SQL database rather than
119/// replacing it (named `db`, not `kv`, purely for wizard/CLI
120/// discoverability - see `larust-db`'s own doc comment). See that crate's
121/// own doc comment for the full design and the `#[derive(Model)]`/
122/// relations trade-off that keeps this from being a second database
123/// backend.
124#[cfg(feature = "db")]
125pub mod db {
126    pub use larust_db::{
127        connect, forget, get, get_raw, keys, parse_cli_value, put, put_raw, DbPlugin,
128    };
129}
130
131/// Gated behind the `permissions` feature - see `larust-support`'s own
132/// `Cargo.toml` doc comment (if any) or `docs/ARCHITECTURE.md` for why
133/// this and its three siblings below are opt-in rather than always
134/// compiled in: each stands in for a genuinely optional third-party
135/// Laravel package (`spatie/laravel-permission`), not core framework
136/// surface, so an app that never uses it shouldn't pay to compile it.
137#[cfg(feature = "permissions")]
138pub mod permission {
139    pub use larust_permissions::{
140        assign_role, authorize_admin, authorize_permission, create_permission, create_role,
141        give_permission_to, grant_role_permission, has_permission_to, has_role, is_admin,
142        remove_role, AdminRole, PermissionName, RoleName,
143    };
144}
145
146/// Gated behind the `reverb` feature - see [`permission`]'s own doc
147/// comment for why.
148#[cfg(feature = "reverb")]
149pub mod reverb {
150    pub use larust_reverb::{authorize, broadcast_event, runtime_js, socket, ReverbPlugin};
151}
152
153/// Gated behind the `sanctum` feature - see [`permission`]'s own doc
154/// comment for why.
155#[cfg(feature = "sanctum")]
156pub mod sanctum {
157    pub use larust_sanctum::{create_token, revoke_all_tokens_for, revoke_token, ApiAuth};
158}
159
160/// Gated behind the `shield` feature (which implies `permissions` - see
161/// that feature's own `Cargo.toml` comment) - a lighter-weight,
162/// `bezhansalleh/filament-shield`-inspired resource/ability layer on top
163/// of [`permission`], not a stand-in for a Laravel package (there isn't
164/// one). See `larust-shield`'s own doc comment for the full design and
165/// what's deliberately out of scope.
166#[cfg(feature = "shield")]
167pub mod shield {
168    pub use larust_shield::{
169        authorize_ability, can, create_resource_permissions, grant_resource_abilities, Ability,
170        ResourceName, ResourcePermission, ALL_ABILITIES,
171    };
172}
173
174/// Gated behind the `sitemap` feature - see [`permission`]'s own doc
175/// comment for why.
176#[cfg(feature = "sitemap")]
177pub mod sitemap {
178    pub use larust_sitemap::{build_xml, from_static_routes, response, ChangeFreq, SitemapEntry};
179}
180
181/// Gated behind the `socialite` feature - see [`permission`]'s own doc
182/// comment for why.
183#[cfg(feature = "socialite")]
184pub mod socialite {
185    pub use larust_socialite::{
186        github, google, redirect_url, user_from_callback, OAuthProvider, ProviderUser,
187        SocialiteUser,
188    };
189}
190
191pub mod cache {
192    pub use larust_cache::{forget, get, put, remember};
193}
194
195pub mod console {
196    pub use larust_console::{Command, CommandInfo, CommandRegistry};
197}
198
199pub mod event {
200    pub use larust_events::{dispatch, listeners, Event, ListenerRegistry};
201}
202
203/// Not feature-gated - see [`spa`]'s own doc comment for the same
204/// reasoning: `__()`/`trans()` are core Laravel functionality, not a
205/// stand-in for a specific optional third-party package the way
206/// `permission`/`sanctum`/etc. are. `larust_http::locale::negotiate` (the
207/// session-reading half of this) lives with the other opt-in HTTP
208/// middleware instead of being re-exported here, matching `csrf::verify`/
209/// `require_auth`'s own precedent of being attached via `.middleware(...)`
210/// directly rather than through the facade.
211pub mod lang {
212    pub use larust_lang::{current_locale, set_current_locale, t, t_or, t_or_with, t_with};
213}
214
215pub mod queue {
216    pub use larust_queue::{dispatch, work, Job, JobRegistry};
217}
218
219pub mod schedule {
220    pub use larust_scheduler::{work, Schedule};
221}
222
223pub mod storage {
224    pub use larust_storage::{
225        local, local_at, public, public_at, Disk, DiskConfig, FilesystemConfig,
226    };
227}
228
229pub mod wire {
230    pub use larust_live::{
231        components, mount, runtime_js, update, LiveRegistry, WireComponent, WirePlugin,
232    };
233}
234
235pub mod push {
236    pub use larust_live::push::{broadcast, runtime_js, socket, wrap, PushPlugin};
237}
238
239/// Not feature-gated, unlike [`permission`]/`reverb`/`sanctum`/`sitemap`/
240/// `socialite` above - `@spa` is core template-directive surface (the same
241/// tier as [`wire`]/[`push`]), not a stand-in for an optional third-party
242/// Laravel package an app opts into compiling.
243pub mod spa {
244    pub use larust_spa::{runtime_js, SpaPlugin};
245}