@adonisjs/inertia
Version:
Official Inertia.js adapter for AdonisJS
109 lines (105 loc) • 3.63 kB
TypeScript
import { Vite } from '@adonisjs/vite';
import { HttpContext } from '@adonisjs/core/http';
import { NextFn } from '@adonisjs/core/types/http';
import { R as ResolvedConfig, D as Data, P as PageObject, M as MaybePromise, O as OptionalProp, a as MergeProp, A as AlwaysProp, b as DeferProp } from '../types-DVqEHBD1.js';
import '@adonisjs/core/types';
import '@tuyau/utils/types';
/**
* Main class used to interact with Inertia
*/
declare class Inertia {
#private;
protected ctx: HttpContext;
protected config: ResolvedConfig;
protected vite?: Vite | undefined;
constructor(ctx: HttpContext, config: ResolvedConfig, vite?: Vite | undefined);
/**
* Share data for the current request.
* This data will override any shared data defined in the config.
*/
share(data: Record<string, Data>): void;
/**
* Render a page using Inertia
*/
render<TPageProps extends Record<string, any> = {}, TViewProps extends Record<string, any> = {}>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject<TPageProps>>;
/**
* Clear history state.
*
* See https://v2.inertiajs.com/history-encryption#clearing-history
*/
clearHistory(): void;
/**
* Encrypt history
*
* See https://v2.inertiajs.com/history-encryption
*/
encryptHistory(encrypt?: boolean): void;
/**
* Create a lazy prop
*
* Lazy props are never resolved on first visit, but only when the client
* request a partial reload explicitely with this value.
*
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
*
* @deprecated use `optional` instead
*/
lazy<T>(callback: () => MaybePromise<T>): OptionalProp<() => MaybePromise<T>>;
/**
* Create an optional prop
*
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
*/
optional<T>(callback: () => MaybePromise<T>): OptionalProp<() => MaybePromise<T>>;
/**
* Create a mergeable prop
*
* See https://v2.inertiajs.com/merging-props
*/
merge<T>(callback: () => MaybePromise<T>): MergeProp<() => MaybePromise<T>>;
/**
* Create an always prop
*
* Always props are resolved on every request, no matter if it's a partial
* request or not.
*
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
*/
always<T>(callback: () => MaybePromise<T>): AlwaysProp<() => MaybePromise<T>>;
/**
* Create a deferred prop
*
* Deferred props feature allows you to defer the loading of certain
* page data until after the initial page render.
*
* See https://v2.inertiajs.com/deferred-props
*/
defer<T>(callback: () => MaybePromise<T>, group?: string): DeferProp<() => MaybePromise<T>>;
/**
* This method can be used to redirect the user to an external website
* or even a non-inertia route of your application.
*
* See https://inertiajs.com/redirects#external-redirects
*/
location(url: string): Promise<void>;
}
/**
* HttpContext augmentations
*/
declare module '@adonisjs/core/http' {
interface HttpContext {
inertia: Inertia;
}
}
/**
* Inertia middleware to handle the Inertia requests and
* set appropriate headers/status
*/
declare class InertiaMiddleware {
#private;
protected config: ResolvedConfig;
protected vite?: Vite | undefined;
constructor(config: ResolvedConfig, vite?: Vite | undefined);
handle(ctx: HttpContext, next: NextFn): Promise<void>;
}
export { InertiaMiddleware as default };