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, read_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/// Umbrella namespace for subscription billing (`laravel/cashier`) - one
116/// submodule per payment provider backend, each gated behind its own
117/// independently-selectable feature (`cashier-stripe` today; a future
118/// `cashier-paypal`/`cashier-square` gets its own `paypal`/`square`
119/// submodule the same way) rather than one shared trait every provider
120/// implements - see `larust-cashier-stripe`'s own doc comment for why a
121/// shared interface would be either leaky or lowest-common-denominator
122/// thin across providers whose own object models don't actually agree.
123/// An app can enable more than one backend at once; nothing here forces a
124/// choice between them.
125pub mod cashier {
126 /// See [`permission`]'s own doc comment for why this (and every
127 /// backend submodule here) is opt-in. No `Billable` trait the way
128 /// real Cashier mixes into its `User` model - see
129 /// `larust-cashier-stripe`'s own doc comment for the full design.
130 #[cfg(feature = "cashier-stripe")]
131 pub mod stripe {
132 pub use larust_cashier_stripe::{
133 cancel_subscription, checkout_url, create_customer, customer_for, handle_webhook,
134 resume_subscription, subscribed, subscription_for, swap_subscription, CashierError,
135 Subscription, WebhookEvent,
136 };
137 }
138}
139
140/// Gated behind the `db` feature - see [`permission`]'s own doc comment
141/// for why. `db` stands in for no particular Laravel package (there isn't
142/// one) - it's an optional, additive facade over `larust-db`'s embedded
143/// pure-Rust key-value store, alongside the SQL database rather than
144/// replacing it (named `db`, not `kv`, purely for wizard/CLI
145/// discoverability - see `larust-db`'s own doc comment). See that crate's
146/// own doc comment for the full design and the `#[derive(Model)]`/
147/// relations trade-off that keeps this from being a second database
148/// backend.
149#[cfg(feature = "db")]
150pub mod db {
151 pub use larust_db::{
152 connect, forget, get, get_raw, keys, parse_cli_value, put, put_raw, DbPlugin,
153 };
154}
155
156/// Not feature-gated, unlike [`cashier`]/[`db`]/[`permission`]/etc. above:
157/// `<Image ...>` is core template-directive surface, the same tier as
158/// [`wire`]/[`spa`] (see [`spa`]'s own doc comment for the identical
159/// reasoning). Backs `larust-view`'s own `<Image src="..." width="..."
160/// height="..." />` tag - see `larust-image`'s own doc comment for the
161/// full design (on-demand resize + AVIF/JPEG re-encoding, local images
162/// only).
163pub mod image {
164 pub use larust_image::{
165 build_srcset, optimized_url, tag, ImageOptions, ImagePlugin, Loading, Placeholder,
166 DEFAULT_QUALITY,
167 };
168}
169
170/// Gated behind the `passport` feature - see [`permission`]'s own doc
171/// comment for why. A full OAuth2 authorization server (`laravel/
172/// passport`) - client registration, the Authorization Code grant with
173/// mandatory PKCE, Client Credentials, and Refresh Token rotation; see
174/// `larust-passport`'s own doc comment for the full design, including
175/// the three ways it's deliberately narrower than real Passport (one
176/// redirect URI per client, no bespoke `xr` client-registration
177/// subcommand, no scopes UI/consent-screen rendering - your own
178/// `/oauth/authorize` route owns that).
179#[cfg(feature = "passport")]
180pub mod passport {
181 pub use larust_passport::{
182 create_authorization_code, create_client, exchange_token, has_scope, require_scope,
183 revoke_access_token, revoke_refresh_token, AuthorizeRequest, NewClient, OAuthAuth,
184 OAuthClientAuth, OAuthError, PkceMethod, TokenRequest, TokenResponse,
185 };
186}
187
188/// Gated behind the `pennant` feature - see [`permission`]'s own doc
189/// comment for why. Boolean-only, scope-aware feature flags
190/// (`laravel/pennant`) - persisted via this crate's own `feature_flags`
191/// table, no process-wide resolver registry; see `larust-pennant`'s own
192/// doc comment for the full design, including why `active`'s `default`
193/// is a plain argument rather than something registered once elsewhere.
194#[cfg(feature = "pennant")]
195pub mod pennant {
196 pub use larust_pennant::{activate, active, deactivate, forget, purge};
197}
198
199/// Gated behind the `permissions` feature - see `larust-support`'s own
200/// `Cargo.toml` doc comment (if any) or `docs/ARCHITECTURE.md` for why
201/// this and its three siblings below are opt-in rather than always
202/// compiled in: each stands in for a genuinely optional third-party
203/// Laravel package (`spatie/laravel-permission`), not core framework
204/// surface, so an app that never uses it shouldn't pay to compile it.
205#[cfg(feature = "permissions")]
206pub mod permission {
207 pub use larust_permissions::{
208 assign_role, authorize_admin, authorize_permission, create_permission, create_role,
209 give_permission_to, grant_role_permission, has_permission_to, has_role, is_admin,
210 remove_role, AdminRole, PermissionName, RoleName,
211 };
212}
213
214/// Gated behind the `reverb` feature - see [`permission`]'s own doc
215/// comment for why.
216#[cfg(feature = "reverb")]
217pub mod reverb {
218 pub use larust_reverb::{authorize, broadcast_event, runtime_js, socket, ReverbPlugin};
219}
220
221/// Gated behind the `sanctum` feature - see [`permission`]'s own doc
222/// comment for why.
223#[cfg(feature = "sanctum")]
224pub mod sanctum {
225 pub use larust_sanctum::{create_token, revoke_all_tokens_for, revoke_token, ApiAuth};
226}
227
228/// Gated behind the `scout` feature - see [`permission`]'s own doc
229/// comment for why. Full-text search (`laravel/scout`), Meilisearch
230/// only - see `larust-scout`'s own doc comment for the full design,
231/// including why there's no `Searchable` trait/automatic model-lifecycle
232/// indexing the way real Scout has.
233#[cfg(feature = "scout")]
234pub mod scout {
235 pub use larust_scout::{index, remove, search, SearchResults};
236}
237
238/// Gated behind the `shield` feature (which implies `permissions` - see
239/// that feature's own `Cargo.toml` comment) - a lighter-weight,
240/// `bezhansalleh/filament-shield`-inspired resource/ability layer on top
241/// of [`permission`], not a stand-in for a Laravel package (there isn't
242/// one). See `larust-shield`'s own doc comment for the full design and
243/// what's deliberately out of scope.
244#[cfg(feature = "shield")]
245pub mod shield {
246 pub use larust_shield::{
247 authorize_ability, can, create_resource_permissions, grant_resource_abilities, Ability,
248 ResourceName, ResourcePermission, ALL_ABILITIES,
249 };
250}
251
252/// Gated behind the `sitemap` feature - see [`permission`]'s own doc
253/// comment for why.
254#[cfg(feature = "sitemap")]
255pub mod sitemap {
256 pub use larust_sitemap::{build_xml, from_static_routes, response, ChangeFreq, SitemapEntry};
257}
258
259/// Gated behind the `socialite` feature - see [`permission`]'s own doc
260/// comment for why.
261#[cfg(feature = "socialite")]
262pub mod socialite {
263 pub use larust_socialite::{
264 github, google, redirect_url, user_from_callback, OAuthProvider, ProviderUser,
265 SocialiteUser,
266 };
267}
268
269pub mod cache {
270 pub use larust_cache::{forget, get, put, remember};
271}
272
273pub mod console {
274 pub use larust_console::{Command, CommandInfo, CommandRegistry};
275}
276
277pub mod event {
278 pub use larust_events::{dispatch, listeners, Event, ListenerRegistry};
279}
280
281/// Not feature-gated - see [`spa`]'s own doc comment for the same
282/// reasoning: `__()`/`trans()` are core Laravel functionality, not a
283/// stand-in for a specific optional third-party package the way
284/// `permission`/`sanctum`/etc. are. `larust_http::locale::negotiate` (the
285/// session-reading half of this) lives with the other opt-in HTTP
286/// middleware instead of being re-exported here, matching `csrf::verify`/
287/// `require_auth`'s own precedent of being attached via `.middleware(...)`
288/// directly rather than through the facade.
289pub mod lang {
290 pub use larust_lang::{current_locale, set_current_locale, t, t_or, t_or_with, t_with};
291}
292
293pub mod queue {
294 pub use larust_queue::{dispatch, work, Job, JobRegistry};
295}
296
297pub mod schedule {
298 pub use larust_scheduler::{work, Schedule};
299}
300
301pub mod storage {
302 pub use larust_storage::{
303 local, local_at, public, public_at, Disk, DiskConfig, FilesystemConfig,
304 };
305}
306
307pub mod wire {
308 pub use larust_live::{
309 components, mount, runtime_js, update, LiveRegistry, WireComponent, WirePlugin,
310 };
311}
312
313pub mod push {
314 pub use larust_live::push::{broadcast, runtime_js, socket, wrap, PushPlugin};
315}
316
317/// Not feature-gated, unlike [`permission`]/`reverb`/`sanctum`/`sitemap`/
318/// `socialite` above - `@spa` is core template-directive surface (the same
319/// tier as [`wire`]/[`push`]), not a stand-in for an optional third-party
320/// Laravel package an app opts into compiling.
321pub mod spa {
322 pub use larust_spa::{runtime_js, SpaPlugin};
323}