@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,269 @@
|
|
|
1
|
+
import { type AsyncOrSync } from '@poppinss/utils/types';
|
|
2
|
+
import { type DeferProp, type PageProps, type AlwaysProp, type OptionalProp, type MergeableProp, type ComponentProps, type UnPackedPageProps } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a deferred prop that is never included in standard visits but must be shared with
|
|
5
|
+
* the client during standard visits. Can be explicitly requested and supports merging.
|
|
6
|
+
*
|
|
7
|
+
* Deferred props are useful for expensive computations that should only be loaded when
|
|
8
|
+
* specifically requested by the client.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - Function that computes the prop value when requested
|
|
11
|
+
* @returns A deferred prop object with compute and merge capabilities
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* // Create a deferred prop for expensive user statistics
|
|
16
|
+
* const userStats = defer(() => {
|
|
17
|
+
* return calculateExpensiveUserStats(userId)
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* // Use in page props
|
|
21
|
+
* return inertia.render('dashboard', {
|
|
22
|
+
* user: user,
|
|
23
|
+
* stats: userStats // Only loaded when explicitly requested
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function defer<T extends UnPackedPageProps>(fn: () => AsyncOrSync<T>, group?: string): DeferProp<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates an optional prop that is never included in standard visits and can only be
|
|
30
|
+
* explicitly requested by the client. Unlike deferred props, optional props are not
|
|
31
|
+
* shared with the client during standard visits.
|
|
32
|
+
*
|
|
33
|
+
* Optional props are ideal for data that is rarely needed and should only be loaded
|
|
34
|
+
* on demand to optimize performance.
|
|
35
|
+
*
|
|
36
|
+
* @param fn - Function that computes the prop value when requested
|
|
37
|
+
* @returns An optional prop object that computes values lazily
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```javascript
|
|
41
|
+
* // Create an optional prop for detailed audit logs
|
|
42
|
+
* const auditLogs = optional(() => {
|
|
43
|
+
* return fetchDetailedAuditLogs(resourceId)
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* // Use in page props
|
|
47
|
+
* return inertia.render('resource/show', {
|
|
48
|
+
* resource: resource,
|
|
49
|
+
* auditLogs: auditLogs // Only loaded when explicitly requested
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function optional<T extends UnPackedPageProps>(fn: () => AsyncOrSync<T>): OptionalProp<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a prop that is always included in responses and cannot be removed during
|
|
56
|
+
* cherry-picking. This ensures the prop is always available to the frontend component.
|
|
57
|
+
*
|
|
58
|
+
* Always props are useful for critical data that the frontend component must have
|
|
59
|
+
* to function properly, regardless of what props are specifically requested.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to always include in the response
|
|
62
|
+
* @returns An always prop object that cannot be cherry-picked away
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```javascript
|
|
66
|
+
* // Create an always prop for critical user permissions
|
|
67
|
+
* const userPermissions = always(user.permissions)
|
|
68
|
+
*
|
|
69
|
+
* // Use in page props
|
|
70
|
+
* return inertia.render('admin/dashboard', {
|
|
71
|
+
* users: users,
|
|
72
|
+
* permissions: userPermissions // Always included, never filtered out
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function always<T extends UnPackedPageProps>(value: T): AlwaysProp<T>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a prop that should be merged with existing props on the page rather than
|
|
79
|
+
* replaced. This is useful for incremental updates where you want to combine new
|
|
80
|
+
* data with existing data on the client side.
|
|
81
|
+
*
|
|
82
|
+
* Mergeable props enable efficient partial updates by allowing the client to
|
|
83
|
+
* merge new prop values with existing ones instead of replacing them entirely.
|
|
84
|
+
*
|
|
85
|
+
* @param value - The value to be merged with existing props
|
|
86
|
+
* @returns A mergeable prop object marked for merging behavior
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```javascript
|
|
90
|
+
* // Create a mergeable prop for incremental notifications
|
|
91
|
+
* const newNotifications = merge([
|
|
92
|
+
* { id: 1, message: 'New message received' },
|
|
93
|
+
* { id: 2, message: 'Task completed' }
|
|
94
|
+
* ])
|
|
95
|
+
*
|
|
96
|
+
* // Use in page props - will merge with existing notifications
|
|
97
|
+
* return inertia.render('dashboard', {
|
|
98
|
+
* user: user,
|
|
99
|
+
* notifications: newNotifications // Merges with existing notifications array
|
|
100
|
+
* })
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function merge<T extends UnPackedPageProps | DeferProp<UnPackedPageProps>>(value: T): MergeableProp<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a prop that should be deeply merged with existing props on the page.
|
|
106
|
+
*
|
|
107
|
+
* Unlike shallow merge, deep merge recursively merges nested objects and arrays,
|
|
108
|
+
* allowing for more granular updates to complex data structures.
|
|
109
|
+
*
|
|
110
|
+
* @param value - The value to be deeply merged with existing props
|
|
111
|
+
* @returns A mergeable prop object marked for deep merging behavior
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```javascript
|
|
115
|
+
* // Create a deep mergeable prop for nested user settings
|
|
116
|
+
* const updatedSettings = deepMerge({
|
|
117
|
+
* notifications: {
|
|
118
|
+
* email: true,
|
|
119
|
+
* push: false
|
|
120
|
+
* },
|
|
121
|
+
* privacy: {
|
|
122
|
+
* profile: 'public'
|
|
123
|
+
* }
|
|
124
|
+
* })
|
|
125
|
+
*
|
|
126
|
+
* // Use in page props - will deeply merge with existing settings
|
|
127
|
+
* return inertia.render('settings', {
|
|
128
|
+
* user: user,
|
|
129
|
+
* settings: updatedSettings // Deep merges with existing settings object
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function deepMerge<T extends UnPackedPageProps | DeferProp<UnPackedPageProps>>(value: T): MergeableProp<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Type guard that checks if a prop value is a deferred prop.
|
|
136
|
+
*
|
|
137
|
+
* Deferred props contain the DEFERRED_PROP symbol and have compute/merge capabilities.
|
|
138
|
+
* This function is useful for runtime type checking and conditional prop handling.
|
|
139
|
+
*
|
|
140
|
+
* @param propValue - The object to check for deferred prop characteristics
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```javascript
|
|
144
|
+
* const prop = defer(() => ({ data: 'value' }))
|
|
145
|
+
*
|
|
146
|
+
* if (isDeferredProp(prop)) {
|
|
147
|
+
* // prop is now typed as DeferProp<T>
|
|
148
|
+
* const result = prop.compute()
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function isDeferredProp<T extends UnPackedPageProps>(propValue: Object): propValue is DeferProp<T>;
|
|
153
|
+
/**
|
|
154
|
+
* Type guard that checks if a prop value is a mergeable prop.
|
|
155
|
+
*
|
|
156
|
+
* Mergeable props contain the TO_BE_MERGED symbol and should be merged with
|
|
157
|
+
* existing props rather than replaced during updates.
|
|
158
|
+
*
|
|
159
|
+
* @param propValue - The object to check for mergeable prop characteristics
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```javascript
|
|
163
|
+
* const prop = merge({ items: [1, 2, 3] })
|
|
164
|
+
*
|
|
165
|
+
* if (isMergeableProp(prop)) {
|
|
166
|
+
* // prop is now typed as MergeableProp<T>
|
|
167
|
+
* const value = prop.value
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare function isMergeableProp<T extends UnPackedPageProps | DeferProp<UnPackedPageProps>>(propValue: Object): propValue is MergeableProp<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Type guard that checks if a prop value is an always prop.
|
|
174
|
+
*
|
|
175
|
+
* Always props contain the ALWAYS_PROP symbol and are always included in
|
|
176
|
+
* responses, regardless of cherry-picking or selective prop requests.
|
|
177
|
+
*
|
|
178
|
+
* @param propValue - The object to check for always prop characteristics
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```javascript
|
|
182
|
+
* const prop = always({ userId: 123, permissions: ['read', 'write'] })
|
|
183
|
+
*
|
|
184
|
+
* if (isAlwaysProp(prop)) {
|
|
185
|
+
* // prop is now typed as AlwaysProp<T>
|
|
186
|
+
* const value = prop.value
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare function isAlwaysProp<T extends UnPackedPageProps>(propValue: Object): propValue is AlwaysProp<T>;
|
|
191
|
+
/**
|
|
192
|
+
* Type guard that checks if a prop value is an optional prop.
|
|
193
|
+
*
|
|
194
|
+
* Optional props contain the OPTIONAL_PROP symbol and are only included
|
|
195
|
+
* when explicitly requested by the client, never in standard visits.
|
|
196
|
+
*
|
|
197
|
+
* @param propValue - The object to check for optional prop characteristics
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```javascript
|
|
201
|
+
* const prop = optional(() => ({ detailedData: 'expensive computation' }))
|
|
202
|
+
*
|
|
203
|
+
* if (isOptionalProp(prop)) {
|
|
204
|
+
* // prop is now typed as OptionalProp<T>
|
|
205
|
+
* const result = prop.compute()
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function isOptionalProp<T extends UnPackedPageProps>(propValue: Object): propValue is OptionalProp<T>;
|
|
210
|
+
/**
|
|
211
|
+
* Builds props for standard (non-partial) Inertia visits.
|
|
212
|
+
*
|
|
213
|
+
* This function processes page props and categorizes them based on their type:
|
|
214
|
+
* - Deferred props: Skipped but communicated to client
|
|
215
|
+
* - Optional props: Skipped entirely
|
|
216
|
+
* - Always props: Always included
|
|
217
|
+
* - Mergeable props: Included and marked for merging
|
|
218
|
+
* - Regular props: Included normally
|
|
219
|
+
*
|
|
220
|
+
* @param pageProps - The page props to process
|
|
221
|
+
* @returns Object containing processed props, deferred props list, and merge props list
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```js
|
|
225
|
+
* const result = await buildStandardVisitProps({
|
|
226
|
+
* user: { name: 'John' },
|
|
227
|
+
* posts: defer(() => getPosts()),
|
|
228
|
+
* settings: merge({ theme: 'dark' })
|
|
229
|
+
* })
|
|
230
|
+
* // Returns: { props: { user: {...} }, deferredProps: { default: ['posts'] }, mergeProps: ['settings'] }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare function buildStandardVisitProps(pageProps: PageProps): Promise<{
|
|
234
|
+
props: ComponentProps;
|
|
235
|
+
mergeProps: string[];
|
|
236
|
+
deepMergeProps: string[];
|
|
237
|
+
deferredProps: {
|
|
238
|
+
[group: string]: string[];
|
|
239
|
+
};
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Builds props for partial (cherry-picked) Inertia requests.
|
|
243
|
+
*
|
|
244
|
+
* This function processes page props for partial requests where only specific
|
|
245
|
+
* props are requested. It handles:
|
|
246
|
+
* - Always props: Always included regardless of cherry picking
|
|
247
|
+
* - Cherry-picked props: Only included if in the cherryPickProps list
|
|
248
|
+
* - Mergeable props: Included and marked for merging
|
|
249
|
+
* - Regular props: Included if cherry-picked
|
|
250
|
+
*
|
|
251
|
+
* @param pageProps - The page props to process
|
|
252
|
+
* @param cherryPickProps - Array of prop names to include
|
|
253
|
+
* @returns Object containing processed props and merge props list
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```js
|
|
257
|
+
* const result = await buildPartialRequestProps(
|
|
258
|
+
* { user: { name: 'John' }, posts: defer(() => getPosts()), stats: optional(() => getStats()) },
|
|
259
|
+
* ['posts', 'stats']
|
|
260
|
+
* )
|
|
261
|
+
* // Returns: { props: { posts: [...], stats: [...] }, mergeProps: [], deferredProps: {} }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare function buildPartialRequestProps(pageProps: PageProps, cherryPickProps: string[]): Promise<{
|
|
265
|
+
props: ComponentProps;
|
|
266
|
+
mergeProps: string[];
|
|
267
|
+
deepMergeProps: string[];
|
|
268
|
+
deferredProps: {};
|
|
269
|
+
}>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Vite } from '@adonisjs/vite';
|
|
2
|
+
import type { PageObject, InertiaConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Server-side renderer for Inertia.js applications.
|
|
5
|
+
*
|
|
6
|
+
* Handles rendering Inertia pages on the server using either Vite's development
|
|
7
|
+
* runtime API or production SSR bundles.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const renderer = new ServerRenderer(config, vite)
|
|
12
|
+
* const { head, body } = await renderer.render(pageObject)
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class ServerRenderer {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new ServerRenderer instance.
|
|
19
|
+
*
|
|
20
|
+
* @param config - Inertia configuration object containing SSR settings
|
|
21
|
+
* @param vite - Vite instance for development mode rendering and asset management
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* const renderer = new ServerRenderer(config, vite)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
constructor(config: InertiaConfig, vite: Vite);
|
|
29
|
+
/**
|
|
30
|
+
* Renders an Inertia page on the server.
|
|
31
|
+
*
|
|
32
|
+
* In development mode, uses Vite's Runtime API to execute the SSR entrypoint.
|
|
33
|
+
* In production mode, imports and uses the pre-built SSR bundle.
|
|
34
|
+
*
|
|
35
|
+
* @param pageObject - The Inertia page object containing component, props, and metadata
|
|
36
|
+
* @returns Promise resolving to an object with rendered head and body HTML
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const pageObject = {
|
|
41
|
+
* component: 'Home',
|
|
42
|
+
* props: { user: { name: 'John' } },
|
|
43
|
+
* url: '/dashboard',
|
|
44
|
+
* version: '1.0.0'
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const { head, body } = await renderer.render(pageObject)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
render(pageObject: PageObject): Promise<{
|
|
51
|
+
head: string[];
|
|
52
|
+
body: string;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol used to mark props that should always be included in responses.
|
|
3
|
+
* Props marked with this symbol cannot be filtered out during cherry-picking.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ALWAYS_PROP: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Symbol used to mark props that are optional and only included when explicitly requested.
|
|
8
|
+
* These props are never included in standard visits and must be cherry-picked.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPTIONAL_PROP: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Symbol used to mark props that should be merged with existing props on the client.
|
|
13
|
+
* Props marked with this symbol will be merged rather than replaced during updates.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TO_BE_MERGED: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* Symbol used to mark props that are deferred and computed lazily.
|
|
18
|
+
* These props are skipped in standard visits but communicated to the client for potential loading.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFERRED_PROP: unique symbol;
|
|
21
|
+
/**
|
|
22
|
+
* Symbol used to indicate that a mergeable prop should use deep merging behavior.
|
|
23
|
+
* Deep merging recursively merges nested objects and arrays.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEEP_MERGE: unique symbol;
|