@adonisjs/inertia 4.0.0-next.9 → 4.0.0

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 (48) hide show
  1. package/build/commands/commands.json +1 -0
  2. package/build/commands/main.d.ts +4 -0
  3. package/build/commands/main.js +36 -0
  4. package/build/commands/make_page.d.ts +16 -0
  5. package/build/commands/make_page.js +47 -0
  6. package/build/debug-CBMTuPUm.js +3 -0
  7. package/build/define_config-O1Y9QfzM.js +57 -0
  8. package/build/factories/main.js +60 -172
  9. package/build/headers-DafWEpBh.js +11 -0
  10. package/build/index.js +5 -24
  11. package/build/inertia_manager-Ra2dhBKa.js +410 -0
  12. package/build/providers/inertia_provider.js +25 -79
  13. package/build/src/client/common.d.ts +27 -0
  14. package/build/src/client/helpers.js +11 -28
  15. package/build/src/client/react/context.d.ts +24 -0
  16. package/build/src/client/react/form.d.ts +76 -0
  17. package/build/src/client/react/index.d.ts +4 -0
  18. package/build/src/client/react/index.js +62 -0
  19. package/build/src/client/react/link.d.ts +59 -0
  20. package/build/src/client/react/router.d.ts +60 -0
  21. package/build/src/client/vite.js +19 -29
  22. package/build/src/client/vue/context.d.ts +23 -0
  23. package/build/src/client/vue/form.d.ts +69 -0
  24. package/build/src/client/vue/index.d.ts +4 -0
  25. package/build/src/client/vue/index.js +103 -0
  26. package/build/src/client/vue/link.d.ts +52 -0
  27. package/build/src/client/vue/router.d.ts +62 -0
  28. package/build/src/debug.d.ts +1 -1
  29. package/build/src/index_pages.d.ts +30 -1
  30. package/build/src/inertia_middleware.js +45 -111
  31. package/build/src/plugins/edge/plugin.js +49 -81
  32. package/build/src/plugins/japa/api_client.js +44 -59
  33. package/build/src/types.d.ts +14 -21
  34. package/build/src/types.js +1 -0
  35. package/build/stubs/make/page/react.stub +20 -0
  36. package/build/stubs/make/page/vue.stub +18 -0
  37. package/build/tests/commands/make_page.spec.d.ts +1 -0
  38. package/build/tests/helpers.d.ts +2 -2
  39. package/build/tests/react_components.spec.d.ts +1 -0
  40. package/build/tests/types/react.spec.d.ts +68 -0
  41. package/build/tests/types/vue.spec.d.ts +1 -0
  42. package/build/tsdown.config.d.ts +2 -0
  43. package/package.json +68 -57
  44. package/build/chunk-4EZ2J6OA.js +0 -7
  45. package/build/chunk-5QRJHXXQ.js +0 -91
  46. package/build/chunk-DISC5OYC.js +0 -46
  47. package/build/chunk-MLKGABMK.js +0 -9
  48. package/build/chunk-XXMTGYB5.js +0 -813
@@ -0,0 +1 @@
1
+ {"commands":[{"commandName":"make:page","description":"Create a new Inertia page component","help":"","namespace":"make","aliases":[],"flags":[{"name":"vue","flagName":"vue","required":false,"type":"boolean","description":"Create a Vue page component"},{"name":"react","flagName":"react","required":false,"type":"boolean","description":"Create a React page component"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the page component","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make_page.js"}],"version":1}
@@ -0,0 +1,4 @@
1
+ import { CommandMetaData, Command } from '@adonisjs/ace/types';
2
+
3
+ export function getMetaData(): Promise<CommandMetaData[]>
4
+ export function getCommand(metaData: CommandMetaData): Promise<Command | null>
@@ -0,0 +1,36 @@
1
+ import { readFile } from 'node:fs/promises'
2
+
3
+ /**
4
+ * In-memory cache of commands after they have been loaded
5
+ */
6
+ let commandsMetaData
7
+
8
+ /**
9
+ * Reads the commands from the "./commands.json" file. Since, the commands.json
10
+ * file is generated automatically, we do not have to validate its contents
11
+ */
12
+ export async function getMetaData() {
13
+ if (commandsMetaData) {
14
+ return commandsMetaData
15
+ }
16
+
17
+ const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
18
+ commandsMetaData = JSON.parse(commandsIndex).commands
19
+
20
+ return commandsMetaData
21
+ }
22
+
23
+ /**
24
+ * Imports the command by lookingup its path from the commands
25
+ * metadata
26
+ */
27
+ export async function getCommand(metaData) {
28
+ const commands = await getMetaData()
29
+ const command = commands.find(({ commandName }) => metaData.commandName === commandName)
30
+ if (!command) {
31
+ return null
32
+ }
33
+
34
+ const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
35
+ return commandConstructor
36
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ import type { CommandOptions } from '@adonisjs/core/types/ace';
3
+ export default class MakePage extends BaseCommand {
4
+ #private;
5
+ static commandName: string;
6
+ static description: string;
7
+ static options: CommandOptions;
8
+ name: string;
9
+ vue: boolean;
10
+ react: boolean;
11
+ /**
12
+ * Directory under which the inertia pages are stored
13
+ */
14
+ protected pagesDir: string;
15
+ run(): Promise<void>;
16
+ }
@@ -0,0 +1,47 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { BaseCommand, args, flags } from "@adonisjs/core/ace";
3
+ import { join } from "node:path";
4
+ function __decorate(decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ }
10
+ const stubsRoot = join(import.meta.dirname, "../stubs");
11
+ var MakePage = class extends BaseCommand {
12
+ static commandName = "make:page";
13
+ static description = "Create a new Inertia page component";
14
+ static options = { allowUnknownFlags: true };
15
+ pagesDir = "inertia/pages";
16
+ async #detectFramework() {
17
+ try {
18
+ const files = await readdir(this.app.makePath(this.pagesDir), { recursive: true });
19
+ const hasVue = files.some((file) => file.endsWith(".vue"));
20
+ const hasReact = files.some((file) => file.endsWith(".tsx") || file.endsWith(".jsx"));
21
+ if (hasVue && !hasReact) return "vue";
22
+ if (hasReact && !hasVue) return "react";
23
+ return null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ async #resolveFramework() {
29
+ if (this.vue) return "vue";
30
+ if (this.react) return "react";
31
+ const detected = await this.#detectFramework();
32
+ if (detected) return detected;
33
+ return this.prompt.choice("Select the frontend framework", ["vue", "react"]);
34
+ }
35
+ async run() {
36
+ const framework = await this.#resolveFramework();
37
+ await (await this.createCodemods()).makeUsingStub(stubsRoot, `make/page/${framework}.stub`, {
38
+ flags: this.parsed.flags,
39
+ pagesDir: this.pagesDir,
40
+ entity: this.app.generators.createEntity(this.name)
41
+ });
42
+ }
43
+ };
44
+ __decorate([args.string({ description: "Name of the page component" })], MakePage.prototype, "name", void 0);
45
+ __decorate([flags.boolean({ description: "Create a Vue page component" })], MakePage.prototype, "vue", void 0);
46
+ __decorate([flags.boolean({ description: "Create a React page component" })], MakePage.prototype, "react", void 0);
47
+ export { MakePage as default };
@@ -0,0 +1,3 @@
1
+ import { debuglog } from "node:util";
2
+ var debug_default = debuglog("adonisjs:inertia");
3
+ export { debug_default as t };
@@ -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 };
@@ -1,175 +1,63 @@
1
- import {
2
- defineConfig
3
- } from "../chunk-5QRJHXXQ.js";
4
- import {
5
- Inertia,
6
- ServerRenderer
7
- } from "../chunk-XXMTGYB5.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
1
+ import { n as ServerRenderer, r as Inertia } from "../inertia_manager-Ra2dhBKa.js";
2
+ import { t as InertiaHeaders } from "../headers-DafWEpBh.js";
3
+ import "../debug-CBMTuPUm.js";
4
+ import { t as defineConfig } from "../define_config-O1Y9QfzM.js";
5
+ import "../index.js";
15
6
  import { HttpContextFactory } from "@adonisjs/core/factories/http";
16
7
  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
8
+ #vite;
9
+ #parameters = {
10
+ ctx: new HttpContextFactory().create(),
11
+ config: defineConfig({})
12
+ };
13
+ constructor() {
14
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
15
+ }
16
+ merge(parameters) {
17
+ if (parameters.ctx) this.#parameters.ctx = parameters.ctx;
18
+ if (parameters.config) this.#parameters.config = defineConfig(parameters.config);
19
+ this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
20
+ return this;
21
+ }
22
+ withoutInertia() {
23
+ delete this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia];
24
+ return this;
25
+ }
26
+ partialReload(component) {
27
+ const self = this;
28
+ const request = this.#parameters.ctx.request;
29
+ request.request.headers[InertiaHeaders.PartialComponent] = component;
30
+ return {
31
+ only(props) {
32
+ request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
33
+ return this;
34
+ },
35
+ except(props) {
36
+ request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
37
+ return this;
38
+ },
39
+ reset(props) {
40
+ request.request.headers[InertiaHeaders.Reset] = props.join(",");
41
+ return this;
42
+ },
43
+ create() {
44
+ return self.create();
45
+ }
46
+ };
47
+ }
48
+ withVersion(version) {
49
+ this.#parameters.config = {
50
+ ...this.#parameters.config,
51
+ assetsVersion: version
52
+ };
53
+ return this;
54
+ }
55
+ withVite(options) {
56
+ this.#vite = options;
57
+ return this;
58
+ }
59
+ create() {
60
+ return new Inertia(this.#parameters.ctx, this.#parameters.config, this.#vite, this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0);
61
+ }
175
62
  };
63
+ 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-XXMTGYB5.js";
11
- import {
12
- InertiaHeaders
13
- } from "./chunk-DISC5OYC.js";
14
- import "./chunk-4EZ2J6OA.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-Ra2dhBKa.js";
2
+ import { t as InertiaHeaders } from "./headers-DafWEpBh.js";
3
+ import "./debug-CBMTuPUm.js";
4
+ import { n as indexPages, t as defineConfig } from "./define_config-O1Y9QfzM.js";
5
+ export { Inertia, InertiaHeaders, InertiaManager, ServerRenderer, defineConfig, indexPages, symbols_exports as symbols };