UNPKG

@adonisjs/inertia

Version:

Official Inertia.js adapter for AdonisJS

138 lines (137 loc) 3.83 kB
import { type Vite } from '@adonisjs/vite'; import { type HttpContext } from '@adonisjs/core/http'; import { Inertia } from '../src/inertia.js'; import { type AssetsVersion, type InertiaConfig, type ComponentProps, type InertiaConfigInput } from '../src/types.js'; /** * Parameters for configuring the Inertia factory */ type FactoryParameters = { /** HTTP context for the request */ ctx: HttpContext; /** Inertia configuration object */ config: InertiaConfig; }; /** * Inertia factory to quickly create a new instance of Inertia * for testing purposes * * @example * ```typescript * const factory = new InertiaFactory() * const inertia = factory * .merge({ config: { ssr: { enabled: true } } }) * .withVersion('1.0.0') * .create() * ``` */ export declare class InertiaFactory<Pages extends Record<string, ComponentProps>> { #private; /** * Creates a new InertiaFactory instance with default Inertia headers * * @example * ```typescript * const factory = new InertiaFactory() * ``` */ constructor(); /** * Merges additional parameters into the factory configuration * * @param parameters - Partial factory parameters to merge * * @example * ```typescript * factory.merge({ * config: { ssr: { enabled: true } }, * ctx: customContext * }) * ``` */ merge(parameters: Omit<Partial<FactoryParameters>, 'config'> & { config?: InertiaConfigInput; }): this; /** * Removes the X-Inertia header from the request headers * * @example * ```typescript * const inertia = factory.withoutInertia().create() * ``` */ withoutInertia(): this; /** * Configures the factory for partial reloads of a specific component * * @param component - Name of the component to partially reload * * @example * ```typescript * const inertia = factory * .partialReload('UserProfile') * .only(['name', 'email']) * .create() * ``` */ partialReload<Page extends keyof Pages & string>(component: Page): { /** * Specifies which props to include in the partial reload * * @param props - Array of property names to include */ only(props: string[]): /*elided*/ any; /** * Specifies which props to exclude from the partial reload * * @param props - Array of property names to exclude */ except(props: string[]): /*elided*/ any; /** * Specifies which props should be reset during the partial reload * * @param props - Array of property names to reset */ reset(props: string[]): /*elided*/ any; /** * Creates the Inertia instance with partial reload configuration */ create(): Inertia<Pages>; }; /** * Sets the assets version for cache busting * * @param version - Version string or function for asset versioning * * @example * ```typescript * factory.withVersion('1.0.0') * // or * factory.withVersion(() => Date.now().toString()) * ``` */ withVersion(version: AssetsVersion): this; /** * Sets the Vite instance for asset handling * * @param options - Vite configuration object * * @example * ```typescript * factory.withVite(viteInstance) * ``` */ withVite(options: Vite): this; /** * Creates a new Inertia instance with the configured parameters * * @example * ```typescript * const inertia = factory * .merge({ config: customConfig }) * .withVersion('1.0.0') * .create() * ``` */ create(): Inertia<Pages>; } export {};