@adonisjs/inertia 4.0.0-next.5 → 4.0.0-next.6
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/build/{chunk-XFUDVODO.js → chunk-GLGCE7D6.js} +17 -3
- package/build/factories/main.js +1 -1
- package/build/index.js +1 -1
- package/build/providers/inertia_provider.js +1 -1
- package/build/src/client/helpers.d.ts +4 -2
- package/build/src/client/helpers.js +17 -3
- package/build/src/client/vite.d.ts +2 -0
- package/build/src/define_config.d.ts +1 -0
- package/build/src/index_pages.d.ts +3 -0
- package/build/src/inertia.d.ts +9 -2
- package/build/src/inertia_manager.d.ts +1 -0
- package/build/src/inertia_middleware.d.ts +4 -1
- package/build/src/inertia_middleware.js +1 -1
- package/build/src/props.d.ts +12 -6
- package/build/src/server_renderer.d.ts +1 -1
- package/package.json +1 -1
|
@@ -341,6 +341,8 @@ var Inertia = class {
|
|
|
341
341
|
* Resolve the root view template
|
|
342
342
|
*
|
|
343
343
|
* Handles both static strings and dynamic functions for the root view.
|
|
344
|
+
*
|
|
345
|
+
* @returns The resolved root view template name
|
|
344
346
|
*/
|
|
345
347
|
#resolveRootView() {
|
|
346
348
|
return typeof this.config.rootView === "function" ? this.config.rootView(this.ctx) : this.config.rootView;
|
|
@@ -353,6 +355,7 @@ var Inertia = class {
|
|
|
353
355
|
* @param component - The component name being rendered
|
|
354
356
|
* @param requestInfo - Information about the current request
|
|
355
357
|
* @param pageProps - Raw page props to be processed
|
|
358
|
+
* @returns Promise resolving to processed props object with metadata
|
|
356
359
|
*/
|
|
357
360
|
#buildPageProps(component, requestInfo, pageProps) {
|
|
358
361
|
const finalProps = { ...this.#sharedState, ...pageProps };
|
|
@@ -376,6 +379,7 @@ var Inertia = class {
|
|
|
376
379
|
* Handle Inertia request by setting headers and returning page object
|
|
377
380
|
*
|
|
378
381
|
* @param pageObject - The page object to return
|
|
382
|
+
* @returns The page object with appropriate headers set
|
|
379
383
|
*/
|
|
380
384
|
#handleInertiaRequest(pageObject) {
|
|
381
385
|
this.ctx.response.header(InertiaHeaders.Inertia, "true");
|
|
@@ -386,6 +390,7 @@ var Inertia = class {
|
|
|
386
390
|
*
|
|
387
391
|
* @param pageObject - The page object to render
|
|
388
392
|
* @param viewProps - Additional props to pass to the root view template
|
|
393
|
+
* @returns Promise resolving to the rendered HTML string
|
|
389
394
|
*/
|
|
390
395
|
async #renderWithSSR(pageObject, viewProps) {
|
|
391
396
|
if (!this.#serverRenderer) {
|
|
@@ -403,6 +408,7 @@ var Inertia = class {
|
|
|
403
408
|
*
|
|
404
409
|
* @param pageObject - The page object to render
|
|
405
410
|
* @param viewProps - Additional props to pass to the root view template
|
|
411
|
+
* @returns Promise resolving to the rendered HTML string
|
|
406
412
|
*/
|
|
407
413
|
async #renderClientSide(pageObject, viewProps) {
|
|
408
414
|
debug_default("rendering shell for SPA %O", pageObject);
|
|
@@ -413,6 +419,9 @@ var Inertia = class {
|
|
|
413
419
|
*
|
|
414
420
|
* Parses various Inertia headers to determine request type and props filtering.
|
|
415
421
|
*
|
|
422
|
+
* @param reCompute - Whether to recompute the request info instead of using cached version
|
|
423
|
+
* @returns The request information object containing Inertia-specific data
|
|
424
|
+
*
|
|
416
425
|
* @example
|
|
417
426
|
* ```js
|
|
418
427
|
* const info = inertia.requestInfo()
|
|
@@ -441,6 +450,8 @@ var Inertia = class {
|
|
|
441
450
|
* Compute and cache the assets version
|
|
442
451
|
*
|
|
443
452
|
* Uses Vite manifest hash when available, otherwise defaults to '1'.
|
|
453
|
+
*
|
|
454
|
+
* @returns The computed version string for asset versioning
|
|
444
455
|
*/
|
|
445
456
|
getVersion() {
|
|
446
457
|
if (this.#cachedVersion) {
|
|
@@ -459,6 +470,7 @@ var Inertia = class {
|
|
|
459
470
|
* Checks global SSR settings and component-specific configuration.
|
|
460
471
|
*
|
|
461
472
|
* @param component - The component name to check
|
|
473
|
+
* @returns Promise resolving to true if SSR is enabled for the component
|
|
462
474
|
*
|
|
463
475
|
* @example
|
|
464
476
|
* ```js
|
|
@@ -488,6 +500,7 @@ var Inertia = class {
|
|
|
488
500
|
* in every page render alongside page-specific props.
|
|
489
501
|
*
|
|
490
502
|
* @param sharedState - Props to share across all pages
|
|
503
|
+
* @returns The Inertia instance for method chaining
|
|
491
504
|
*
|
|
492
505
|
* @example
|
|
493
506
|
* ```js
|
|
@@ -514,6 +527,7 @@ var Inertia = class {
|
|
|
514
527
|
*
|
|
515
528
|
* @param page - The page component name
|
|
516
529
|
* @param pageProps - Props to pass to the page component
|
|
530
|
+
* @returns Promise resolving to the complete page object
|
|
517
531
|
*
|
|
518
532
|
* @example
|
|
519
533
|
* ```js
|
|
@@ -553,8 +567,7 @@ var Inertia = class {
|
|
|
553
567
|
* @param page - The page component name to render
|
|
554
568
|
* @param pageProps - Props to pass to the page component
|
|
555
569
|
* @param viewProps - Additional props to pass to the root view template
|
|
556
|
-
*
|
|
557
|
-
* @returns PageObject for Inertia requests, HTML string for initial page loads
|
|
570
|
+
* @returns Promise resolving to PageObject for Inertia requests, HTML string for initial page loads
|
|
558
571
|
*
|
|
559
572
|
* @example
|
|
560
573
|
* ```js
|
|
@@ -678,7 +691,7 @@ var ServerRenderer = class {
|
|
|
678
691
|
* @returns Promise resolving to an object with rendered head and body HTML
|
|
679
692
|
*
|
|
680
693
|
* @example
|
|
681
|
-
* ```
|
|
694
|
+
* ```js
|
|
682
695
|
* const pageObject = {
|
|
683
696
|
* component: 'Home',
|
|
684
697
|
* props: { user: { name: 'John' } },
|
|
@@ -741,6 +754,7 @@ var InertiaManager = class {
|
|
|
741
754
|
* Creates a new Inertia instance for a specific HTTP request
|
|
742
755
|
*
|
|
743
756
|
* @param ctx - HTTP context for the current request
|
|
757
|
+
* @returns A new Inertia instance configured for the given request
|
|
744
758
|
*
|
|
745
759
|
* @example
|
|
746
760
|
* ```js
|
package/build/factories/main.js
CHANGED
package/build/index.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param path - The page path(s) to resolve. Can be a single string or array of strings
|
|
7
7
|
* @param pages - Registry of page components where keys are paths and values are either promises or functions returning promises
|
|
8
|
+
* @param layout - Optional layout component to assign to the resolved page
|
|
9
|
+
* @returns Promise resolving to the page component
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```js
|
|
@@ -20,6 +22,6 @@
|
|
|
20
22
|
* })
|
|
21
23
|
* ```
|
|
22
24
|
*
|
|
23
|
-
* @throws
|
|
25
|
+
* @throws Error When none of the provided paths can be resolved in the pages registry
|
|
24
26
|
*/
|
|
25
|
-
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>) | T
|
|
27
|
+
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>) | T>, layout?: any): Promise<T>;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import "../../chunk-MLKGABMK.js";
|
|
2
2
|
|
|
3
3
|
// src/client/helpers.ts
|
|
4
|
-
async function resolvePageComponent(path, pages) {
|
|
4
|
+
async function resolvePageComponent(path, pages, layout) {
|
|
5
5
|
for (const p of Array.isArray(path) ? path : [path]) {
|
|
6
6
|
const page = pages[p];
|
|
7
7
|
if (typeof page === "undefined") {
|
|
8
8
|
continue;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const resolvedPage = await (typeof page === "function" ? page() : page);
|
|
11
|
+
if (!resolvedPage) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Invalid page exported from "${path}". Make sure to default export a function`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if ("default" in resolvedPage === false) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Invalid page exported from "${path}". Make sure to default export a function`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (layout && !resolvedPage.default.layout) {
|
|
22
|
+
resolvedPage.default.layout = layout;
|
|
23
|
+
}
|
|
24
|
+
return resolvedPage;
|
|
11
25
|
}
|
|
12
|
-
throw new Error(`Page not found: ${path}`);
|
|
26
|
+
throw new Error(`Page not found: "${path}"`);
|
|
13
27
|
}
|
|
14
28
|
export {
|
|
15
29
|
resolvePageComponent
|
|
@@ -6,6 +6,7 @@ import type { InertiaConfig, InertiaConfigInput } from './types.js';
|
|
|
6
6
|
* to create a complete Inertia configuration object.
|
|
7
7
|
*
|
|
8
8
|
* @param config - User configuration input to override defaults
|
|
9
|
+
* @returns Complete Inertia configuration object with defaults applied
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```js
|
|
@@ -7,14 +7,17 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @param config - Configuration object specifying the frontend framework
|
|
9
9
|
* @param config.framework - The frontend framework ('vue3' or 'react')
|
|
10
|
+
* @returns Assembler hook object with run method for generating page types
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
13
|
+
* ```js
|
|
12
14
|
* // In your adonisrc.ts file
|
|
13
15
|
* export default defineConfig({
|
|
14
16
|
* assembler: {
|
|
15
17
|
* onBuildStarting: [indexPages({ framework: 'vue3' })]
|
|
16
18
|
* }
|
|
17
19
|
* })
|
|
20
|
+
* ```
|
|
18
21
|
*/
|
|
19
22
|
export declare const indexPages: (config: {
|
|
20
23
|
framework: "vue3" | "react";
|
package/build/src/inertia.d.ts
CHANGED
|
@@ -104,6 +104,9 @@ export declare class Inertia<Pages> {
|
|
|
104
104
|
*
|
|
105
105
|
* Parses various Inertia headers to determine request type and props filtering.
|
|
106
106
|
*
|
|
107
|
+
* @param reCompute - Whether to recompute the request info instead of using cached version
|
|
108
|
+
* @returns The request information object containing Inertia-specific data
|
|
109
|
+
*
|
|
107
110
|
* @example
|
|
108
111
|
* ```js
|
|
109
112
|
* const info = inertia.requestInfo()
|
|
@@ -117,6 +120,8 @@ export declare class Inertia<Pages> {
|
|
|
117
120
|
* Compute and cache the assets version
|
|
118
121
|
*
|
|
119
122
|
* Uses Vite manifest hash when available, otherwise defaults to '1'.
|
|
123
|
+
*
|
|
124
|
+
* @returns The computed version string for asset versioning
|
|
120
125
|
*/
|
|
121
126
|
getVersion(): string;
|
|
122
127
|
/**
|
|
@@ -125,6 +130,7 @@ export declare class Inertia<Pages> {
|
|
|
125
130
|
* Checks global SSR settings and component-specific configuration.
|
|
126
131
|
*
|
|
127
132
|
* @param component - The component name to check
|
|
133
|
+
* @returns Promise resolving to true if SSR is enabled for the component
|
|
128
134
|
*
|
|
129
135
|
* @example
|
|
130
136
|
* ```js
|
|
@@ -143,6 +149,7 @@ export declare class Inertia<Pages> {
|
|
|
143
149
|
* in every page render alongside page-specific props.
|
|
144
150
|
*
|
|
145
151
|
* @param sharedState - Props to share across all pages
|
|
152
|
+
* @returns The Inertia instance for method chaining
|
|
146
153
|
*
|
|
147
154
|
* @example
|
|
148
155
|
* ```js
|
|
@@ -166,6 +173,7 @@ export declare class Inertia<Pages> {
|
|
|
166
173
|
*
|
|
167
174
|
* @param page - The page component name
|
|
168
175
|
* @param pageProps - Props to pass to the page component
|
|
176
|
+
* @returns Promise resolving to the complete page object
|
|
169
177
|
*
|
|
170
178
|
* @example
|
|
171
179
|
* ```js
|
|
@@ -187,8 +195,7 @@ export declare class Inertia<Pages> {
|
|
|
187
195
|
* @param page - The page component name to render
|
|
188
196
|
* @param pageProps - Props to pass to the page component
|
|
189
197
|
* @param viewProps - Additional props to pass to the root view template
|
|
190
|
-
*
|
|
191
|
-
* @returns PageObject for Inertia requests, HTML string for initial page loads
|
|
198
|
+
* @returns Promise resolving to PageObject for Inertia requests, HTML string for initial page loads
|
|
192
199
|
*
|
|
193
200
|
* @example
|
|
194
201
|
* ```js
|
|
@@ -51,8 +51,11 @@ export default abstract class BaseInertiaMiddleware {
|
|
|
51
51
|
* This method should return an object containing data that will be
|
|
52
52
|
* available to all Inertia pages as props.
|
|
53
53
|
*
|
|
54
|
+
* @param ctx - The HTTP context object
|
|
55
|
+
* @returns Props to share across all pages
|
|
56
|
+
*
|
|
54
57
|
* @example
|
|
55
|
-
* ```
|
|
58
|
+
* ```js
|
|
56
59
|
* async share() {
|
|
57
60
|
* return {
|
|
58
61
|
* user: ctx.auth?.user,
|
package/build/src/props.d.ts
CHANGED
|
@@ -139,9 +139,10 @@ export declare function deepMerge<T extends UnPackedPageProps | DeferProp<UnPack
|
|
|
139
139
|
* This function is useful for runtime type checking and conditional prop handling.
|
|
140
140
|
*
|
|
141
141
|
* @param propValue - The object to check for deferred prop characteristics
|
|
142
|
+
* @returns True if the prop value is a deferred prop
|
|
142
143
|
*
|
|
143
144
|
* @example
|
|
144
|
-
* ```
|
|
145
|
+
* ```js
|
|
145
146
|
* const prop = defer(() => ({ data: 'value' }))
|
|
146
147
|
*
|
|
147
148
|
* if (isDeferredProp(prop)) {
|
|
@@ -158,9 +159,10 @@ export declare function isDeferredProp<T extends UnPackedPageProps>(propValue: O
|
|
|
158
159
|
* existing props rather than replaced during updates.
|
|
159
160
|
*
|
|
160
161
|
* @param propValue - The object to check for mergeable prop characteristics
|
|
162
|
+
* @returns True if the prop value is a mergeable prop
|
|
161
163
|
*
|
|
162
164
|
* @example
|
|
163
|
-
* ```
|
|
165
|
+
* ```js
|
|
164
166
|
* const prop = merge({ items: [1, 2, 3] })
|
|
165
167
|
*
|
|
166
168
|
* if (isMergeableProp(prop)) {
|
|
@@ -177,9 +179,10 @@ export declare function isMergeableProp<T extends UnPackedPageProps | DeferProp<
|
|
|
177
179
|
* responses, regardless of cherry-picking or selective prop requests.
|
|
178
180
|
*
|
|
179
181
|
* @param propValue - The object to check for always prop characteristics
|
|
182
|
+
* @returns True if the prop value is an always prop
|
|
180
183
|
*
|
|
181
184
|
* @example
|
|
182
|
-
* ```
|
|
185
|
+
* ```js
|
|
183
186
|
* const prop = always({ userId: 123, permissions: ['read', 'write'] })
|
|
184
187
|
*
|
|
185
188
|
* if (isAlwaysProp(prop)) {
|
|
@@ -196,9 +199,10 @@ export declare function isAlwaysProp<T extends UnPackedPageProps>(propValue: Obj
|
|
|
196
199
|
* when explicitly requested by the client, never in standard visits.
|
|
197
200
|
*
|
|
198
201
|
* @param propValue - The object to check for optional prop characteristics
|
|
202
|
+
* @returns True if the prop value is an optional prop
|
|
199
203
|
*
|
|
200
204
|
* @example
|
|
201
|
-
* ```
|
|
205
|
+
* ```js
|
|
202
206
|
* const prop = optional(() => ({ detailedData: 'expensive computation' }))
|
|
203
207
|
*
|
|
204
208
|
* if (isOptionalProp(prop)) {
|
|
@@ -219,7 +223,8 @@ export declare function isOptionalProp<T extends UnPackedPageProps>(propValue: O
|
|
|
219
223
|
* - Regular props: Included normally
|
|
220
224
|
*
|
|
221
225
|
* @param pageProps - The page props to process
|
|
222
|
-
* @
|
|
226
|
+
* @param containerResolver - Container resolver for dependency injection
|
|
227
|
+
* @returns Promise resolving to object containing processed props, deferred props list, and merge props list
|
|
223
228
|
*
|
|
224
229
|
* @example
|
|
225
230
|
* ```js
|
|
@@ -251,7 +256,8 @@ export declare function buildStandardVisitProps(pageProps: PageProps, containerR
|
|
|
251
256
|
*
|
|
252
257
|
* @param pageProps - The page props to process
|
|
253
258
|
* @param cherryPickProps - Array of prop names to include
|
|
254
|
-
* @
|
|
259
|
+
* @param containerResolver - Container resolver for dependency injection
|
|
260
|
+
* @returns Promise resolving to object containing processed props and merge props list
|
|
255
261
|
*
|
|
256
262
|
* @example
|
|
257
263
|
* ```js
|