@adonisjs/inertia 4.0.0-next.10 → 4.0.0-next.12

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.
@@ -0,0 +1,3 @@
1
+ import { debuglog } from "node:util";
2
+ var debug_default = debuglog("adonisjs:inertia");
3
+ export { debug_default as t };
@@ -1,175 +1,62 @@
1
- import {
2
- defineConfig
3
- } from "../chunk-5QRJHXXQ.js";
4
- import {
5
- Inertia,
6
- ServerRenderer
7
- } from "../chunk-YQ72YL64.js";
8
- import "../chunk-4EZ2J6OA.js";
9
- import {
10
- InertiaHeaders
11
- } from "../chunk-DISC5OYC.js";
12
- import "../chunk-MLKGABMK.js";
13
-
14
- // factories/inertia_factory.ts
1
+ import { n as ServerRenderer, r as Inertia } from "../inertia_manager-Di3J3hSG.js";
2
+ import { t as InertiaHeaders } from "../headers-DafWEpBh.js";
3
+ import "../debug-CBMTuPUm.js";
4
+ import { t as defineConfig } from "../inertia-D5A2KtfR.js";
15
5
  import { HttpContextFactory } from "@adonisjs/core/factories/http";
16
6
  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
7
+ #vite;
8
+ #parameters = {
9
+ ctx: new HttpContextFactory().create(),
10
+ config: defineConfig({})
11
+ };
12
+ constructor() {
13
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
14
+ }
15
+ merge(parameters) {
16
+ if (parameters.ctx) this.#parameters.ctx = parameters.ctx;
17
+ if (parameters.config) this.#parameters.config = defineConfig(parameters.config);
18
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
19
+ return this;
20
+ }
21
+ withoutInertia() {
22
+ delete this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia];
23
+ return this;
24
+ }
25
+ partialReload(component) {
26
+ const self = this;
27
+ const request = this.#parameters.ctx.request;
28
+ request.request.headers[InertiaHeaders.PartialComponent] = component;
29
+ return {
30
+ only(props) {
31
+ request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
32
+ return this;
33
+ },
34
+ except(props) {
35
+ request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
36
+ return this;
37
+ },
38
+ reset(props) {
39
+ request.request.headers[InertiaHeaders.Reset] = props.join(",");
40
+ return this;
41
+ },
42
+ create() {
43
+ return self.create();
44
+ }
45
+ };
46
+ }
47
+ withVersion(version) {
48
+ this.#parameters.config = {
49
+ ...this.#parameters.config,
50
+ assetsVersion: version
51
+ };
52
+ return this;
53
+ }
54
+ withVite(options) {
55
+ this.#vite = options;
56
+ return this;
57
+ }
58
+ create() {
59
+ return new Inertia(this.#parameters.ctx, this.#parameters.config, this.#vite, this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0);
60
+ }
175
61
  };
62
+ export { InertiaFactory };
@@ -0,0 +1,11 @@
1
+ const InertiaHeaders = {
2
+ Inertia: "x-inertia",
3
+ Reset: "x-inertia-reset",
4
+ Version: "x-inertia-version",
5
+ Location: "x-inertia-location",
6
+ ErrorBag: "x-inertia-error-bag",
7
+ PartialOnly: "x-inertia-partial-data",
8
+ PartialExcept: "x-inertia-partial-except",
9
+ PartialComponent: "x-inertia-partial-component"
10
+ };
11
+ export { InertiaHeaders as t };
package/build/index.js CHANGED
@@ -1,24 +1,5 @@
1
- import {
2
- defineConfig,
3
- indexPages
4
- } from "./chunk-5QRJHXXQ.js";
5
- import {
6
- Inertia,
7
- InertiaManager,
8
- ServerRenderer,
9
- symbols_exports
10
- } from "./chunk-YQ72YL64.js";
11
- import "./chunk-4EZ2J6OA.js";
12
- import {
13
- InertiaHeaders
14
- } from "./chunk-DISC5OYC.js";
15
- import "./chunk-MLKGABMK.js";
16
- export {
17
- Inertia,
18
- InertiaHeaders,
19
- InertiaManager,
20
- ServerRenderer,
21
- defineConfig,
22
- indexPages,
23
- symbols_exports as symbols
24
- };
1
+ import { i as symbols_exports, n as ServerRenderer, r as Inertia, t as InertiaManager } from "./inertia_manager-Di3J3hSG.js";
2
+ import { t as InertiaHeaders } from "./headers-DafWEpBh.js";
3
+ import "./debug-CBMTuPUm.js";
4
+ import { n as indexPages, t as defineConfig } from "./inertia-D5A2KtfR.js";
5
+ export { Inertia, InertiaHeaders, InertiaManager, ServerRenderer, defineConfig, indexPages, symbols_exports as symbols };
@@ -0,0 +1,57 @@
1
+ import lodash from "@poppinss/utils/lodash";
2
+ const GLOB = {
3
+ vue3: ["**/*.vue"],
4
+ react: ["**/*.ts", "**/*.tsx"]
5
+ };
6
+ const SUPPORTED_FRAMEWORKS = Object.keys(GLOB);
7
+ const TYPES_EXTRACTION_HELPER = {
8
+ vue3: `import type { VNodeProps, AllowedComponentProps, ComponentInstance } from 'vue'
9
+
10
+ type ExtractProps<T> = Omit<
11
+ ComponentInstance<T>['$props'],
12
+ keyof VNodeProps | keyof AllowedComponentProps
13
+ >`,
14
+ react: `import type React from 'react'
15
+ import type { Prettify } from '@adonisjs/core/types/common'
16
+
17
+ type ExtractProps<T> =
18
+ T extends React.FC<infer Props>
19
+ ? Prettify<Omit<Props, 'children'>>
20
+ : T extends React.Component<infer Props>
21
+ ? Prettify<Omit<Props, 'children'>>
22
+ : never`
23
+ };
24
+ const indexPages = function(config) {
25
+ if (!SUPPORTED_FRAMEWORKS.includes(config.framework)) throw new Error(`Unsupported framework "${config.framework}". Types generation is available only for ${SUPPORTED_FRAMEWORKS.join(",")}`);
26
+ return { run(_, indexGenerator) {
27
+ indexGenerator.add("inertiaPages", {
28
+ source: "inertia/pages",
29
+ glob: GLOB[config.framework],
30
+ output: ".adonisjs/server/pages.d.ts",
31
+ as(vfs, buffer, __, helpers) {
32
+ const filesList = vfs.asList();
33
+ buffer.writeLine(`import '@adonisjs/inertia/types'`);
34
+ buffer.writeLine(TYPES_EXTRACTION_HELPER[config.framework]);
35
+ buffer.write(`declare module '@adonisjs/inertia/types' {`).indent();
36
+ buffer.write(`export interface InertiaPages {`).indent();
37
+ Object.keys(filesList).forEach((key) => {
38
+ buffer.write(`'${key}': ExtractProps<(typeof import('${helpers.toImportPath(filesList[key])}'))['default']>`);
39
+ });
40
+ buffer.dedent().write(`}`);
41
+ buffer.dedent().write(`}`);
42
+ }
43
+ });
44
+ } };
45
+ };
46
+ function defineConfig(config) {
47
+ return lodash.merge({
48
+ rootView: "inertia_layout",
49
+ history: { encrypt: false },
50
+ ssr: {
51
+ enabled: false,
52
+ bundle: "ssr/ssr.js",
53
+ entrypoint: "inertia/ssr.tsx"
54
+ }
55
+ }, config);
56
+ }
57
+ export { indexPages as n, defineConfig as t };