Inertia Types¶
Type definitions and utilities for Inertia.js protocol support.
This module provides the core type definitions used for Inertia.js page rendering, including page props, headers, and configuration for v2 features like deferred props, merge strategies, and infinite scroll.
Available Types¶
- PageProps
Generic type representing the complete page object sent to Inertia client. Includes support for v2 features like history encryption, merge props, deferred loading, and infinite scroll.
- InertiaProps
Wrapper type for Inertia props.
- InertiaHeaderType
TypedDict for Inertia request/response headers.
- MergeStrategy
Literal type for merge strategies: “append”, “prepend”, “deep”.
- DeferredPropsConfig
Configuration for lazy-loaded props (v2 feature).
- ScrollPropsConfig
Configuration for infinite scroll pagination (v2 feature).
Available Functions¶
- to_camel_case
Convert snake_case strings to camelCase for JavaScript compatibility.
- to_inertia_dict
Convert Python dataclasses to dicts with camelCase keys for Inertia.js protocol.
Inertia protocol types and serialization helpers.
This module defines the Python-side data structures for the Inertia.js protocol and provides helpers to serialize dataclass instances into the camelCase shape expected by the client.
- class litestar_vite.inertia.types.DeferredPropsConfig[source]¶
Bases:
objectConfiguration for deferred props (v2 feature).
Deferred props are loaded lazily after the initial page render. This allows for faster initial page loads by deferring non-critical data.
- class litestar_vite.inertia.types.InertiaHeaderType[source]¶
Bases:
TypedDictType for inertia_headers parameter in get_headers().
- class litestar_vite.inertia.types.PageProps[source]¶
Bases:
Generic[T]Inertia Page Props Type.
This represents the page object sent to the Inertia client. See: https://inertiajs.com/the-protocol
Note: Field names use snake_case in Python but are serialized to camelCase for the Inertia.js protocol using to_inertia_dict().
- scroll_props¶
Configuration for infinite scroll (v2).
- Type:
- to_dict() dict[str, Any][source]¶
Convert to Inertia.js protocol format with camelCase keys.
- Returns:
The Inertia protocol dictionary.
- __init__(component: str, url: str, version: str, props: dict[str, Any], encrypt_history: bool = False, clear_history: bool = False, merge_props: list[str] | None = None, prepend_props: list[str] | None = None, deep_merge_props: list[str] | None = None, match_props_on: dict[str, list[str]] | None = None, deferred_props: dict[str, list[str]] | None = None, scroll_props: ScrollPropsConfig | None = None) None¶
- class litestar_vite.inertia.types.ScrollPagination[source]¶
Bases:
Generic[T]Pagination container optimized for infinite scroll.
A generic pagination type that works seamlessly with Inertia’s infinite scroll feature. Can be constructed directly or created from any pagination container using
create_from().Example:
from litestar_vite.inertia.types import ScrollPagination Direct construction:: @get("/users", component="Users", infinite_scroll=True) async def list_users() -> ScrollPagination[User]: users = await fetch_users(limit=10, offset=0) return ScrollPagination(items=users, total=100, limit=10, offset=0) From an existing pagination container:: @get("/posts", component="Posts", infinite_scroll=True) async def list_posts() -> ScrollPagination[Post]: pagination = await repo.list_paginated(limit=10, offset=0) return ScrollPagination.create_from(pagination)
- classmethod create_from(pagination: Any) ScrollPagination[T][source]¶
Create from any pagination container (auto-detects type).
Supports OffsetPagination, ClassicPagination, and any custom pagination class with standard pagination attributes.
- Parameters:
pagination¶ – Any pagination container with
itemsattribute.- Returns:
A ScrollPagination instance with normalized offset-based metadata.
Example:
from litestar.pagination import OffsetPagination, ClassicPagination From OffsetPagination:: offset_page = OffsetPagination(items=[...], limit=10, offset=20, total=100) scroll = ScrollPagination.create_from(offset_page) From ClassicPagination:: classic_page = ClassicPagination(items=[...], page_size=10, current_page=3, total_pages=10) scroll = ScrollPagination.create_from(classic_page)
- class litestar_vite.inertia.types.ScrollPropsConfig[source]¶
Bases:
objectConfiguration for infinite scroll (v2 feature).
- litestar_vite.inertia.types.to_camel_case(snake_str: str) str[source]¶
Convert snake_case string to camelCase.
- Parameters:
snake_str¶ – A snake_case string.
- Returns:
The camelCase equivalent.
Examples
>>> to_camel_case("encrypt_history") 'encryptHistory' >>> to_camel_case("deep_merge_props") 'deepMergeProps'
- litestar_vite.inertia.types.to_inertia_dict(obj: Any, required_fields: set[str] | None = None) dict[str, Any][source]¶
Convert a dataclass to a dict with camelCase keys for Inertia.js protocol.
- Parameters:
- Returns:
A dictionary with camelCase keys, excluding None values for optional fields.
Note
This function avoids using dataclasses.asdict() directly because of a bug in Python 3.10/3.11 that fails when processing dict[str, list[str]] types. See: https://github.com/python/cpython/issues/103000