@adonisjs/inertia 4.0.0-next.2 → 4.0.0-next.4

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.
@@ -13,11 +13,8 @@ type ExtractProps<T> = Omit<
13
13
  >`,
14
14
  react: `import type React from 'react'
15
15
 
16
- type ExtractProps<T> = T extends React.FC<infer Props>
17
- ? Props
18
- : T extends React.Component<infer Props>
19
- ? Props
20
- : never`
16
+ type ExtractProps<T> =
17
+ T extends React.FC<infer Props> ? Props : T extends React.Component<infer Props> ? Props : never`
21
18
  };
22
19
  var indexPages = function(config) {
23
20
  if (!SUPPORTED_FRAMEWORKS.includes(config.framework)) {
@@ -26,14 +23,29 @@ var indexPages = function(config) {
26
23
  );
27
24
  }
28
25
  return {
26
+ /**
27
+ * Executes the page indexing process to generate TypeScript definitions.
28
+ *
29
+ * @param _ - Unused first parameter (assembler context)
30
+ * @param indexGenerator - The index generator instance used to register the pages type generation
31
+ */
29
32
  run(_, indexGenerator) {
30
33
  indexGenerator.add("inertiaPages", {
31
34
  source: "inertia/pages",
32
35
  glob: GLOB[config.framework],
33
36
  output: ".adonisjs/server/pages.d.ts",
37
+ /**
38
+ * Generates the TypeScript module declaration for Inertia pages.
39
+ *
40
+ * @param vfs - Virtual file system containing the scanned page files
41
+ * @param buffer - Buffer instance for writing the generated TypeScript code
42
+ * @param __ - Unused third parameter
43
+ * @param helpers - Helper utilities for path manipulation and imports
44
+ */
34
45
  as(vfs, buffer, __, helpers) {
35
46
  const filesList = vfs.asList();
36
- buffer.write(TYPES_EXTRACTION_HELPER[config.framework]);
47
+ buffer.writeLine(`import '@adonisjs/inertia/types'`);
48
+ buffer.writeLine(TYPES_EXTRACTION_HELPER[config.framework]);
37
49
  buffer.write(`declare module '@adonisjs/inertia/types' {`).indent();
38
50
  buffer.write(`export interface InertiaPages {`).indent();
39
51
  Object.keys(filesList).forEach((key) => {
@@ -1,9 +1,9 @@
1
- import {
2
- debug_default
3
- } from "./chunk-4EZ2J6OA.js";
4
1
  import {
5
2
  InertiaHeaders
6
3
  } from "./chunk-DISC5OYC.js";
4
+ import {
5
+ debug_default
6
+ } from "./chunk-4EZ2J6OA.js";
7
7
  import {
8
8
  __export
9
9
  } from "./chunk-MLKGABMK.js";
@@ -79,10 +79,10 @@ function isAlwaysProp(propValue) {
79
79
  function isOptionalProp(propValue) {
80
80
  return OPTIONAL_PROP in propValue;
81
81
  }
82
- async function unpackPropValue(value) {
83
- return serialize(value);
82
+ async function unpackPropValue(value, containerResolver) {
83
+ return serialize(value, containerResolver);
84
84
  }
85
- async function buildStandardVisitProps(pageProps) {
85
+ async function buildStandardVisitProps(pageProps, containerResolver) {
86
86
  const mergeProps = [];
87
87
  const deepMergeProps = [];
88
88
  const newProps = {};
@@ -141,11 +141,11 @@ async function buildStandardVisitProps(pageProps) {
141
141
  await Promise.all(
142
142
  unpackedValues.map(async ({ key, value }) => {
143
143
  if (typeof value === "function") {
144
- return Promise.resolve(value()).then((r) => unpackPropValue(r)).then((jsonValue) => {
144
+ return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
145
145
  newProps[key] = jsonValue;
146
146
  });
147
147
  } else {
148
- return unpackPropValue(value).then((jsonValue) => {
148
+ return unpackPropValue(value, containerResolver).then((jsonValue) => {
149
149
  newProps[key] = jsonValue;
150
150
  });
151
151
  }
@@ -158,7 +158,7 @@ async function buildStandardVisitProps(pageProps) {
158
158
  deferredProps
159
159
  };
160
160
  }
161
- async function buildPartialRequestProps(pageProps, cherryPickProps) {
161
+ async function buildPartialRequestProps(pageProps, cherryPickProps, containerResolver) {
162
162
  const mergeProps = [];
163
163
  const deepMergeProps = [];
164
164
  const newProps = {};
@@ -208,11 +208,11 @@ async function buildPartialRequestProps(pageProps, cherryPickProps) {
208
208
  await Promise.all(
209
209
  unpackedValues.map(async ({ key, value }) => {
210
210
  if (typeof value === "function") {
211
- return Promise.resolve(value()).then((r) => unpackPropValue(r)).then((jsonValue) => {
211
+ return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
212
212
  newProps[key] = jsonValue;
213
213
  });
214
214
  } else {
215
- return unpackPropValue(value).then((jsonValue) => {
215
+ return unpackPropValue(value, containerResolver).then((jsonValue) => {
216
216
  newProps[key] = jsonValue;
217
217
  });
218
218
  }
@@ -367,10 +367,10 @@ var Inertia = class {
367
367
  });
368
368
  debug_default("building props for a partial reload %O", requestInfo);
369
369
  debug_default("cherry picking props %s", cherryPickProps);
370
- return buildPartialRequestProps(finalProps, cherryPickProps);
370
+ return buildPartialRequestProps(finalProps, cherryPickProps, this.ctx.containerResolver);
371
371
  }
372
372
  debug_default("building props for a standard visit %O", requestInfo);
373
- return buildStandardVisitProps(finalProps);
373
+ return buildStandardVisitProps(finalProps, this.ctx.containerResolver);
374
374
  }
375
375
  /**
376
376
  * Handle Inertia request by setting headers and returning page object
@@ -447,7 +447,7 @@ var Inertia = class {
447
447
  return this.#cachedVersion;
448
448
  }
449
449
  if (this.#vite?.hasManifestFile) {
450
- this.#cachedVersion = createHash("md5").update(JSON.stringify(this.#vite.manifest)).digest("hex");
450
+ this.#cachedVersion = createHash("md5").update(JSON.stringify(this.#vite.manifest())).digest("hex");
451
451
  } else {
452
452
  this.#cachedVersion = "1";
453
453
  }
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  defineConfig
3
- } from "../chunk-PDP56GPP.js";
3
+ } from "../chunk-PJU4O2LR.js";
4
4
  import {
5
5
  Inertia,
6
6
  ServerRenderer
7
- } from "../chunk-GO6QSFRS.js";
8
- import "../chunk-4EZ2J6OA.js";
7
+ } from "../chunk-XFUDVODO.js";
9
8
  import {
10
9
  InertiaHeaders
11
10
  } from "../chunk-DISC5OYC.js";
11
+ import "../chunk-4EZ2J6OA.js";
12
12
  import "../chunk-MLKGABMK.js";
13
13
 
14
14
  // factories/inertia_factory.ts
package/build/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  defineConfig,
3
3
  indexPages
4
- } from "./chunk-PDP56GPP.js";
4
+ } from "./chunk-PJU4O2LR.js";
5
5
  import {
6
6
  Inertia,
7
7
  InertiaManager,
8
8
  ServerRenderer,
9
9
  symbols_exports
10
- } from "./chunk-GO6QSFRS.js";
11
- import "./chunk-4EZ2J6OA.js";
10
+ } from "./chunk-XFUDVODO.js";
12
11
  import {
13
12
  InertiaHeaders
14
13
  } from "./chunk-DISC5OYC.js";
14
+ import "./chunk-4EZ2J6OA.js";
15
15
  import "./chunk-MLKGABMK.js";
16
16
  export {
17
17
  Inertia,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  InertiaManager
3
- } from "../chunk-GO6QSFRS.js";
4
- import "../chunk-4EZ2J6OA.js";
3
+ } from "../chunk-XFUDVODO.js";
5
4
  import "../chunk-DISC5OYC.js";
5
+ import "../chunk-4EZ2J6OA.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
 
8
8
  // providers/inertia_provider.ts
@@ -22,4 +22,4 @@
22
22
  *
23
23
  * @throws {Error} When none of the provided paths can be resolved in the pages registry
24
24
  */
25
- export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
25
+ export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>) | T>): Promise<T>;
@@ -1,5 +1,29 @@
1
+ /**
2
+ * Creates an AdonisJS assembler hook to automatically generate TypeScript definitions
3
+ * for Inertia.js pages based on the specified framework.
4
+ *
5
+ * This function scans page components in the 'inertia/pages' directory and generates
6
+ * type definitions that map page names to their component props.
7
+ *
8
+ * @param config - Configuration object specifying the frontend framework
9
+ * @param config.framework - The frontend framework ('vue3' or 'react')
10
+ *
11
+ * @example
12
+ * // In your adonisrc.ts file
13
+ * export default defineConfig({
14
+ * assembler: {
15
+ * onBuildStarting: [indexPages({ framework: 'vue3' })]
16
+ * }
17
+ * })
18
+ */
1
19
  export declare const indexPages: (config: {
2
20
  framework: "vue3" | "react";
3
21
  }) => {
22
+ /**
23
+ * Executes the page indexing process to generate TypeScript definitions.
24
+ *
25
+ * @param _ - Unused first parameter (assembler context)
26
+ * @param indexGenerator - The index generator instance used to register the pages type generation
27
+ */
4
28
  run(_: import("@adonisjs/assembler").DevServer | import("@adonisjs/assembler").TestRunner | import("@adonisjs/assembler").Bundler, indexGenerator: import("@adonisjs/assembler/index_generator").IndexGenerator): void;
5
29
  };
@@ -23,7 +23,7 @@ import { defer, merge, always, optional, deepMerge } from './props.ts';
23
23
  * inertia.location('/dashboard')
24
24
  * ```
25
25
  */
26
- export declare class Inertia<Pages extends Record<string, ComponentProps>> {
26
+ export declare class Inertia<Pages> {
27
27
  #private;
28
28
  protected ctx: HttpContext;
29
29
  protected config: InertiaConfig;
@@ -175,7 +175,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
175
175
  * })
176
176
  * ```
177
177
  */
178
- page<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>): Promise<PageObject<Pages[Page]>>;
178
+ page<Page extends keyof Pages & string>(page: Page, pageProps: Pages[Page] extends ComponentProps ? AsPageProps<Pages[Page]> : never): Promise<PageObject<Pages[Page]>>;
179
179
  /**
180
180
  * Render a page using Inertia
181
181
  *
@@ -202,7 +202,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
202
202
  * const html = await inertia.render('Home', { welcome: 'Hello World' })
203
203
  * ```
204
204
  */
205
- render<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>, viewProps?: Record<string, any>): Promise<string | PageObject<Pages[Page]>>;
205
+ render<Page extends keyof Pages & string>(page: Page, pageProps: Pages[Page] extends ComponentProps ? AsPageProps<Pages[Page]> : never, viewProps?: Record<string, any>): Promise<string | PageObject<Pages[Page]>>;
206
206
  /**
207
207
  * Clear the browser history on the next navigation
208
208
  *
@@ -1,9 +1,9 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import { type Inertia } from './inertia.js';
3
- import type { ComponentProps, InertiaPages, PageProps } from './types.js';
3
+ import type { InertiaPages, PageProps } from './types.js';
4
4
  declare module '@adonisjs/core/http' {
5
5
  interface HttpContext {
6
- inertia: Inertia<InertiaPages extends Record<string, ComponentProps> ? InertiaPages : never>;
6
+ inertia: Inertia<InertiaPages>;
7
7
  }
8
8
  }
9
9
  /**
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  InertiaManager
3
- } from "../chunk-GO6QSFRS.js";
4
- import {
5
- debug_default
6
- } from "../chunk-4EZ2J6OA.js";
3
+ } from "../chunk-XFUDVODO.js";
7
4
  import {
8
5
  InertiaHeaders
9
6
  } from "../chunk-DISC5OYC.js";
7
+ import {
8
+ debug_default
9
+ } from "../chunk-4EZ2J6OA.js";
10
10
  import "../chunk-MLKGABMK.js";
11
11
 
12
12
  // src/inertia_middleware.ts
@@ -1,5 +1,6 @@
1
1
  import { type AsyncOrSync } from '@poppinss/utils/types';
2
2
  import { type DeferProp, type PageProps, type AlwaysProp, type OptionalProp, type MergeableProp, type ComponentProps, type UnPackedPageProps } from './types.ts';
3
+ import { type ContainerResolver } from '@adonisjs/core/container';
3
4
  /**
4
5
  * Creates a deferred prop that is never included in standard visits but must be shared with
5
6
  * the client during standard visits. Can be explicitly requested and supports merging.
@@ -230,7 +231,7 @@ export declare function isOptionalProp<T extends UnPackedPageProps>(propValue: O
230
231
  * // Returns: { props: { user: {...} }, deferredProps: { default: ['posts'] }, mergeProps: ['settings'] }
231
232
  * ```
232
233
  */
233
- export declare function buildStandardVisitProps(pageProps: PageProps): Promise<{
234
+ export declare function buildStandardVisitProps(pageProps: PageProps, containerResolver: ContainerResolver<any>): Promise<{
234
235
  props: ComponentProps;
235
236
  mergeProps: string[];
236
237
  deepMergeProps: string[];
@@ -261,7 +262,7 @@ export declare function buildStandardVisitProps(pageProps: PageProps): Promise<{
261
262
  * // Returns: { props: { posts: [...], stats: [...] }, mergeProps: [], deferredProps: {} }
262
263
  * ```
263
264
  */
264
- export declare function buildPartialRequestProps(pageProps: PageProps, cherryPickProps: string[]): Promise<{
265
+ export declare function buildPartialRequestProps(pageProps: PageProps, cherryPickProps: string[], containerResolver: ContainerResolver<any>): Promise<{
265
266
  props: ComponentProps;
266
267
  mergeProps: string[];
267
268
  deepMergeProps: string[];
@@ -47,7 +47,7 @@ export declare class ServerRenderer {
47
47
  * const { head, body } = await renderer.render(pageObject)
48
48
  * ```
49
49
  */
50
- render(pageObject: PageObject): Promise<{
50
+ render(pageObject: PageObject<any>): Promise<{
51
51
  head: string[];
52
52
  body: string;
53
53
  }>;
@@ -290,7 +290,7 @@ export type InertiaConfigInput = DeepPartial<InertiaConfig>;
290
290
  *
291
291
  * @template Props - The props type for the page component
292
292
  */
293
- export type PageObject<Props extends PageProps = PageProps> = {
293
+ export type PageObject<Props> = {
294
294
  /**
295
295
  * The name/path of the component to render
296
296
  */
@@ -373,7 +373,7 @@ export interface InertiaPages {
373
373
  * @param page - The page object containing component and props data
374
374
  * @returns Promise resolving to an object with head tags and body HTML
375
375
  */
376
- export type RenderInertiaSsrApp = (page: PageObject) => Promise<{
376
+ export type RenderInertiaSsrApp = (page: PageObject<any>) => Promise<{
377
377
  head: string[];
378
378
  body: string;
379
379
  }>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "4.0.0-next.2",
4
+ "version": "4.0.0-next.4",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@adonisjs/assembler": "^8.0.0-next.9",
46
46
  "@adonisjs/core": "^7.0.0-next.1",
47
- "@adonisjs/eslint-config": "^3.0.0-next.1",
47
+ "@adonisjs/eslint-config": "^3.0.0-next.4",
48
48
  "@adonisjs/prettier-config": "^1.4.5",
49
49
  "@adonisjs/session": "^8.0.0-next.0",
50
50
  "@adonisjs/tsconfig": "^2.0.0-next.0",
@@ -58,21 +58,21 @@
58
58
  "@japa/snapshot": "^2.0.9",
59
59
  "@poppinss/ts-exec": "^1.4.1",
60
60
  "@release-it/conventional-changelog": "^10.0.1",
61
- "@types/node": "^24.3.1",
61
+ "@types/node": "^24.6.0",
62
62
  "@types/supertest": "^6.0.3",
63
63
  "c8": "^10.1.3",
64
64
  "copyfiles": "^2.4.1",
65
- "cross-env": "^10.0.0",
66
- "del-cli": "^6.0.0",
65
+ "cross-env": "^10.1.0",
66
+ "del-cli": "^7.0.0",
67
67
  "edge.js": "^6.3.0",
68
- "eslint": "^9.35.0",
68
+ "eslint": "^9.36.0",
69
69
  "get-port": "^7.1.0",
70
70
  "prettier": "^3.6.2",
71
- "release-it": "^19.0.4",
71
+ "release-it": "^19.0.5",
72
72
  "supertest": "^7.1.4",
73
73
  "tsup": "^8.5.0",
74
74
  "typescript": "~5.9.2",
75
- "vite": "^7.1.5"
75
+ "vite": "^7.1.7"
76
76
  },
77
77
  "dependencies": {
78
78
  "@poppinss/utils": "^7.0.0-next.3",