@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.
Files changed (81) hide show
  1. package/README.md +8 -5
  2. package/build/bin/test.d.ts +1 -0
  3. package/build/chunk-4EZ2J6OA.js +7 -0
  4. package/build/chunk-74S2VAL7.js +761 -0
  5. package/build/chunk-DISC5OYC.js +46 -0
  6. package/build/chunk-MLKGABMK.js +9 -0
  7. package/build/chunk-PDP56GPP.js +75 -0
  8. package/build/factories/inertia_factory.d.ts +137 -0
  9. package/build/factories/main.d.ts +1 -0
  10. package/build/factories/main.js +175 -0
  11. package/build/index.d.ts +7 -19
  12. package/build/index.js +21 -307
  13. package/build/providers/inertia_provider.d.ts +86 -13
  14. package/build/providers/inertia_provider.js +48 -18
  15. package/build/src/client/vite.d.ts +63 -0
  16. package/build/src/{plugins → client}/vite.js +9 -13
  17. package/build/src/debug.d.ts +22 -0
  18. package/build/src/define_config.d.ts +29 -0
  19. package/build/src/headers.d.ts +61 -0
  20. package/build/src/index_pages.d.ts +5 -0
  21. package/build/src/inertia.d.ts +253 -0
  22. package/build/src/inertia_manager.d.ts +46 -0
  23. package/build/src/inertia_middleware.d.ts +74 -87
  24. package/build/src/inertia_middleware.js +110 -3
  25. package/build/src/plugins/edge/plugin.d.ts +30 -6
  26. package/build/src/plugins/edge/plugin.js +13 -9
  27. package/build/src/plugins/edge/tags.d.ts +47 -0
  28. package/build/src/plugins/edge/utils.d.ts +26 -0
  29. package/build/src/plugins/japa/api_client.d.ts +136 -22
  30. package/build/src/plugins/japa/api_client.js +36 -48
  31. package/build/src/props.d.ts +269 -0
  32. package/build/src/server_renderer.d.ts +54 -0
  33. package/build/src/symbols.d.ts +25 -0
  34. package/build/src/types.d.ts +404 -4
  35. package/build/tests/helpers.d.ts +35 -0
  36. package/build/tests/index_pages.spec.d.ts +1 -0
  37. package/build/tests/inertia.spec.d.ts +1 -0
  38. package/build/tests/inertia_page.spec.d.ts +1 -0
  39. package/build/tests/middleware.spec.d.ts +1 -0
  40. package/build/tests/plugins/api_client.spec.d.ts +1 -0
  41. package/build/tests/plugins/edge.plugin.spec.d.ts +1 -0
  42. package/build/tests/provider.spec.d.ts +1 -0
  43. package/build/tests/types/shared_props.spec.d.ts +1 -0
  44. package/build/tests/types/to_component_props.spec.d.ts +1 -0
  45. package/build/tests/types/to_page_props.spec.d.ts +1 -0
  46. package/package.json +88 -71
  47. package/build/app.css.stub +0 -13
  48. package/build/chunk-W7TVEB4V.js +0 -412
  49. package/build/config.stub +0 -33
  50. package/build/react/app.tsx.stub +0 -38
  51. package/build/react/errors/not_found.tsx.stub +0 -14
  52. package/build/react/errors/server_error.tsx.stub +0 -14
  53. package/build/react/home.tsx.stub +0 -349
  54. package/build/react/root.edge.stub +0 -76
  55. package/build/react/ssr.tsx.stub +0 -17
  56. package/build/react/tsconfig.json.stub +0 -15
  57. package/build/solid/app.tsx.stub +0 -38
  58. package/build/solid/errors/not_found.tsx.stub +0 -14
  59. package/build/solid/errors/server_error.tsx.stub +0 -14
  60. package/build/solid/home.tsx.stub +0 -358
  61. package/build/solid/root.edge.stub +0 -73
  62. package/build/solid/ssr.tsx.stub +0 -19
  63. package/build/solid/tsconfig.json.stub +0 -16
  64. package/build/src/helpers.d.ts +0 -12
  65. package/build/src/helpers.js +0 -14
  66. package/build/src/plugins/vite.d.ts +0 -26
  67. package/build/svelte/app.ts.stub +0 -32
  68. package/build/svelte/errors/not_found.svelte.stub +0 -10
  69. package/build/svelte/errors/server_error.svelte.stub +0 -14
  70. package/build/svelte/home.svelte.stub +0 -339
  71. package/build/svelte/root.edge.stub +0 -75
  72. package/build/svelte/ssr.ts.stub +0 -19
  73. package/build/svelte/tsconfig.json.stub +0 -14
  74. package/build/types-DVqEHBD1.d.ts +0 -240
  75. package/build/vue/app.ts.stub +0 -41
  76. package/build/vue/errors/not_found.vue.stub +0 -10
  77. package/build/vue/errors/server_error.vue.stub +0 -14
  78. package/build/vue/home.vue.stub +0 -343
  79. package/build/vue/root.edge.stub +0 -75
  80. package/build/vue/ssr.ts.stub +0 -22
  81. package/build/vue/tsconfig.json.stub +0 -16
@@ -0,0 +1,46 @@
1
+ // src/headers.ts
2
+ var InertiaHeaders = {
3
+ /**
4
+ * Header to identify Inertia.js requests.
5
+ * Set to 'true' by Inertia.js client to indicate an Inertia request.
6
+ */
7
+ Inertia: "x-inertia",
8
+ /**
9
+ * Header to drop a prop from the merge and deep merge object.
10
+ */
11
+ Reset: "x-inertia-reset",
12
+ /**
13
+ * Header containing the current asset version.
14
+ * Used for cache busting - if versions don't match, Inertia performs a full page reload.
15
+ */
16
+ Version: "x-inertia-version",
17
+ /**
18
+ * Header containing the target URL for redirects.
19
+ * Used when the server wants to redirect to a different URL than the current request.
20
+ */
21
+ Location: "x-inertia-location",
22
+ /**
23
+ * Header specifying the error bag name for validation errors.
24
+ * Allows multiple forms on the same page to have separate error handling.
25
+ */
26
+ ErrorBag: "x-inertia-error-bag",
27
+ /**
28
+ * Header containing comma-separated list of props to include in partial data requests.
29
+ * Only the specified props will be returned in the response.
30
+ */
31
+ PartialOnly: "x-inertia-partial-data",
32
+ /**
33
+ * Header containing comma-separated list of props to exclude in partial data requests.
34
+ * All props except the specified ones will be returned in the response.
35
+ */
36
+ PartialExcept: "x-inertia-partial-except",
37
+ /**
38
+ * Header specifying the component name for partial reloads.
39
+ * Used to identify which component is being partially reloaded.
40
+ */
41
+ PartialComponent: "x-inertia-partial-component"
42
+ };
43
+
44
+ export {
45
+ InertiaHeaders
46
+ };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -0,0 +1,75 @@
1
+ // src/index_pages.ts
2
+ var GLOB = {
3
+ vue3: ["**/*.vue"],
4
+ react: ["**/*.ts", "**/*.tsx"]
5
+ };
6
+ var SUPPORTED_FRAMEWORKS = Object.keys(GLOB);
7
+ var TYPES_EXTRACTION_HELPER = {
8
+ vue3: `import type { VNodeProps, AllowedComponentProps, ComponentInstance } from 'vue'
9
+
10
+ type ExtractProps<T> = Omit<
11
+ ComponentInstance<T>['$props'][K],
12
+ keyof VNodeProps | keyof AllowedComponentProps
13
+ >`,
14
+ react: `import type React from 'react'
15
+
16
+ type ExtractProps<T> = T extends React.FC<infer Props>
17
+ ? Props
18
+ : T extends React.Component<infer Props>
19
+ ? Props
20
+ : never`
21
+ };
22
+ var indexPages = function(config) {
23
+ if (!SUPPORTED_FRAMEWORKS.includes(config.framework)) {
24
+ throw new Error(
25
+ `Unsupported framework "${config.framework}". Types generation is available only for ${SUPPORTED_FRAMEWORKS.join(",")}`
26
+ );
27
+ }
28
+ return {
29
+ run(_, indexGenerator) {
30
+ indexGenerator.add("inertiaPages", {
31
+ source: "inertia/pages",
32
+ glob: GLOB[config.framework],
33
+ output: ".adonisjs/server/pages.d.ts",
34
+ as(vfs, buffer, __, helpers) {
35
+ const filesList = vfs.asList();
36
+ buffer.write(TYPES_EXTRACTION_HELPER[config.framework]);
37
+ buffer.write(`declare module '@adonisjs/inertia/types' {`).indent();
38
+ buffer.write(`export interface InertiaPages {`).indent();
39
+ Object.keys(filesList).forEach((key) => {
40
+ buffer.write(
41
+ `'${key}': ExtractProps<(typeof import('${helpers.toImportPath(filesList[key])}'))['default']>`
42
+ );
43
+ });
44
+ buffer.dedent().write(`}`);
45
+ buffer.dedent().write(`}`);
46
+ }
47
+ });
48
+ }
49
+ };
50
+ };
51
+
52
+ // src/define_config.ts
53
+ import lodash from "@poppinss/utils/lodash";
54
+ function defineConfig(config) {
55
+ return lodash.merge(
56
+ {
57
+ rootView: "inertia_layout",
58
+ entrypoint: "inertia/app/app.ts",
59
+ history: {
60
+ encrypt: false
61
+ },
62
+ ssr: {
63
+ enabled: false,
64
+ bundle: "ssr/ssr.js",
65
+ entrypoint: "inertia/app/ssr.ts"
66
+ }
67
+ },
68
+ config
69
+ );
70
+ }
71
+
72
+ export {
73
+ indexPages,
74
+ defineConfig
75
+ };
@@ -0,0 +1,137 @@
1
+ import { type Vite } from '@adonisjs/vite';
2
+ import { type HttpContext } from '@adonisjs/core/http';
3
+ import { Inertia } from '../src/inertia.js';
4
+ import { type AssetsVersion, type InertiaConfig, type ComponentProps, type InertiaConfigInput } from '../src/types.js';
5
+ /**
6
+ * Parameters for configuring the Inertia factory
7
+ */
8
+ type FactoryParameters = {
9
+ /** HTTP context for the request */
10
+ ctx: HttpContext;
11
+ /** Inertia configuration object */
12
+ config: InertiaConfig;
13
+ };
14
+ /**
15
+ * Inertia factory to quickly create a new instance of Inertia
16
+ * for testing purposes
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const factory = new InertiaFactory()
21
+ * const inertia = factory
22
+ * .merge({ config: { ssr: { enabled: true } } })
23
+ * .withVersion('1.0.0')
24
+ * .create()
25
+ * ```
26
+ */
27
+ export declare class InertiaFactory<Pages extends Record<string, ComponentProps>> {
28
+ #private;
29
+ /**
30
+ * Creates a new InertiaFactory instance with default Inertia headers
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const factory = new InertiaFactory()
35
+ * ```
36
+ */
37
+ constructor();
38
+ /**
39
+ * Merges additional parameters into the factory configuration
40
+ *
41
+ * @param parameters - Partial factory parameters to merge
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * factory.merge({
46
+ * config: { ssr: { enabled: true } },
47
+ * ctx: customContext
48
+ * })
49
+ * ```
50
+ */
51
+ merge(parameters: Omit<Partial<FactoryParameters>, 'config'> & {
52
+ config?: InertiaConfigInput;
53
+ }): this;
54
+ /**
55
+ * Removes the X-Inertia header from the request headers
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const inertia = factory.withoutInertia().create()
60
+ * ```
61
+ */
62
+ withoutInertia(): this;
63
+ /**
64
+ * Configures the factory for partial reloads of a specific component
65
+ *
66
+ * @param component - Name of the component to partially reload
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const inertia = factory
71
+ * .partialReload('UserProfile')
72
+ * .only(['name', 'email'])
73
+ * .create()
74
+ * ```
75
+ */
76
+ partialReload<Page extends keyof Pages & string>(component: Page): {
77
+ /**
78
+ * Specifies which props to include in the partial reload
79
+ *
80
+ * @param props - Array of property names to include
81
+ */
82
+ only(props: string[]): /*elided*/ any;
83
+ /**
84
+ * Specifies which props to exclude from the partial reload
85
+ *
86
+ * @param props - Array of property names to exclude
87
+ */
88
+ except(props: string[]): /*elided*/ any;
89
+ /**
90
+ * Specifies which props should be reset during the partial reload
91
+ *
92
+ * @param props - Array of property names to reset
93
+ */
94
+ reset(props: string[]): /*elided*/ any;
95
+ /**
96
+ * Creates the Inertia instance with partial reload configuration
97
+ */
98
+ create(): Inertia<Pages>;
99
+ };
100
+ /**
101
+ * Sets the assets version for cache busting
102
+ *
103
+ * @param version - Version string or function for asset versioning
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * factory.withVersion('1.0.0')
108
+ * // or
109
+ * factory.withVersion(() => Date.now().toString())
110
+ * ```
111
+ */
112
+ withVersion(version: AssetsVersion): this;
113
+ /**
114
+ * Sets the Vite instance for asset handling
115
+ *
116
+ * @param options - Vite configuration object
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * factory.withVite(viteInstance)
121
+ * ```
122
+ */
123
+ withVite(options: Vite): this;
124
+ /**
125
+ * Creates a new Inertia instance with the configured parameters
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const inertia = factory
130
+ * .merge({ config: customConfig })
131
+ * .withVersion('1.0.0')
132
+ * .create()
133
+ * ```
134
+ */
135
+ create(): Inertia<Pages>;
136
+ }
137
+ export {};
@@ -0,0 +1 @@
1
+ export { InertiaFactory } from './inertia_factory.ts';
@@ -0,0 +1,175 @@
1
+ import {
2
+ defineConfig
3
+ } from "../chunk-PDP56GPP.js";
4
+ import {
5
+ Inertia,
6
+ ServerRenderer
7
+ } from "../chunk-74S2VAL7.js";
8
+ import {
9
+ InertiaHeaders
10
+ } from "../chunk-DISC5OYC.js";
11
+ import "../chunk-4EZ2J6OA.js";
12
+ import "../chunk-MLKGABMK.js";
13
+
14
+ // factories/inertia_factory.ts
15
+ import { HttpContextFactory } from "@adonisjs/core/factories/http";
16
+ var InertiaFactory = class {
17
+ /** Optional Vite instance for asset handling */
18
+ #vite;
19
+ /** Internal parameters for factory configuration */
20
+ #parameters = {
21
+ ctx: new HttpContextFactory().create(),
22
+ config: defineConfig({})
23
+ };
24
+ /**
25
+ * Creates a new InertiaFactory instance with default Inertia headers
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const factory = new InertiaFactory()
30
+ * ```
31
+ */
32
+ constructor() {
33
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
34
+ }
35
+ /**
36
+ * Merges additional parameters into the factory configuration
37
+ *
38
+ * @param parameters - Partial factory parameters to merge
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * factory.merge({
43
+ * config: { ssr: { enabled: true } },
44
+ * ctx: customContext
45
+ * })
46
+ * ```
47
+ */
48
+ merge(parameters) {
49
+ if (parameters.ctx) {
50
+ this.#parameters.ctx = parameters.ctx;
51
+ }
52
+ if (parameters.config) {
53
+ this.#parameters.config = defineConfig(parameters.config);
54
+ }
55
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
56
+ return this;
57
+ }
58
+ /**
59
+ * Removes the X-Inertia header from the request headers
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const inertia = factory.withoutInertia().create()
64
+ * ```
65
+ */
66
+ withoutInertia() {
67
+ delete this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia];
68
+ return this;
69
+ }
70
+ /**
71
+ * Configures the factory for partial reloads of a specific component
72
+ *
73
+ * @param component - Name of the component to partially reload
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const inertia = factory
78
+ * .partialReload('UserProfile')
79
+ * .only(['name', 'email'])
80
+ * .create()
81
+ * ```
82
+ */
83
+ partialReload(component) {
84
+ const self = this;
85
+ const request = this.#parameters.ctx.request;
86
+ request.request.headers[InertiaHeaders.PartialComponent] = component;
87
+ return {
88
+ /**
89
+ * Specifies which props to include in the partial reload
90
+ *
91
+ * @param props - Array of property names to include
92
+ */
93
+ only(props) {
94
+ request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
95
+ return this;
96
+ },
97
+ /**
98
+ * Specifies which props to exclude from the partial reload
99
+ *
100
+ * @param props - Array of property names to exclude
101
+ */
102
+ except(props) {
103
+ request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
104
+ return this;
105
+ },
106
+ /**
107
+ * Specifies which props should be reset during the partial reload
108
+ *
109
+ * @param props - Array of property names to reset
110
+ */
111
+ reset(props) {
112
+ request.request.headers[InertiaHeaders.Reset] = props.join(",");
113
+ return this;
114
+ },
115
+ /**
116
+ * Creates the Inertia instance with partial reload configuration
117
+ */
118
+ create() {
119
+ return self.create();
120
+ }
121
+ };
122
+ }
123
+ /**
124
+ * Sets the assets version for cache busting
125
+ *
126
+ * @param version - Version string or function for asset versioning
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * factory.withVersion('1.0.0')
131
+ * // or
132
+ * factory.withVersion(() => Date.now().toString())
133
+ * ```
134
+ */
135
+ withVersion(version) {
136
+ this.#parameters.config = { ...this.#parameters.config, assetsVersion: version };
137
+ return this;
138
+ }
139
+ /**
140
+ * Sets the Vite instance for asset handling
141
+ *
142
+ * @param options - Vite configuration object
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * factory.withVite(viteInstance)
147
+ * ```
148
+ */
149
+ withVite(options) {
150
+ this.#vite = options;
151
+ return this;
152
+ }
153
+ /**
154
+ * Creates a new Inertia instance with the configured parameters
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const inertia = factory
159
+ * .merge({ config: customConfig })
160
+ * .withVersion('1.0.0')
161
+ * .create()
162
+ * ```
163
+ */
164
+ create() {
165
+ return new Inertia(
166
+ this.#parameters.ctx,
167
+ this.#parameters.config,
168
+ this.#vite,
169
+ this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0
170
+ );
171
+ }
172
+ };
173
+ export {
174
+ InertiaFactory
175
+ };
package/build/index.d.ts CHANGED
@@ -1,19 +1,7 @@
1
- import Configure from '@adonisjs/core/commands/configure';
2
- import { ConfigProvider } from '@adonisjs/core/types';
3
- import { S as SharedData, I as InertiaConfig, R as ResolvedConfig } from './types-DVqEHBD1.js';
4
- import '@adonisjs/core/http';
5
- import '@tuyau/utils/types';
6
-
7
- /**
8
- * Configures the package
9
- */
10
- declare function configure(command: Configure): Promise<void>;
11
-
12
- /**
13
- * Define the Inertia configuration
14
- */
15
- declare function defineConfig<T extends SharedData>(config: InertiaConfig<T>): ConfigProvider<ResolvedConfig<T>>;
16
-
17
- declare const stubsRoot: string;
18
-
19
- export { configure, defineConfig, stubsRoot };
1
+ export { Inertia } from './src/inertia.ts';
2
+ export * as symbols from './src/symbols.ts';
3
+ export { InertiaHeaders } from './src/headers.ts';
4
+ export { indexPages } from './src/index_pages.ts';
5
+ export { defineConfig } from './src/define_config.js';
6
+ export { InertiaManager } from './src/inertia_manager.ts';
7
+ export { ServerRenderer } from './src/server_renderer.ts';