@adonisjs/inertia 3.1.1 → 4.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/build/bin/test.d.ts +1 -0
- package/build/chunk-4EZ2J6OA.js +7 -0
- package/build/chunk-74S2VAL7.js +761 -0
- package/build/chunk-DISC5OYC.js +46 -0
- package/build/chunk-MLKGABMK.js +9 -0
- package/build/chunk-PDP56GPP.js +75 -0
- package/build/factories/inertia_factory.d.ts +137 -0
- package/build/factories/main.d.ts +1 -0
- package/build/factories/main.js +175 -0
- package/build/index.d.ts +7 -19
- package/build/index.js +21 -307
- package/build/providers/inertia_provider.d.ts +86 -13
- package/build/providers/inertia_provider.js +48 -18
- package/build/src/client/vite.d.ts +63 -0
- package/build/src/{plugins → client}/vite.js +9 -13
- package/build/src/debug.d.ts +22 -0
- package/build/src/define_config.d.ts +29 -0
- package/build/src/headers.d.ts +61 -0
- package/build/src/index_pages.d.ts +5 -0
- package/build/src/inertia.d.ts +253 -0
- package/build/src/inertia_manager.d.ts +46 -0
- package/build/src/inertia_middleware.d.ts +74 -87
- package/build/src/inertia_middleware.js +110 -3
- package/build/src/plugins/edge/plugin.d.ts +30 -6
- package/build/src/plugins/edge/plugin.js +13 -9
- package/build/src/plugins/edge/tags.d.ts +47 -0
- package/build/src/plugins/edge/utils.d.ts +26 -0
- package/build/src/plugins/japa/api_client.d.ts +136 -22
- package/build/src/plugins/japa/api_client.js +36 -48
- package/build/src/props.d.ts +269 -0
- package/build/src/server_renderer.d.ts +54 -0
- package/build/src/symbols.d.ts +25 -0
- package/build/src/types.d.ts +404 -4
- package/build/tests/helpers.d.ts +35 -0
- package/build/tests/index_pages.spec.d.ts +1 -0
- package/build/tests/inertia.spec.d.ts +1 -0
- package/build/tests/inertia_page.spec.d.ts +1 -0
- package/build/tests/middleware.spec.d.ts +1 -0
- package/build/tests/plugins/api_client.spec.d.ts +1 -0
- package/build/tests/plugins/edge.plugin.spec.d.ts +1 -0
- package/build/tests/provider.spec.d.ts +1 -0
- package/build/tests/types/shared_props.spec.d.ts +1 -0
- package/build/tests/types/to_component_props.spec.d.ts +1 -0
- package/build/tests/types/to_page_props.spec.d.ts +1 -0
- package/package.json +88 -71
- package/build/app.css.stub +0 -13
- package/build/chunk-W7TVEB4V.js +0 -412
- package/build/config.stub +0 -33
- package/build/react/app.tsx.stub +0 -38
- package/build/react/errors/not_found.tsx.stub +0 -14
- package/build/react/errors/server_error.tsx.stub +0 -14
- package/build/react/home.tsx.stub +0 -349
- package/build/react/root.edge.stub +0 -76
- package/build/react/ssr.tsx.stub +0 -17
- package/build/react/tsconfig.json.stub +0 -15
- package/build/solid/app.tsx.stub +0 -38
- package/build/solid/errors/not_found.tsx.stub +0 -14
- package/build/solid/errors/server_error.tsx.stub +0 -14
- package/build/solid/home.tsx.stub +0 -358
- package/build/solid/root.edge.stub +0 -73
- package/build/solid/ssr.tsx.stub +0 -19
- package/build/solid/tsconfig.json.stub +0 -16
- package/build/src/helpers.d.ts +0 -12
- package/build/src/helpers.js +0 -14
- package/build/src/plugins/vite.d.ts +0 -26
- package/build/svelte/app.ts.stub +0 -32
- package/build/svelte/errors/not_found.svelte.stub +0 -10
- package/build/svelte/errors/server_error.svelte.stub +0 -14
- package/build/svelte/home.svelte.stub +0 -339
- package/build/svelte/root.edge.stub +0 -75
- package/build/svelte/ssr.ts.stub +0 -19
- package/build/svelte/tsconfig.json.stub +0 -14
- package/build/types-DVqEHBD1.d.ts +0 -240
- package/build/vue/app.ts.stub +0 -41
- package/build/vue/errors/not_found.vue.stub +0 -10
- package/build/vue/errors/server_error.vue.stub +0 -14
- package/build/vue/home.vue.stub +0 -343
- package/build/vue/root.edge.stub +0 -75
- package/build/vue/ssr.ts.stub +0 -22
- package/build/vue/tsconfig.json.stub +0 -16
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { InertiaConfig, InertiaConfigInput } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define the Inertia configuration with default values
|
|
4
|
+
*
|
|
5
|
+
* This function merges user-provided configuration with sensible defaults
|
|
6
|
+
* to create a complete Inertia configuration object.
|
|
7
|
+
*
|
|
8
|
+
* @param config - User configuration input to override defaults
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
* const config = defineConfig({
|
|
13
|
+
* rootView: 'layouts/app',
|
|
14
|
+
* ssr: {
|
|
15
|
+
* enabled: true,
|
|
16
|
+
* bundle: 'build/ssr/ssr.js'
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```js
|
|
23
|
+
* // Minimal configuration
|
|
24
|
+
* const config = defineConfig({
|
|
25
|
+
* rootView: 'app'
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function defineConfig(config: InertiaConfigInput): InertiaConfig;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of possible headers used by Inertia.js for client-server communication.
|
|
3
|
+
* These headers control various aspects of Inertia requests and responses,
|
|
4
|
+
* enabling features like partial reloads, version checking, and error handling.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* // Check if request is an Inertia request
|
|
9
|
+
* const isInertiaRequest = request.header(InertiaHeaders.Inertia) === 'true'
|
|
10
|
+
*
|
|
11
|
+
* // Set version header in response
|
|
12
|
+
* response.header(InertiaHeaders.Version, '1.0.0')
|
|
13
|
+
*
|
|
14
|
+
* // Handle partial data requests
|
|
15
|
+
* if (request.header(InertiaHeaders.PartialOnly)) {
|
|
16
|
+
* const onlyProps = request.header(InertiaHeaders.PartialOnly).split(',')
|
|
17
|
+
* // Return only specified props
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const InertiaHeaders: {
|
|
22
|
+
/**
|
|
23
|
+
* Header to identify Inertia.js requests.
|
|
24
|
+
* Set to 'true' by Inertia.js client to indicate an Inertia request.
|
|
25
|
+
*/
|
|
26
|
+
readonly Inertia: "x-inertia";
|
|
27
|
+
/**
|
|
28
|
+
* Header to drop a prop from the merge and deep merge object.
|
|
29
|
+
*/
|
|
30
|
+
readonly Reset: "x-inertia-reset";
|
|
31
|
+
/**
|
|
32
|
+
* Header containing the current asset version.
|
|
33
|
+
* Used for cache busting - if versions don't match, Inertia performs a full page reload.
|
|
34
|
+
*/
|
|
35
|
+
readonly Version: "x-inertia-version";
|
|
36
|
+
/**
|
|
37
|
+
* Header containing the target URL for redirects.
|
|
38
|
+
* Used when the server wants to redirect to a different URL than the current request.
|
|
39
|
+
*/
|
|
40
|
+
readonly Location: "x-inertia-location";
|
|
41
|
+
/**
|
|
42
|
+
* Header specifying the error bag name for validation errors.
|
|
43
|
+
* Allows multiple forms on the same page to have separate error handling.
|
|
44
|
+
*/
|
|
45
|
+
readonly ErrorBag: "x-inertia-error-bag";
|
|
46
|
+
/**
|
|
47
|
+
* Header containing comma-separated list of props to include in partial data requests.
|
|
48
|
+
* Only the specified props will be returned in the response.
|
|
49
|
+
*/
|
|
50
|
+
readonly PartialOnly: "x-inertia-partial-data";
|
|
51
|
+
/**
|
|
52
|
+
* Header containing comma-separated list of props to exclude in partial data requests.
|
|
53
|
+
* All props except the specified ones will be returned in the response.
|
|
54
|
+
*/
|
|
55
|
+
readonly PartialExcept: "x-inertia-partial-except";
|
|
56
|
+
/**
|
|
57
|
+
* Header specifying the component name for partial reloads.
|
|
58
|
+
* Used to identify which component is being partially reloaded.
|
|
59
|
+
*/
|
|
60
|
+
readonly PartialComponent: "x-inertia-partial-component";
|
|
61
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const indexPages: (config: {
|
|
2
|
+
framework: "vue3" | "react";
|
|
3
|
+
}) => {
|
|
4
|
+
run(_: import("@adonisjs/assembler").DevServer | import("@adonisjs/assembler").TestRunner | import("@adonisjs/assembler").Bundler, indexGenerator: import("@adonisjs/assembler/index_generator").IndexGenerator): void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { type Vite } from '@adonisjs/vite';
|
|
2
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
3
|
+
import { type ServerRenderer } from './server_renderer.js';
|
|
4
|
+
import type { PageProps, PageObject, AsPageProps, RequestInfo, InertiaConfig, ComponentProps } from './types.js';
|
|
5
|
+
import { defer, merge, always, optional, deepMerge } from './props.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Main class used to interact with Inertia
|
|
8
|
+
*
|
|
9
|
+
* Provides a complete interface for handling Inertia.js requests, rendering pages,
|
|
10
|
+
* managing props, and controlling page navigation behavior.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* const inertia = new Inertia(ctx, config, vite, serverRenderer)
|
|
15
|
+
*
|
|
16
|
+
* // Render a page
|
|
17
|
+
* const result = await inertia.render('Home', { user: { name: 'John' } })
|
|
18
|
+
*
|
|
19
|
+
* // Clear browser history
|
|
20
|
+
* inertia.clearHistory()
|
|
21
|
+
*
|
|
22
|
+
* // Redirect to a different location
|
|
23
|
+
* inertia.location('/dashboard')
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class Inertia<Pages extends Record<string, ComponentProps>> {
|
|
27
|
+
#private;
|
|
28
|
+
protected ctx: HttpContext;
|
|
29
|
+
protected config: InertiaConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Defer prop evaluation until client-side rendering
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```js
|
|
35
|
+
* {
|
|
36
|
+
* expensiveData: inertia.defer(() => computeExpensiveData())
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
defer: typeof defer;
|
|
41
|
+
/**
|
|
42
|
+
* Always include prop in both server and client renders
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* {
|
|
47
|
+
* currentUser: inertia.always(() => getCurrentUser())
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
always: typeof always;
|
|
52
|
+
/**
|
|
53
|
+
* Merge prop with existing client-side data
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```js
|
|
57
|
+
* {
|
|
58
|
+
* posts: inertia.merge(() => getPosts())
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
merge: typeof merge;
|
|
63
|
+
/**
|
|
64
|
+
* Include prop only when specifically requested
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```js
|
|
68
|
+
* {
|
|
69
|
+
* optionalData: inertia.optional(() => getOptionalData())
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
optional: typeof optional;
|
|
74
|
+
/**
|
|
75
|
+
* Deep merge prop with existing client-side data
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* {
|
|
80
|
+
* settings: inertia.deepMerge(() => getSettings())
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
deepMerge: typeof deepMerge;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new Inertia instance
|
|
87
|
+
*
|
|
88
|
+
* @param ctx - HTTP context for the current request
|
|
89
|
+
* @param config - Inertia configuration object
|
|
90
|
+
* @param vite - Vite instance for asset management
|
|
91
|
+
* @param serverRenderer - Optional server renderer for SSR
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```js
|
|
95
|
+
* const inertia = new Inertia(ctx, {
|
|
96
|
+
* rootView: 'app',
|
|
97
|
+
* ssr: { enabled: true }
|
|
98
|
+
* }, vite, serverRenderer)
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
constructor(ctx: HttpContext, config: InertiaConfig, vite?: Vite, serverRenderer?: ServerRenderer);
|
|
102
|
+
/**
|
|
103
|
+
* Extract Inertia-specific information from request headers
|
|
104
|
+
*
|
|
105
|
+
* Parses various Inertia headers to determine request type and props filtering.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```js
|
|
109
|
+
* const info = inertia.requestInfo()
|
|
110
|
+
* if (info.isInertiaRequest) {
|
|
111
|
+
* // Handle as Inertia request
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
requestInfo(reCompute?: boolean): RequestInfo;
|
|
116
|
+
/**
|
|
117
|
+
* Compute and cache the assets version
|
|
118
|
+
*
|
|
119
|
+
* Uses Vite manifest hash when available, otherwise defaults to '1'.
|
|
120
|
+
*/
|
|
121
|
+
getVersion(): string;
|
|
122
|
+
/**
|
|
123
|
+
* Determine if server-side rendering is enabled for a specific component
|
|
124
|
+
*
|
|
125
|
+
* Checks global SSR settings and component-specific configuration.
|
|
126
|
+
*
|
|
127
|
+
* @param component - The component name to check
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```js
|
|
131
|
+
* const shouldSSR = await inertia.ssrEnabled('UserProfile')
|
|
132
|
+
* if (shouldSSR) {
|
|
133
|
+
* // Render on server
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
ssrEnabled<Page extends keyof Pages & string>(component: Page): Promise<boolean>;
|
|
138
|
+
/**
|
|
139
|
+
* Share props across all pages
|
|
140
|
+
*
|
|
141
|
+
* Merges the provided props with existing shared state, making them available
|
|
142
|
+
* to all pages rendered by this Inertia instance. Shared props are included
|
|
143
|
+
* in every page render alongside page-specific props.
|
|
144
|
+
*
|
|
145
|
+
* @param sharedState - Props to share across all pages
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```js
|
|
149
|
+
* // Share user data across all pages
|
|
150
|
+
* inertia.share({
|
|
151
|
+
* user: getCurrentUser(),
|
|
152
|
+
* flash: getFlashMessages()
|
|
153
|
+
* })
|
|
154
|
+
*
|
|
155
|
+
* // Chain multiple shares
|
|
156
|
+
* inertia
|
|
157
|
+
* .share({ currentUser: user })
|
|
158
|
+
* .share({ permissions: userPermissions })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
share(sharedState: PageProps): this;
|
|
162
|
+
/**
|
|
163
|
+
* Build a page object with processed props and metadata
|
|
164
|
+
*
|
|
165
|
+
* Creates the complete page object that will be sent to the client or used for SSR.
|
|
166
|
+
*
|
|
167
|
+
* @param page - The page component name
|
|
168
|
+
* @param pageProps - Props to pass to the page component
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```js
|
|
172
|
+
* const pageObject = await inertia.page('Dashboard', {
|
|
173
|
+
* user: { name: 'John' },
|
|
174
|
+
* posts: defer(() => getPosts())
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
page<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>): Promise<PageObject<Pages[Page]>>;
|
|
179
|
+
/**
|
|
180
|
+
* Render a page using Inertia
|
|
181
|
+
*
|
|
182
|
+
* This method handles three distinct rendering scenarios:
|
|
183
|
+
* 1. Inertia requests - Returns JSON page object for client-side navigation
|
|
184
|
+
* 2. Initial page loads with SSR - Returns HTML with server-rendered content
|
|
185
|
+
* 3. Initial page loads without SSR - Returns HTML for client-side hydration
|
|
186
|
+
*
|
|
187
|
+
* @param page - The page component name to render
|
|
188
|
+
* @param pageProps - Props to pass to the page component
|
|
189
|
+
* @param viewProps - Additional props to pass to the root view template
|
|
190
|
+
*
|
|
191
|
+
* @returns PageObject for Inertia requests, HTML string for initial page loads
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```js
|
|
195
|
+
* // For Inertia requests, returns PageObject
|
|
196
|
+
* const result = await inertia.render('Profile', {
|
|
197
|
+
* user: getCurrentUser(),
|
|
198
|
+
* posts: defer(() => getUserPosts())
|
|
199
|
+
* })
|
|
200
|
+
*
|
|
201
|
+
* // For initial page loads, returns HTML string
|
|
202
|
+
* const html = await inertia.render('Home', { welcome: 'Hello World' })
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
render<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>, viewProps?: Record<string, any>): Promise<string | PageObject<Pages[Page]>>;
|
|
206
|
+
/**
|
|
207
|
+
* Clear the browser history on the next navigation
|
|
208
|
+
*
|
|
209
|
+
* Instructs the client to clear the browser history stack when navigating.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```js
|
|
213
|
+
* inertia.clearHistory()
|
|
214
|
+
* return inertia.render('Dashboard', props)
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
clearHistory(): void;
|
|
218
|
+
/**
|
|
219
|
+
* Control whether browser history should be encrypted
|
|
220
|
+
*
|
|
221
|
+
* Enables or disables encryption of sensitive data in browser history.
|
|
222
|
+
*
|
|
223
|
+
* @param encrypt - Whether to encrypt history (defaults to true)
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```js
|
|
227
|
+
* // Enable encryption for sensitive pages
|
|
228
|
+
* inertia.encryptHistory(true)
|
|
229
|
+
*
|
|
230
|
+
* // Disable encryption for public pages
|
|
231
|
+
* inertia.encryptHistory(false)
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
encryptHistory(encrypt?: boolean): void;
|
|
235
|
+
/**
|
|
236
|
+
* Redirect to a different location
|
|
237
|
+
*
|
|
238
|
+
* Sets the appropriate headers to redirect the client to a new URL.
|
|
239
|
+
* Uses a 409 status code which Inertia.js interprets as a redirect instruction.
|
|
240
|
+
*
|
|
241
|
+
* @param url - The URL to redirect to
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```js
|
|
245
|
+
* // Redirect after login
|
|
246
|
+
* inertia.location('/dashboard')
|
|
247
|
+
*
|
|
248
|
+
* // Redirect with full URL
|
|
249
|
+
* inertia.location('https://example.com/external')
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
location(url: string): void;
|
|
253
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Vite } from '@adonisjs/vite';
|
|
2
|
+
import { type HttpContext } from '@adonisjs/core/http';
|
|
3
|
+
import { Inertia } from './inertia.ts';
|
|
4
|
+
import { type ComponentProps, type InertiaConfig } from './types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Manager class for managing Inertia instances
|
|
7
|
+
*
|
|
8
|
+
* Acts as a factory for creating Inertia instances with shared configuration
|
|
9
|
+
* and Vite integration.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* const manager = new InertiaManager(config, vite)
|
|
14
|
+
* const inertia = manager.createForRequest(ctx)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class InertiaManager {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new InertiaManager instance
|
|
21
|
+
*
|
|
22
|
+
* @param config - Inertia configuration object
|
|
23
|
+
* @param vite - Optional Vite instance for development mode and SSR
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* const manager = new InertiaManager({
|
|
28
|
+
* rootView: 'app',
|
|
29
|
+
* ssr: { enabled: true }
|
|
30
|
+
* }, vite)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
constructor(config: InertiaConfig, vite?: Vite);
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Inertia instance for a specific HTTP request
|
|
36
|
+
*
|
|
37
|
+
* @param ctx - HTTP context for the current request
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```js
|
|
41
|
+
* const inertia = manager.createForRequest(ctx)
|
|
42
|
+
* await inertia.render('Home', { user: ctx.auth.user })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
createForRequest<Pages extends Record<string, ComponentProps>>(ctx: HttpContext): Inertia<Pages>;
|
|
46
|
+
}
|
|
@@ -1,108 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import { type Inertia } from './inertia.js';
|
|
3
|
+
import type { ComponentProps, InertiaPages, PageProps } from './types.js';
|
|
4
|
+
declare module '@adonisjs/core/http' {
|
|
5
|
+
interface HttpContext {
|
|
6
|
+
inertia: Inertia<InertiaPages extends Record<string, ComponentProps> ? InertiaPages : never>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Base middleware class for handling Inertia.js requests
|
|
11
|
+
*
|
|
12
|
+
* This middleware handles the initialization of the Inertia instance,
|
|
13
|
+
* manages request headers, handles redirects for mutation methods,
|
|
14
|
+
* and implements asset versioning.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* export default class InertiaMiddleware extends BaseInertiaMiddleware {
|
|
19
|
+
* async share() {
|
|
20
|
+
* return {
|
|
21
|
+
* user: ctx.auth?.user
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
10
26
|
*/
|
|
11
|
-
|
|
12
|
-
#private;
|
|
13
|
-
protected ctx: HttpContext;
|
|
14
|
-
protected config: ResolvedConfig;
|
|
15
|
-
protected vite?: Vite | undefined;
|
|
16
|
-
constructor(ctx: HttpContext, config: ResolvedConfig, vite?: Vite | undefined);
|
|
17
|
-
/**
|
|
18
|
-
* Share data for the current request.
|
|
19
|
-
* This data will override any shared data defined in the config.
|
|
20
|
-
*/
|
|
21
|
-
share(data: Record<string, Data>): void;
|
|
22
|
-
/**
|
|
23
|
-
* Render a page using Inertia
|
|
24
|
-
*/
|
|
25
|
-
render<TPageProps extends Record<string, any> = {}, TViewProps extends Record<string, any> = {}>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject<TPageProps>>;
|
|
26
|
-
/**
|
|
27
|
-
* Clear history state.
|
|
28
|
-
*
|
|
29
|
-
* See https://v2.inertiajs.com/history-encryption#clearing-history
|
|
30
|
-
*/
|
|
31
|
-
clearHistory(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Encrypt history
|
|
34
|
-
*
|
|
35
|
-
* See https://v2.inertiajs.com/history-encryption
|
|
36
|
-
*/
|
|
37
|
-
encryptHistory(encrypt?: boolean): void;
|
|
27
|
+
export default abstract class BaseInertiaMiddleware {
|
|
38
28
|
/**
|
|
39
|
-
*
|
|
29
|
+
* Extract validation errors from the session and format them for Inertia
|
|
40
30
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
31
|
+
* Retrieves validation errors from the session flash messages and formats
|
|
32
|
+
* them according to Inertia's error bag conventions. Supports both simple
|
|
33
|
+
* error objects and error bags for multi-form scenarios.
|
|
43
34
|
*
|
|
44
|
-
*
|
|
35
|
+
* @param ctx - The HTTP context containing session data
|
|
36
|
+
* @returns Formatted validation errors, either as a simple object or error bags
|
|
45
37
|
*
|
|
46
|
-
* @
|
|
38
|
+
* @example
|
|
39
|
+
* ```js
|
|
40
|
+
* const errors = middleware.getValidationErrors(ctx)
|
|
41
|
+
* // Returns: { email: 'Email is required', password: 'Password too short' }
|
|
42
|
+
* // Or with error bags: { login: { email: 'Email is required' } }
|
|
43
|
+
* ```
|
|
47
44
|
*/
|
|
48
|
-
|
|
45
|
+
getValidationErrors(ctx: HttpContext): Record<string, string> | {
|
|
46
|
+
[errorBag: string]: Record<string, string>;
|
|
47
|
+
};
|
|
49
48
|
/**
|
|
50
|
-
*
|
|
49
|
+
* Share data with all Inertia pages
|
|
51
50
|
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
optional<T>(callback: () => MaybePromise<T>): OptionalProp<() => MaybePromise<T>>;
|
|
55
|
-
/**
|
|
56
|
-
* Create a mergeable prop
|
|
51
|
+
* This method should return an object containing data that will be
|
|
52
|
+
* available to all Inertia pages as props.
|
|
57
53
|
*
|
|
58
|
-
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* async share() {
|
|
57
|
+
* return {
|
|
58
|
+
* user: ctx.auth?.user,
|
|
59
|
+
* flash: ctx.session?.flashMessages.all()
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
59
63
|
*/
|
|
60
|
-
|
|
64
|
+
abstract share?(ctx: HttpContext): PageProps | Promise<PageProps>;
|
|
61
65
|
/**
|
|
62
|
-
*
|
|
66
|
+
* Initialize the Inertia instance for the current request
|
|
63
67
|
*
|
|
64
|
-
*
|
|
65
|
-
* request
|
|
68
|
+
* This method creates an Inertia instance and attaches it to the
|
|
69
|
+
* HTTP context, making it available throughout the request lifecycle.
|
|
66
70
|
*
|
|
67
|
-
*
|
|
71
|
+
* @param ctx - The HTTP context object
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* await middleware.init(ctx)
|
|
76
|
+
* ```
|
|
68
77
|
*/
|
|
69
|
-
|
|
78
|
+
init(ctx: HttpContext): Promise<void>;
|
|
70
79
|
/**
|
|
71
|
-
*
|
|
80
|
+
* Clean up and finalize the Inertia response
|
|
72
81
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
82
|
+
* This method handles the final processing of Inertia requests including:
|
|
83
|
+
* - Setting appropriate response headers
|
|
84
|
+
* - Handling redirects for mutation methods (PUT/PATCH/DELETE)
|
|
85
|
+
* - Managing asset versioning conflicts
|
|
75
86
|
*
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
defer<T>(callback: () => MaybePromise<T>, group?: string): DeferProp<() => MaybePromise<T>>;
|
|
79
|
-
/**
|
|
80
|
-
* This method can be used to redirect the user to an external website
|
|
81
|
-
* or even a non-inertia route of your application.
|
|
87
|
+
* @param ctx - The HTTP context object
|
|
82
88
|
*
|
|
83
|
-
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* await middleware.dispose(ctx)
|
|
92
|
+
* ```
|
|
84
93
|
*/
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* HttpContext augmentations
|
|
90
|
-
*/
|
|
91
|
-
declare module '@adonisjs/core/http' {
|
|
92
|
-
interface HttpContext {
|
|
93
|
-
inertia: Inertia;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Inertia middleware to handle the Inertia requests and
|
|
98
|
-
* set appropriate headers/status
|
|
99
|
-
*/
|
|
100
|
-
declare class InertiaMiddleware {
|
|
101
|
-
#private;
|
|
102
|
-
protected config: ResolvedConfig;
|
|
103
|
-
protected vite?: Vite | undefined;
|
|
104
|
-
constructor(config: ResolvedConfig, vite?: Vite | undefined);
|
|
105
|
-
handle(ctx: HttpContext, next: NextFn): Promise<void>;
|
|
94
|
+
dispose(ctx: HttpContext): void;
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
export { InertiaMiddleware as default };
|