@adonisjs/inertia 1.0.0-9 → 1.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 (46) hide show
  1. package/README.md +3 -3
  2. package/build/app.css.stub +1 -1
  3. package/build/{chunk-CXICUKHN.js → chunk-QKSM72AR.js} +59 -23
  4. package/build/config.stub +10 -2
  5. package/build/index.d.ts +7 -3
  6. package/build/index.js +140 -38
  7. package/build/providers/inertia_provider.d.ts +15 -1
  8. package/build/providers/inertia_provider.js +13 -2
  9. package/build/react/app.tsx.stub +19 -6
  10. package/build/react/errors/not_found.tsx.stub +14 -0
  11. package/build/react/errors/server_error.tsx.stub +14 -0
  12. package/build/react/home.tsx.stub +2 -2
  13. package/build/react/root.edge.stub +2 -2
  14. package/build/react/ssr.tsx.stub +17 -0
  15. package/build/react/tsconfig.json.stub +5 -15
  16. package/build/solid/app.tsx.stub +19 -5
  17. package/build/solid/errors/not_found.tsx.stub +14 -0
  18. package/build/solid/errors/server_error.tsx.stub +14 -0
  19. package/build/solid/home.tsx.stub +2 -5
  20. package/build/solid/root.edge.stub +2 -2
  21. package/build/solid/ssr.tsx.stub +19 -0
  22. package/build/solid/tsconfig.json.stub +6 -16
  23. package/build/src/helpers.d.ts +12 -0
  24. package/build/src/helpers.js +14 -0
  25. package/build/src/inertia_middleware.d.ts +5 -51
  26. package/build/src/inertia_middleware.js +1 -1
  27. package/build/src/plugins/japa/api_client.d.ts +3 -1
  28. package/build/src/plugins/vite.d.ts +1 -1
  29. package/build/src/plugins/vite.js +5 -2
  30. package/build/src/types.d.ts +5 -96
  31. package/build/svelte/app.ts.stub +33 -0
  32. package/build/svelte/errors/not_found.svelte.stub +10 -0
  33. package/build/svelte/errors/server_error.svelte.stub +14 -0
  34. package/build/svelte/home.svelte.stub +19 -0
  35. package/build/svelte/root.edge.stub +21 -0
  36. package/build/svelte/ssr.ts.stub +15 -0
  37. package/build/svelte/tsconfig.json.stub +14 -0
  38. package/build/types-fb05P61I.d.ts +203 -0
  39. package/build/vue/app.ts.stub +18 -4
  40. package/build/vue/errors/not_found.vue.stub +10 -0
  41. package/build/vue/errors/server_error.vue.stub +14 -0
  42. package/build/vue/home.vue.stub +4 -4
  43. package/build/vue/root.edge.stub +2 -2
  44. package/build/vue/ssr.ts.stub +22 -0
  45. package/build/vue/tsconfig.json.stub +5 -15
  46. package/package.json +52 -42
@@ -0,0 +1,203 @@
1
+ import { ConfigProvider } from '@adonisjs/core/types';
2
+ import { HttpContext } from '@adonisjs/core/http';
3
+ import { Simplify, Serialize } from '@tuyau/utils/types';
4
+ import { Vite } from '@adonisjs/vite';
5
+
6
+ /**
7
+ * Symbol used to identify lazy props
8
+ */
9
+ declare const kLazySymbol: unique symbol;
10
+ /**
11
+ * Main class used to interact with Inertia
12
+ */
13
+ declare class Inertia {
14
+ #private;
15
+ protected ctx: HttpContext;
16
+ protected config: ResolvedConfig;
17
+ protected vite?: Vite | undefined;
18
+ constructor(ctx: HttpContext, config: ResolvedConfig, vite?: Vite | undefined);
19
+ /**
20
+ * Share data for the current request.
21
+ * This data will override any shared data defined in the config.
22
+ */
23
+ share(data: Record<string, Data>): void;
24
+ /**
25
+ * Render a page using Inertia
26
+ */
27
+ render<TPageProps extends Record<string, any> = {}, TViewProps extends Record<string, any> = {}>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject<TPageProps>>;
28
+ /**
29
+ * Create a lazy prop
30
+ *
31
+ * Lazy props are never resolved on first visit, but only when the client
32
+ * request a partial reload explicitely with this value.
33
+ *
34
+ * See https://inertiajs.com/partial-reloads#lazy-data-evaluation
35
+ */
36
+ lazy<T>(callback: () => MaybePromise<T>): {
37
+ [kLazySymbol]: () => MaybePromise<T>;
38
+ };
39
+ /**
40
+ * This method can be used to redirect the user to an external website
41
+ * or even a non-inertia route of your application.
42
+ *
43
+ * See https://inertiajs.com/redirects#external-redirects
44
+ */
45
+ location(url: string): Promise<void>;
46
+ }
47
+
48
+ /**
49
+ * VersionCache is used to cache the version of the assets.
50
+ *
51
+ * If the user has provided a version, it will be used.
52
+ * Otherwise, we will compute a hash from the manifest file
53
+ * and cache it.
54
+ */
55
+ declare class VersionCache {
56
+ #private;
57
+ protected appRoot: URL;
58
+ protected assetsVersion?: AssetsVersion;
59
+ constructor(appRoot: URL, assetsVersion?: AssetsVersion);
60
+ /**
61
+ * Pre-compute the version
62
+ */
63
+ computeVersion(): Promise<this>;
64
+ /**
65
+ * Returns the current assets version
66
+ */
67
+ getVersion(): string | number;
68
+ /**
69
+ * Set the assets version
70
+ */
71
+ setVersion(version: AssetsVersion): Promise<void>;
72
+ }
73
+
74
+ type MaybePromise<T> = T | Promise<T>;
75
+ /**
76
+ * Props that will be passed to inertia render method
77
+ */
78
+ type PageProps = Record<string, unknown>;
79
+ /**
80
+ * Shared data types
81
+ */
82
+ type Data = string | number | object | boolean;
83
+ type SharedDatumFactory = (ctx: HttpContext) => MaybePromise<Data>;
84
+ type SharedData = Record<string, Data | SharedDatumFactory>;
85
+ /**
86
+ * Allowed values for the assets version
87
+ */
88
+ type AssetsVersion = string | number | undefined;
89
+ interface InertiaConfig<T extends SharedData = SharedData> {
90
+ /**
91
+ * Path to the Edge view that will be used as the root view for Inertia responses.
92
+ * @default root (resources/views/inertia_layout.edge)
93
+ */
94
+ rootView?: string | ((ctx: HttpContext) => string);
95
+ /**
96
+ * Path to your client-side entrypoint file.
97
+ */
98
+ entrypoint?: string;
99
+ /**
100
+ * The version of your assets. Every client request will be checked against this version.
101
+ * If the version is not the same, the client will do a full reload.
102
+ */
103
+ assetsVersion?: AssetsVersion;
104
+ /**
105
+ * Data that should be shared with all rendered pages
106
+ */
107
+ sharedData?: T;
108
+ /**
109
+ * Options to configure SSR
110
+ */
111
+ ssr?: {
112
+ /**
113
+ * Enable or disable SSR
114
+ */
115
+ enabled: boolean;
116
+ /**
117
+ * List of components that should be rendered on the server
118
+ */
119
+ pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
120
+ /**
121
+ * Path to the SSR entrypoint file
122
+ */
123
+ entrypoint?: string;
124
+ /**
125
+ * Path to the SSR bundled file that will be used in production
126
+ */
127
+ bundle?: string;
128
+ };
129
+ }
130
+ /**
131
+ * Resolved inertia configuration
132
+ */
133
+ interface ResolvedConfig<T extends SharedData = SharedData> {
134
+ rootView: string | ((ctx: HttpContext) => string);
135
+ versionCache: VersionCache;
136
+ sharedData: T;
137
+ ssr: {
138
+ enabled: boolean;
139
+ entrypoint: string;
140
+ pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
141
+ bundle: string;
142
+ };
143
+ }
144
+ interface PageObject<TPageProps extends PageProps = PageProps> {
145
+ component: string;
146
+ version: string | number;
147
+ props: TPageProps;
148
+ url: string;
149
+ ssrHead?: string;
150
+ ssrBody?: string;
151
+ }
152
+ type IsLazyProp<T> = T extends {
153
+ [kLazySymbol]: () => MaybePromise<any>;
154
+ } ? true : false;
155
+ type InferProps<T> = {
156
+ [K in keyof T as IsLazyProp<T[K]> extends true ? K : never]+?: T[K] extends {
157
+ [kLazySymbol]: () => MaybePromise<infer U>;
158
+ } ? U : T[K];
159
+ } & {
160
+ [K in keyof T as IsLazyProp<T[K]> extends true ? never : K]: T[K];
161
+ };
162
+ type ReturnsTypesSharedData<T extends SharedData> = {} extends T ? {} : {
163
+ [K in keyof T]: T[K] extends (...args: any[]) => MaybePromise<infer U> ? U : T[K];
164
+ };
165
+ /**
166
+ * Infer shared data types from the config provider
167
+ */
168
+ type InferSharedProps<T extends ConfigProvider<ResolvedConfig>> = ReturnsTypesSharedData<Awaited<ReturnType<T['resolver']>>['sharedData']>;
169
+ /**
170
+ * The shared props inferred from the user config user-land.
171
+ * Should be module augmented by the user
172
+ */
173
+ interface SharedProps {
174
+ }
175
+ /**
176
+ * Helper for infering the page props from a Controller method that returns
177
+ * inertia.render
178
+ *
179
+ * InferPageProps will also include the shared props
180
+ *
181
+ * ```ts
182
+ * // Your Adonis Controller
183
+ * class MyController {
184
+ * index() {
185
+ * return inertia.render('foo', { foo: 1 })
186
+ * }
187
+ * }
188
+ *
189
+ * // Your React component
190
+ * export default MyReactComponent(props: InferPageProps<Controller, 'index'>) {
191
+ * }
192
+ * ```
193
+ */
194
+ type InferPageProps<Controller, Method extends keyof Controller> = Controller[Method] extends (...args: any[]) => any ? Simplify<Serialize<InferProps<Exclude<Awaited<ReturnType<Controller[Method]>>, string>['props']> & SharedProps>> : never;
195
+ /**
196
+ * Signature for the method in the SSR entrypoint file
197
+ */
198
+ type RenderInertiaSsrApp = (page: PageObject) => Promise<{
199
+ head: string[];
200
+ body: string;
201
+ }>;
202
+
203
+ export { type AssetsVersion as A, type Data as D, type InertiaConfig as I, type MaybePromise as M, type PageProps as P, type ResolvedConfig as R, type SharedData as S, Inertia as a, type SharedDatumFactory as b, type PageObject as c, type InferSharedProps as d, type SharedProps as e, type InferPageProps as f, type RenderInertiaSsrApp as g };
@@ -1,11 +1,19 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/app.ts') })
2
+ exports({ to: app.makePath('inertia/app/app.ts') })
3
3
  }}}
4
- import './css/app.css';
4
+ /// <reference path="../../adonisrc.ts" />
5
+ /// <reference path="../../config/inertia.ts" />
5
6
 
7
+ import '../css/app.css';
8
+
9
+ {{#if ssr}}
10
+ import { createSSRApp, h } from 'vue'
11
+ {{#else}}
6
12
  import { createApp, h } from 'vue'
13
+ {{/if}}
7
14
  import type { DefineComponent } from 'vue'
8
15
  import { createInertiaApp } from '@inertiajs/vue3'
16
+ import { resolvePageComponent } from '@adonisjs/inertia/helpers'
9
17
 
10
18
  const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
11
19
 
@@ -15,12 +23,18 @@ createInertiaApp({
15
23
  title: (title) => {{ '`${title} - ${appName}`' }},
16
24
 
17
25
  resolve: (name) => {
18
- const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
19
- {{ 'return pages[`./pages/${name}.vue`]' }}
26
+ return resolvePageComponent(
27
+ {{ '`../pages/${name}.vue`' }},
28
+ import.meta.glob<DefineComponent>('../pages/**/*.vue'),
29
+ )
20
30
  },
21
31
 
22
32
  setup({ el, App, props, plugin }) {
33
+ {{#if ssr}}
34
+ createSSRApp({ render: () => h(App, props) })
35
+ {{#else}}
23
36
  createApp({ render: () => h(App, props) })
37
+ {{/if}}
24
38
  .use(plugin)
25
39
  .mount(el)
26
40
  },
@@ -0,0 +1,10 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/not_found.vue') })
3
+ }}}
4
+ <template>
5
+ <div class="container">
6
+ <div class="title">Page not found</div>
7
+
8
+ <span>This page does not exist.</span>
9
+ </div>
10
+ </template>
@@ -0,0 +1,14 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/pages/errors/server_error.vue') })
3
+ }}}
4
+ <script setup lang="ts">
5
+ defineProps<{ error: any }>();
6
+ </script>
7
+
8
+ <template>
9
+ <div class="container">
10
+ <div class="title">Server Error</div>
11
+
12
+ <span>\{\{ error.message \}\}</span>
13
+ </div>
14
+ </template>
@@ -1,5 +1,5 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/pages/home.vue') })
2
+ exports({ to: app.makePath('inertia/pages/home.vue') })
3
3
  }}}
4
4
  <script setup lang="ts">
5
5
  import { Head } from '@inertiajs/vue3'
@@ -10,12 +10,12 @@ defineProps<{ version: number }>()
10
10
  <template>
11
11
  <Head title="Homepage" />
12
12
 
13
- <div className="container">
14
- <div className="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
13
+ <div class="container">
14
+ <div class="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
15
15
 
16
16
  <span>
17
17
  Learn more about AdonisJS and Inertia.js by visiting the
18
- <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
18
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
19
19
  </span>
20
20
  </div>
21
21
  </template>
@@ -1,5 +1,5 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/views/root.edge') })
2
+ exports({ to: app.makePath('resources/views/inertia_layout.edge') })
3
3
  }}}
4
4
  <!DOCTYPE html>
5
5
  <html>
@@ -10,7 +10,7 @@
10
10
 
11
11
  <title inertia>AdonisJS x Inertia x VueJS</title>
12
12
 
13
- @vite(['resources/app.ts'])
13
+ {{ "@vite(['inertia/app/app.ts', `inertia/pages/${page.component}.vue`])" }}
14
14
  @inertiaHead()
15
15
  </head>
16
16
 
@@ -0,0 +1,22 @@
1
+ {{{
2
+ exports({ to: app.makePath('inertia/app/ssr.ts') })
3
+ }}}
4
+
5
+ import { createInertiaApp } from '@inertiajs/vue3'
6
+ import { renderToString } from '@vue/server-renderer'
7
+ import { createSSRApp, h, type DefineComponent } from 'vue'
8
+
9
+ export default function render(page: any) {
10
+ return createInertiaApp({
11
+ page,
12
+ render: renderToString,
13
+ resolve: (name) => {
14
+ const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', { eager: true })
15
+ {{ 'return pages[`../pages/${name}.vue`]' }}
16
+ },
17
+
18
+ setup({ App, props, plugin }) {
19
+ return createSSRApp({ render: () => h(App, props) }).use(plugin)
20
+ },
21
+ })
22
+ }
@@ -1,26 +1,16 @@
1
1
  {{{
2
- exports({ to: app.makePath('resources/tsconfig.json') })
2
+ exports({ to: app.makePath('inertia/tsconfig.json') })
3
3
  }}}
4
4
  {
5
+ "extends": "@adonisjs/tsconfig/tsconfig.client.json",
5
6
  "compilerOptions": {
6
- "target": "ESNext",
7
- "jsx": "preserve",
8
- "jsxImportSource": "vue",
9
- "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
- "useDefineForClassFields": true,
11
7
  "baseUrl": ".",
8
+ "jsx": "preserve",
12
9
  "module": "ESNext",
13
- "moduleResolution": "Bundler",
10
+ "jsxImportSource": "vue",
14
11
  "paths": {
15
- "@/*": ["./*"],
16
- "~/*": ["../*"],
12
+ "~/*": ["./*"],
17
13
  },
18
- "resolveJsonModule": true,
19
- "types": ["vite/client"],
20
- "allowSyntheticDefaultImports": true,
21
- "esModuleInterop": true,
22
- "verbatimModuleSyntax": true,
23
- "skipLibCheck": true,
24
14
  },
25
15
  "include": ["./**/*.ts", "./**/*.vue"],
26
16
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "1.0.0-9",
4
+ "version": "1.0.0",
5
5
  "engines": {
6
- "node": ">=18.16.0"
6
+ "node": ">=20.6.0"
7
7
  },
8
8
  "main": "build/index.js",
9
9
  "type": "module",
@@ -18,7 +18,8 @@
18
18
  "./inertia_provider": "./build/providers/inertia_provider.js",
19
19
  "./plugins/edge": "./build/src/plugins/edge/plugin.js",
20
20
  "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
21
- "./client": "./build/src/plugins/vite.js"
21
+ "./client": "./build/src/plugins/vite.js",
22
+ "./helpers": "./build/src/helpers.js"
22
23
  },
23
24
  "scripts": {
24
25
  "clean": "del-cli build",
@@ -32,56 +33,58 @@
32
33
  "prebuild": "npm run lint && npm run clean",
33
34
  "build": "tsup-node",
34
35
  "postbuild": "npm run copy:templates",
35
- "release": "np",
36
+ "release": "release-it",
36
37
  "version": "npm run build",
37
38
  "prepublishOnly": "npm run build"
38
39
  },
39
40
  "devDependencies": {
40
- "@adonisjs/assembler": "^7.2.1",
41
- "@adonisjs/core": "6.3.0",
42
- "@adonisjs/eslint-config": "^1.2.1",
43
- "@adonisjs/prettier-config": "^1.2.1",
44
- "@adonisjs/session": "7.1.1",
45
- "@adonisjs/tsconfig": "^1.2.1",
46
- "@adonisjs/vite": "^3.0.0-2",
47
- "@japa/api-client": "^2.0.2",
48
- "@japa/assert": "2.1.0",
49
- "@japa/expect-type": "^2.0.1",
50
- "@japa/file-system": "^2.2.0",
51
- "@japa/plugin-adonisjs": "^2.0.3",
52
- "@japa/runner": "3.1.1",
53
- "@swc/core": "^1.4.2",
54
- "@types/node": "^20.11.20",
55
- "@types/qs": "^6.9.11",
41
+ "@adonisjs/assembler": "^7.7.0",
42
+ "@adonisjs/core": "6.9.1",
43
+ "@adonisjs/eslint-config": "^1.3.0",
44
+ "@adonisjs/prettier-config": "^1.3.0",
45
+ "@adonisjs/session": "7.4.0",
46
+ "@adonisjs/tsconfig": "^1.3.0",
47
+ "@adonisjs/vite": "^3.0.0",
48
+ "@japa/api-client": "^2.0.3",
49
+ "@japa/assert": "3.0.0",
50
+ "@japa/expect-type": "^2.0.2",
51
+ "@japa/file-system": "^2.3.0",
52
+ "@japa/plugin-adonisjs": "^3.0.1",
53
+ "@japa/runner": "3.1.4",
54
+ "@japa/snapshot": "^2.0.5",
55
+ "@swc/core": "^1.5.24",
56
+ "@types/node": "^20.13.0",
57
+ "@types/qs": "^6.9.15",
56
58
  "@types/supertest": "^6.0.2",
57
59
  "@vavite/multibuild": "^4.1.1",
58
60
  "c8": "^9.1.0",
59
61
  "copyfiles": "^2.4.1",
60
62
  "del-cli": "^5.1.0",
61
- "edge-parser": "^9.0.1",
62
- "edge.js": "^6.0.1",
63
+ "edge-parser": "^9.0.2",
64
+ "edge.js": "^6.0.2",
63
65
  "eslint": "^8.57.0",
64
- "get-port": "^7.0.0",
65
- "np": "^9.2.0",
66
- "prettier": "^3.2.5",
67
- "supertest": "^6.3.4",
68
- "tinybench": "^2.6.0",
66
+ "get-port": "^7.1.0",
67
+ "prettier": "^3.3.0",
68
+ "release-it": "^17.3.0",
69
+ "supertest": "^7.0.0",
69
70
  "ts-node": "^10.9.2",
70
71
  "tsup": "^8.0.2",
71
- "typescript": "~5.3.3",
72
- "vite": "^5.1.4"
72
+ "typescript": "~5.4.5",
73
+ "vite": "^5.2.12"
73
74
  },
74
75
  "dependencies": {
75
- "@poppinss/utils": "^6.7.2",
76
+ "@poppinss/utils": "^6.7.3",
77
+ "@tuyau/utils": "^0.0.4",
76
78
  "crc-32": "^1.2.2",
77
79
  "edge-error": "^4.0.1",
78
- "html-entities": "^2.4.0",
79
- "qs": "^6.11.2"
80
+ "html-entities": "^2.5.2",
81
+ "locate-path": "^7.2.0",
82
+ "qs": "^6.12.1"
80
83
  },
81
84
  "peerDependencies": {
82
- "@adonisjs/core": "^6.2.0",
83
- "@adonisjs/session": "^7.0.0",
84
- "@adonisjs/vite": "^3.0.0-2",
85
+ "@adonisjs/core": "^6.9.1",
86
+ "@adonisjs/session": "^7.4.0",
87
+ "@adonisjs/vite": "^3.0.0",
85
88
  "@japa/api-client": "^2.0.0",
86
89
  "edge.js": "^6.0.0"
87
90
  },
@@ -104,11 +107,17 @@
104
107
  "access": "public",
105
108
  "tag": "latest"
106
109
  },
107
- "np": {
108
- "message": "chore(release): %s",
109
- "tag": "latest",
110
- "branch": "main",
111
- "anyBranch": false
110
+ "release-it": {
111
+ "git": {
112
+ "commitMessage": "chore(release): ${version}",
113
+ "tagAnnotation": "v${version}",
114
+ "tagName": "v${version}"
115
+ },
116
+ "github": {
117
+ "release": true,
118
+ "releaseName": "v${version}",
119
+ "web": true
120
+ }
112
121
  },
113
122
  "c8": {
114
123
  "reporter": [
@@ -124,12 +133,13 @@
124
133
  "entry": [
125
134
  "./index.ts",
126
135
  "./src/types.ts",
136
+ "./src/helpers.ts",
137
+ "./src/plugins/vite.ts",
127
138
  "./services/inertia.ts",
128
139
  "./src/inertia_middleware.ts",
129
140
  "./providers/inertia_provider.ts",
130
141
  "./src/plugins/edge/plugin.ts",
131
- "./src/plugins/japa/api_client.ts",
132
- "./src/plugins/vite.ts"
142
+ "./src/plugins/japa/api_client.ts"
133
143
  ],
134
144
  "outDir": "./build",
135
145
  "clean": true,